165 lines
5.0 KiB
C#
165 lines
5.0 KiB
C#
using DG.Tweening;
|
||
using Spine.Unity;
|
||
using System;
|
||
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using TMPro;
|
||
using UnityEngine;
|
||
using Random = UnityEngine.Random;
|
||
|
||
public class JinLongEvent : BJRedPacketEvent
|
||
{
|
||
public SkeletonGraphic skeletonGraphic;
|
||
|
||
// ⭐ 爆奖激活时机由 BossControl(FLZY_JL_Boss) 延迟 SetActive 控制:
|
||
// Init 设置好参数后会被 SetActive(false) 收起,delayActivateSeconds 之后 SetActive(true),
|
||
// OnEnable 检测到 _ready 才真正触发爆奖(发红包加分)。这里不跑协程等待。
|
||
private bool _ready = false;
|
||
|
||
public int goldAddCount;
|
||
public int currGoldCount;
|
||
public void Awake()
|
||
{
|
||
//skeletonGraphic.AnimationState.Complete += (trackEntry) =>
|
||
//{
|
||
// if (trackEntry.Animation.Name != "stand")
|
||
// {
|
||
// skeletonGraphic.AnimationState.SetAnimation(0, "stand1", false);
|
||
// }
|
||
//};
|
||
}
|
||
private void Start()
|
||
{
|
||
// ⭐ isAddScore 不在登场动画回调里置 true,统一由 Init 的延迟协程(delayActivateSeconds=7s)激活,
|
||
// 否则 stand01 播完(可能早于 7 秒)就提前开始加分,破坏"默认不激活 + 固定 7 秒"。
|
||
PlayThen("stand01", "stand02", () =>
|
||
{
|
||
tMP_Score.gameObject.SetActive(true);
|
||
});
|
||
}
|
||
/// <summary>
|
||
/// 播放完一个再接另一个(UI Spine),并提供 first 播放完毕事件
|
||
/// </summary>
|
||
public void PlayThen(string first, string next, Action onFirstComplete = null)
|
||
{
|
||
var state = skeletonGraphic.AnimationState;
|
||
|
||
var entry = state.SetAnimation(0, first, false);
|
||
|
||
Spine.AnimationState.TrackEntryDelegate callback = null;
|
||
|
||
callback = track =>
|
||
{
|
||
onFirstComplete?.Invoke();
|
||
entry.Complete -= callback;
|
||
};
|
||
|
||
entry.Complete += callback;
|
||
|
||
state.AddAnimation(0, next, true, 0f);
|
||
}
|
||
|
||
|
||
//public void Init(int goldCount,int posID,int paobei,Action<int> action)
|
||
//{
|
||
// JiaFen =()=>{
|
||
// action?.Invoke(0);
|
||
// } ;
|
||
// maxScore = goldCount;
|
||
// this.posID = posID;
|
||
// paoBei = paobei;
|
||
// goldAddCount = paobei * 100;
|
||
//}
|
||
public TextMeshProUGUI tmp_CoinNum;
|
||
public TMP_SpriteAsset tmp_goldSprite;
|
||
public TMP_SpriteAsset tmp_SilverSprite;
|
||
public override void Init(long goldCount, int posID, long paobei, long fishScore, int beishu, Action<int> action, Action action1 = null)
|
||
{
|
||
base.Init(goldCount, posID, paobei, fishScore, beishu, action, action1);
|
||
// ⭐ 只设置参数、标记就绪,不立即触发爆奖。
|
||
// 真正的激活由 BossControl 延迟 SetActive(true) → OnEnable 触发。
|
||
_ready = true;
|
||
}
|
||
/// <summary>
|
||
/// 对象池复用:重置加分滚动进度。
|
||
/// ⭐ 不重置的话 elapsed 残留上次的大值,t = elapsed / a 会立刻 >= 1,
|
||
/// Update 直接跳到最终分,加分动画(从 0 一点一点加)就没了。
|
||
/// </summary>
|
||
protected override void ResetState()
|
||
{
|
||
base.ResetState();
|
||
_ready = false;
|
||
isAddScore = false;
|
||
elapsed = 0f;
|
||
currGoldCount = 0;
|
||
}
|
||
/// <summary>
|
||
/// 由 BossControl 延迟 SetActive(true) 触发:仅当参数已就绪(_ready)才激活爆奖。
|
||
/// 首次从对象池 Get 时 OnEnable 先于 Init(_ready=false)不会误触发,保证"默认不激活"。
|
||
/// </summary>
|
||
private void OnEnable()
|
||
{
|
||
if (_ready) GoldEffect();
|
||
}
|
||
public override void GoldEffect()
|
||
{
|
||
//开始加分
|
||
isAddScore = true;
|
||
AudioManager.Instance.PlayerFX(62007);
|
||
base.GoldEffect();
|
||
}
|
||
|
||
public override void EffEnd()
|
||
{
|
||
|
||
}
|
||
bool isAddScore=false;
|
||
float a = 1f;
|
||
float elapsed = 0f;
|
||
private void Update()
|
||
{
|
||
if (!isAddScore) return;
|
||
|
||
|
||
// 第三阶段:currScore 增加到 maxScore
|
||
if (currScore < maxScore)
|
||
{
|
||
elapsed += Time.deltaTime;
|
||
float t = elapsed / a;
|
||
currScore = (int)Mathf.Lerp(0, maxScore, t);
|
||
|
||
if (currScore > maxScore)
|
||
currScore = maxScore;
|
||
|
||
tMP_Score.text = currScore.ToString();
|
||
return;
|
||
}
|
||
|
||
// 全部完成
|
||
tMP_Score.text = maxScore.ToString();
|
||
isAddScore = false;
|
||
JiaFen?.Invoke();
|
||
|
||
Invoke(nameof(die), 1f);
|
||
}
|
||
|
||
public void die()
|
||
{
|
||
transform.DOScale(Vector3.zero, 0.5f).OnComplete(() =>
|
||
{
|
||
Destroy(gameObject);
|
||
});
|
||
}
|
||
public List<RedPacketRecord> BigPrize(int min = 10, int max = 15)
|
||
{
|
||
if (layeredPool == null)
|
||
{
|
||
layeredPool = new LayeredPool(maxScore, 1); // 初始化LayeredPool,假设5个人,10000分
|
||
}
|
||
|
||
var v = layeredPool.BossGlodCoinRandrom(tMP_Score.transform.position, min, max, posID);
|
||
return v;
|
||
}
|
||
|
||
}
|