diff --git a/popcorn/Assets/MyGame/Scenes/marketing/Scripts/MarketManager.cs b/popcorn/Assets/MyGame/Scenes/marketing/Scripts/MarketManager.cs index f28c0af8..3cc86422 100644 --- a/popcorn/Assets/MyGame/Scenes/marketing/Scripts/MarketManager.cs +++ b/popcorn/Assets/MyGame/Scenes/marketing/Scripts/MarketManager.cs @@ -176,9 +176,10 @@ public class MarketManager : MonoBehaviour market.SellObservable.Subscribe(coin => { // コイン獲得エフェクト - CoinEffect(coin); - CoinManager.Instance.AddCoinWithEffect(coin, () => { }); - + CoinEffect(coin, pos => + { + CoinManager.Instance.AddCoinWithEffect(coin, pos); + }); blueView.SellAction(); }).AddTo(this); @@ -269,11 +270,16 @@ public class MarketManager : MonoBehaviour } } - private void CoinEffect(int count) + private void CoinEffect(int count, Action onComplete = null) { var effect = Instantiate(coinPrefab, Vector3.zero, Quaternion.identity, rootTransform); effect.GetComponentInChildren().text = count.ToString(); - Destroy(effect.gameObject, 1f); + this.CallWaitForSeconds(1f, () => + { + onComplete?.Invoke(effect.GetChild(0).position); + Destroy(effect.gameObject); + }); + } private void GenerateCustomer(CustomerController controller) diff --git a/popcorn/Assets/MyGame/Scripts/CoinManager.cs b/popcorn/Assets/MyGame/Scripts/CoinManager.cs index b1419ddd..db922a8b 100644 --- a/popcorn/Assets/MyGame/Scripts/CoinManager.cs +++ b/popcorn/Assets/MyGame/Scripts/CoinManager.cs @@ -42,27 +42,35 @@ public class CoinManager : SingletonMonoBehaviour coinCountText.CountUpAnimation(coinTextFormat, ownCoin, duration); } - public void AddCoinWithEffect(int count, Action callback = null) + public void AddCoinWithEffect(int count, Vector3 pos, Action onComplete = null) { ownCoin += count; - // 生成枚数決定 - // 生成ポジション決め、生成 - InstantiateEffeect(coinPrefab, count, Vector3.zero, coinIconTransform.position, () => + InstantiateEffect(coinPrefab, count, pos, coinIconTransform.position, () => { coinCountText.CountUpAnimation(coinTextFormat, ownCoin, duration); - callback?.Invoke(); + onComplete?.Invoke(); }); } - private void InstantiateEffeect(RectTransform prefab, int count, Vector3 from, Vector3 to, Action callback) + private void InstantiateEffect(RectTransform prefab, int count, Vector3 from, Vector3 to, Action callback) { - // アニメ50フレーム - this.CallWaitForSeconds(1.0f, () => { - // コインが到着したらSEとバイブ再生。コインはずみアニメーションを再生 - VibrationManager.Instance.PlayVibrationOnceWeak(); - coinAnimator.SetTrigger(Add); - SoundManager.Instance.PlaySE("se_coin_get"); - callback.Invoke(); + var coinEffect = Instantiate(prefab, from, Quaternion.identity, rootTransform); + var animator = coinEffect.GetComponent(); + this.CallLerp(1f, f => + { + coinEffect.position = Vector3.Lerp(from, to, f * f); + }, () => + { + this.CallWaitForSeconds(0f, () => + { + // コインが到着したらSEとバイブ再生。コインはずみアニメーションを再生 + animator.SetTrigger("Effect"); + Destroy(coinEffect.gameObject, 1f); + VibrationManager.Instance.PlayVibrationOnceWeak(); + // coinAnimator.SetTrigger(Add); + SoundManager.Instance.PlaySE("se_coin_get"); + callback.Invoke(); + }); }); }