Files
5.24BuYu/Assets/MyGame/aa/Game/FLZY/BOSS/YGLG/YGLGDieEvent.cs
T
2026-06-20 15:00:15 +08:00

108 lines
3.0 KiB
C#

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Playables;
public class YGLGDieEvent : BJEventBase
{
public PlayableDirector playable;
public override void Init(int goldCount, int posID, int paobei, int fishScore, int beishu, Action<int> action, Action action1 = null)
{
base.Init(goldCount, posID, paobei, fishScore, beishu, action, action1);
StartCoroutine(ScrollTo_Time(bJbeishu, () => MoveToSit()));
}
public void SetScore()
{
int target = bJbeishu;
StartCoroutine(ScrollTo(target, () => MoveToSit() ));
}
public void Die()
{
transform.GetChild(0).gameObject.SetActive(false);
}
/// <summary>从 currScore 滚动到 target,同时爆破金币效果,完成回调 onComplete</summary>
private IEnumerator ScrollTo(int target, Action onComplete)
{
int from = currScore;
float duration = 5f;
float elapsed = 0f;
float coinInterval = 0.12f;
float nextCoinTime = 0f;
while (elapsed < duration)
{
elapsed += Time.deltaTime;
float t = elapsed / duration;
currScore = (int)Mathf.Lerp(from, target, t);
if (tMP_Score != null)
tMP_Score.text = currScore.ToString();
// 每隔 coinInterval 爆一波金币
if (elapsed >= nextCoinTime)
{
nextCoinTime += coinInterval;
}
yield return null;
}
currScore = target;
if (tMP_Score != null)
tMP_Score.text = target.ToString();
//// 最后补一波金币
//layeredPool = new LayeredPool(paoBei * fishScore / 2, 1);
//BigPrize(5, 10);
//yield return new WaitForSeconds(0.3f); // 等最后一批金币飞到
onComplete?.Invoke();
}
private IEnumerator ScrollTo_Time(int target, Action onComplete)
{
yield return new WaitForSeconds(3.6f);
int from = currScore;
float duration = 5f;
float elapsed = 0f;
float coinInterval = 0.12f;
float nextCoinTime = 0f;
while (elapsed < duration)
{
elapsed += Time.deltaTime;
float t = elapsed / duration;
currScore = (int)Mathf.Lerp(from, target, t);
if (tMP_Score != null)
tMP_Score.text = currScore.ToString();
// 每隔 coinInterval 爆一波金币
if (elapsed >= nextCoinTime)
{
nextCoinTime += coinInterval;
}
yield return null;
}
currScore = target;
if (tMP_Score != null)
tMP_Score.text = target.ToString();
//// 最后补一波金币
//layeredPool = new LayeredPool(paoBei * fishScore / 2, 1);
//BigPrize(5, 10);
//yield return new WaitForSeconds(0.3f); // 等最后一批金币飞到
onComplete?.Invoke();
yield return new WaitForSeconds(5f);
Die();
}
}