コイン追加エフェクト処理追加

This commit is contained in:
kimura 2021-11-25 10:10:59 +09:00
parent 2936d81823
commit 04d9ed3e90
2 changed files with 32 additions and 18 deletions

View File

@ -176,9 +176,10 @@ public class MarketManager : MonoBehaviour
market.SellObservable.Subscribe(coin => market.SellObservable.Subscribe(coin =>
{ {
// コイン獲得エフェクト // コイン獲得エフェクト
CoinEffect(coin); CoinEffect(coin, pos =>
CoinManager.Instance.AddCoinWithEffect(coin, () => { }); {
CoinManager.Instance.AddCoinWithEffect(coin, pos);
});
blueView.SellAction(); blueView.SellAction();
}).AddTo(this); }).AddTo(this);
@ -269,11 +270,16 @@ public class MarketManager : MonoBehaviour
} }
} }
private void CoinEffect(int count) private void CoinEffect(int count, Action<Vector3> onComplete = null)
{ {
var effect = Instantiate(coinPrefab, Vector3.zero, Quaternion.identity, rootTransform); var effect = Instantiate(coinPrefab, Vector3.zero, Quaternion.identity, rootTransform);
effect.GetComponentInChildren<TextMeshProUGUI>().text = count.ToString(); effect.GetComponentInChildren<TextMeshProUGUI>().text = count.ToString();
Destroy(effect.gameObject, 1f); this.CallWaitForSeconds(1f, () =>
{
onComplete?.Invoke(effect.GetChild(0).position);
Destroy(effect.gameObject);
});
} }
private void GenerateCustomer(CustomerController controller) private void GenerateCustomer(CustomerController controller)

View File

@ -42,28 +42,36 @@ public class CoinManager : SingletonMonoBehaviour<CoinManager>
coinCountText.CountUpAnimation(coinTextFormat, ownCoin, duration); 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; ownCoin += count;
// 生成枚数決定 InstantiateEffect(coinPrefab, count, pos, coinIconTransform.position, () =>
// 生成ポジション決め、生成
InstantiateEffeect(coinPrefab, count, Vector3.zero, coinIconTransform.position, () =>
{ {
coinCountText.CountUpAnimation(coinTextFormat, ownCoin, duration); 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)
{
var coinEffect = Instantiate(prefab, from, Quaternion.identity, rootTransform);
var animator = coinEffect.GetComponent<Animator>();
this.CallLerp(1f, f =>
{
coinEffect.position = Vector3.Lerp(from, to, f * f);
}, () =>
{
this.CallWaitForSeconds(0f, () =>
{ {
// アニメ50フレーム
this.CallWaitForSeconds(1.0f, () => {
// コインが到着したらSEとバイブ再生。コインはずみアニメーションを再生 // コインが到着したらSEとバイブ再生。コインはずみアニメーションを再生
animator.SetTrigger("Effect");
Destroy(coinEffect.gameObject, 1f);
VibrationManager.Instance.PlayVibrationOnceWeak(); VibrationManager.Instance.PlayVibrationOnceWeak();
coinAnimator.SetTrigger(Add); // coinAnimator.SetTrigger(Add);
SoundManager.Instance.PlaySE("se_coin_get"); SoundManager.Instance.PlaySE("se_coin_get");
callback.Invoke(); callback.Invoke();
}); });
});
} }
public void SubCoin(int coin){ public void SubCoin(int coin){