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

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

View File

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