159 lines
5.0 KiB
C#
159 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 LeiLongEvent : BJRedPacketEvent
|
||
{
|
||
public SkeletonGraphic skeletonGraphic;
|
||
|
||
// ⭐ 爆奖激活时机由 BossControl(FLZY_JL_Boss) 延迟 SetActive 控制:
|
||
// Init 设置好参数后会被 SetActive(false) 收起,delayActivateSeconds 之后 SetActive(true),
|
||
// OnEnable 检测到 _ready 才真正触发爆奖(发红包加分)。这里不跑协程等待。
|
||
private bool _ready = false;
|
||
|
||
public TextMeshProUGUI tMP_longzhu1;
|
||
public TextMeshProUGUI tMP_longzhu2;
|
||
public TextMeshProUGUI tMP_longzhu3;
|
||
|
||
public int longzhu1;
|
||
public int longzhu2;
|
||
public void Awake()
|
||
{
|
||
//skeletonGraphic.AnimationState.Complete += (trackEntry) =>
|
||
//{
|
||
// if (trackEntry.Animation.Name != "stand")
|
||
// {
|
||
// skeletonGraphic.AnimationState.SetAnimation(0, "stand1", false);
|
||
// }
|
||
//};
|
||
}
|
||
private void Start()
|
||
{
|
||
PlayThen("stand", "stand1");
|
||
transform.SetParent(null);
|
||
transform.position = Vector3.zero;
|
||
transform.position = Vector3.forward*-100;
|
||
}
|
||
/// <summary>
|
||
/// 播放完一个再接另一个(UI Spine)
|
||
/// </summary>
|
||
public void PlayThen(string first, string next)
|
||
{
|
||
var state = skeletonGraphic.AnimationState;
|
||
AudioManager.Instance.PlayerFX(62000+Random.Range(3,6));
|
||
state.SetAnimation(0, first, false);
|
||
state.AddAnimation(0, next, true, 0f);
|
||
}
|
||
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)
|
||
{
|
||
// ⭐ 融合父类初始化(BJRedPacketEvent.Init → BJEventBase.Init):
|
||
// 1. ResetState() 重置对象池残留状态(走 LeiLongEvent.ResetState → _ready=false / isAddScore=false / elapsed=0,BJRedPacketEvent → currScore=0)
|
||
// 2. 参数赋值:JiaFen / maxScore / posID / paoBei / fishScore / bJbeishu
|
||
// 3. ApplySeatOffset() 缓存 _targetSit —— 这是 isSelf 判定的前提数据
|
||
// 4. isSelf = _targetSit.user == GameManager.Instance.user.id(修复 isSelf 恒为 false 的问题)
|
||
// 5. action1?.Invoke()(Boss 传入的龙珠值 longzhu1/longzhu2 赋值)
|
||
// 6. totalBJCount 恢复 + EnsureScoreBoard 建分版 + ApplyScoreStyle 金银币样式
|
||
base.Init(goldCount, posID, paobei, fishScore, beishu, action, action1);
|
||
|
||
// ⭐ 只设置参数、标记就绪,不立即触发爆奖。
|
||
// 真正的激活由 BossControl 延迟 SetActive(true) → OnEnable 触发。
|
||
_ready = true;
|
||
}
|
||
/// <summary>
|
||
/// 对象池复用:重置就绪标记和加分滚动进度。
|
||
/// </summary>
|
||
protected override void ResetState()
|
||
{
|
||
base.ResetState();
|
||
_ready = false;
|
||
isAddScore = false;
|
||
elapsed = 0f;
|
||
}
|
||
/// <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(62001);
|
||
base.GoldEffect();
|
||
}
|
||
|
||
public override void EffEnd()
|
||
{
|
||
|
||
}
|
||
public void LongZhuMerge()
|
||
{
|
||
tMP_longzhu3.text = (longzhu1*longzhu2).ToString();
|
||
|
||
}
|
||
public void LongZhu2()
|
||
{
|
||
tMP_longzhu2.text = longzhu2.ToString();
|
||
|
||
}
|
||
public void LongZhu1()
|
||
{
|
||
|
||
tMP_longzhu1.text = longzhu1.ToString();
|
||
}
|
||
bool isAddScore=false;
|
||
float a = 3f;
|
||
float elapsed = 0f;
|
||
|
||
private void Update()
|
||
{
|
||
|
||
if (isAddScore) {
|
||
if (currScore < maxScore - paoBei)
|
||
{
|
||
elapsed += Time.deltaTime;
|
||
float t = elapsed / a;
|
||
currScore = (int)Mathf.Lerp(0, maxScore, t);
|
||
|
||
//currScore += Random.Range(paoBei, paoBei*2);
|
||
tMP_Score.text = currScore.ToString();
|
||
}
|
||
else
|
||
{
|
||
tMP_Score.text = maxScore.ToString();
|
||
isAddScore = false;
|
||
// 走基类统一收尾:加金币 → 删面板 → 销毁自身
|
||
Invoke(nameof(OnScoreEnd), 1.5f);
|
||
|
||
//OnScoreEnd();
|
||
}
|
||
|
||
}
|
||
}
|
||
public override void die()
|
||
{
|
||
StartCoroutine(i());
|
||
}
|
||
public IEnumerator i()
|
||
{
|
||
yield return new WaitForSeconds(1f);
|
||
transform.DOScale(Vector3.zero, 0.5f).OnComplete(() =>
|
||
{
|
||
|
||
});
|
||
}
|
||
|
||
}
|