吸収演出とカウンターの同期方法調整

This commit is contained in:
kimura 2021-09-21 10:34:37 +09:00
parent 9a05298a38
commit a1b017d903
2 changed files with 18 additions and 18 deletions

View File

@ -76,20 +76,18 @@ public class CornField : MonoBehaviour
} }
GameDataManager.SaveGameData(); GameDataManager.SaveGameData();
// 収穫カウンター // 収穫カウンター+吸収演出
var currentHarvestedCount = 0;
cornHarvester.FinishHarvested cornHarvester.FinishHarvested
.Scan((list, newList) => list.Concat(newList).ToList()) .Scan((list, newList) => (newList.count, list.colliders.Concat(newList.colliders).ToList()))
.Throttle(TimeSpan.FromSeconds(countThrottle)) .Throttle(TimeSpan.FromSeconds(countThrottle))
.Take(1) .Take(1)
.RepeatUntilDestroy(this) .RepeatUntilDestroy(this)
.Subscribe(x => .Subscribe(x =>
{ {
var colliders = x.colliders;
var count = currentHarvestedCount;
// カゴ外のやつ分ける // カゴ外のやつ分ける
var destroyList = x.Where(c => c.enabled == false).ToList(); var destroyList = colliders.Where(c => c.enabled == false).ToList();
var stayList = x.Except(destroyList).ToList(); var stayList = colliders.Except(destroyList).ToList();
// 間引く // 間引く
var animationList = stayList.RandomChoose(animationLimit); var animationList = stayList.RandomChoose(animationLimit);
// 間引かれた分は破棄 // 間引かれた分は破棄
@ -117,7 +115,7 @@ public class CornField : MonoBehaviour
}); });
this.CallWaitForSeconds(animationDuration, () => this.CallWaitForSeconds(animationDuration, () =>
{ {
counterView.SetHarvestedCount(count); counterView.SetHarvestedCount(x.count);
}); });
}).AddTo(this); }).AddTo(this);
// 株設定 // 株設定
@ -137,34 +135,33 @@ public class CornField : MonoBehaviour
seedling.SetSeedlingGene(lineData.Seedlings[index].FirstTime, lineData.Seedlings[index].Period / 3, lineData.Seedlings[index].Level); seedling.SetSeedlingGene(lineData.Seedlings[index].FirstTime, lineData.Seedlings[index].Period / 3, lineData.Seedlings[index].Level);
} }
#endif #endif
// 収穫通知
seedling.Harvested.Subscribe(_ => seedling.Harvested.Subscribe(_ =>
{ {
// 収穫
VibrationManager.Instance.PlayVibrationOnce(); VibrationManager.Instance.PlayVibrationOnce();
var harvestCount = GetHarvestCount(lineData.Seedlings[index].Level); var harvestCount = GetHarvestCount(lineData.Seedlings[index].Level);
var harvestedCorn = GetHarvestedCornCount(gameData.MachineLevel); var harvestedCorn = GetHarvestedCornCount(gameData.MachineLevel);
gameData.cornSeed += harvestedCorn * harvestCount; gameData.cornSeed += harvestedCorn * harvestCount;
currentHarvestedCount += harvestedCorn * harvestCount;
var seedlingTransform = seedling.transform; var seedlingTransform = seedling.transform;
for (int j = 0; j < harvestCount; j++) for (int j = 0; j < harvestCount; j++)
{ {
// 株の位置調整
var pos = seedlingTransform.position; var pos = seedlingTransform.position;
if (harvestCount > 1) if (harvestCount > 1)
{ {
pos += Vector3.right * (j - 1) * harvestedDistance + Vector3.forward * (j - 1); pos += Vector3.right * (j - 1) * harvestedDistance + Vector3.forward * (j - 1);
} }
// 複数株
this.CallWaitForFrame(harvestedFrameInterval * j, () => this.CallWaitForFrame(harvestedFrameInterval * j, () =>
{ {
var harvestAnimation = Instantiate(harvestPrefab, pos, Quaternion.identity, seedlingTransform); var harvestAnimation = Instantiate(harvestPrefab, pos, Quaternion.identity, seedlingTransform);
var beginPos = harvestAnimation.transform.position;
this.CallWaitForSeconds(.5f, () => this.CallWaitForSeconds(.5f, () =>
{ {
this.CallLerp(.4f, f => this.CallLerp(.4f, f =>
{ {
harvestAnimation.transform.position = Vector3.Lerp(beginPos, harvestInsertPosition.position, f.EaseInQuadratic()); harvestAnimation.transform.position = Vector3.Lerp(pos, harvestInsertPosition.position, f.EaseInQuadratic());
}, () => }, () =>
{ {
// コーン排出
cornHarvester.AddCount(harvestedCorn); cornHarvester.AddCount(harvestedCorn);
Destroy(harvestAnimation); Destroy(harvestAnimation);
}); });

View File

@ -15,8 +15,8 @@ public class CornHarvester : MonoBehaviour
private int maxCorn = 100; // 収穫演出で出るコーンの数を制限 private int maxCorn = 100; // 収穫演出で出るコーンの数を制限
private readonly ReactiveProperty<int> count = new ReactiveProperty<int>(0); private readonly ReactiveProperty<int> count = new ReactiveProperty<int>(0);
private readonly Subject<List<Collider2D>> finishHarvested = new Subject<List<Collider2D>>(); private readonly Subject<(int count, List<Collider2D> colliders)> finishHarvested = new Subject<(int count, List<Collider2D> colliders)>();
public Subject<List<Collider2D>> FinishHarvested => finishHarvested; public Subject<(int count, List<Collider2D> colliders)> FinishHarvested => finishHarvested;
private void Start() private void Start()
{ {
@ -27,11 +27,14 @@ public class CornHarvester : MonoBehaviour
.Pairwise() .Pairwise()
.Subscribe(x => .Subscribe(x =>
{ {
StartCoroutine(Harvested(Mathf.Min(maxCorn, x.Current - x.Previous))); StartCoroutine(Harvested(Mathf.Min(maxCorn, x.Current - x.Previous), (list) =>
{
finishHarvested.OnNext((x.Current, list));
}));
}).AddTo(this); }).AddTo(this);
} }
private IEnumerator Harvested(int cnt) private IEnumerator Harvested(int cnt, Action<List<Collider2D>> callback = null)
{ {
var finishedList = new List<Collider2D>(); var finishedList = new List<Collider2D>();
for (int i = 0; i < cnt; i++) for (int i = 0; i < cnt; i++)
@ -41,7 +44,7 @@ public class CornHarvester : MonoBehaviour
finishedList.Add(corn.GetComponent<Collider2D>()); finishedList.Add(corn.GetComponent<Collider2D>());
yield return null; yield return null;
} }
finishHarvested.OnNext(finishedList); callback?.Invoke(finishedList);
} }
public void AddCount(int value) public void AddCount(int value)