From a1b017d9037319958ee774f59f7e747c00534c3d Mon Sep 17 00:00:00 2001 From: kimura Date: Tue, 21 Sep 2021 10:34:37 +0900 Subject: [PATCH] =?UTF-8?q?=E5=90=B8=E5=8F=8E=E6=BC=94=E5=87=BA=E3=81=A8?= =?UTF-8?q?=E3=82=AB=E3=82=A6=E3=83=B3=E3=82=BF=E3=83=BC=E3=81=AE=E5=90=8C?= =?UTF-8?q?=E6=9C=9F=E6=96=B9=E6=B3=95=E8=AA=BF=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Scenes/CornField/Scripts/CornField.cs | 23 ++++++++----------- .../Scenes/CornField/Scripts/CornHarvester.cs | 13 +++++++---- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/popcorn/Assets/MyGame/Scenes/CornField/Scripts/CornField.cs b/popcorn/Assets/MyGame/Scenes/CornField/Scripts/CornField.cs index 804e418a..3cddad3c 100644 --- a/popcorn/Assets/MyGame/Scenes/CornField/Scripts/CornField.cs +++ b/popcorn/Assets/MyGame/Scenes/CornField/Scripts/CornField.cs @@ -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); }); diff --git a/popcorn/Assets/MyGame/Scenes/CornField/Scripts/CornHarvester.cs b/popcorn/Assets/MyGame/Scenes/CornField/Scripts/CornHarvester.cs index 8b562f54..948d0038 100644 --- a/popcorn/Assets/MyGame/Scenes/CornField/Scripts/CornHarvester.cs +++ b/popcorn/Assets/MyGame/Scenes/CornField/Scripts/CornHarvester.cs @@ -15,8 +15,8 @@ public class CornHarvester : MonoBehaviour private int maxCorn = 100; // 収穫演出で出るコーンの数を制限 private readonly ReactiveProperty count = new ReactiveProperty(0); - private readonly Subject> finishHarvested = new Subject>(); - public Subject> FinishHarvested => finishHarvested; + private readonly Subject<(int count, List colliders)> finishHarvested = new Subject<(int count, List colliders)>(); + public Subject<(int count, List 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> callback = null) { var finishedList = new List(); for (int i = 0; i < cnt; i++) @@ -41,7 +44,7 @@ public class CornHarvester : MonoBehaviour finishedList.Add(corn.GetComponent()); yield return null; } - finishHarvested.OnNext(finishedList); + callback?.Invoke(finishedList); } public void AddCount(int value)