119 lines
4.3 KiB
C#
119 lines
4.3 KiB
C#
using Newtonsoft.Json;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using TMPro;
|
||
using UnityEngine;
|
||
using UnityEngine.Playables;
|
||
using UnityEngine.Timeline;
|
||
using Random = UnityEngine.Random;
|
||
|
||
/// <summary>
|
||
/// Timeline 驱动的倍数型爆奖事件(分 n 次加爆奖倍数)。
|
||
/// FLXJ / GSL 共用流程:
|
||
/// Timeline 每轮触发 SetxiaoGuo_Effect(本轮加成倍数 + 随机激活效果面板)
|
||
/// → SetBeiShu(累计倍数显示)→ 最后一轮 EndBJ 结算(基类统一 JiaFen + BJEndUI + die)。
|
||
///
|
||
/// 两个子类的差异(由子类 override 保留):
|
||
/// FLXJEvent.SetBeiShu —— 数字滚动 + 缩放动画;GSL 直接显示
|
||
/// GSLDieEvent.PlayFastTimeline —— 无轮次守卫直接跳帧
|
||
///
|
||
/// ⭐ 字段名与原 FLXJEvent / GSLDieEvent 完全一致,预制体序列化数据无需重拖。
|
||
/// </summary>
|
||
public class TimelineBeiShuEvent : BJRedPacketEvent
|
||
{
|
||
public LeiLongkillObj flxjKill; // 服务端下发的每轮加成倍数
|
||
public TextMeshProUGUI beishu; // 累计倍数显示
|
||
public int beishunum; // 累计倍数
|
||
public TextMeshProUGUI chengshu; // 底分(成数)显示
|
||
public TextMeshProUGUI xiaoGuo_Effect; // 本轮效果/加成倍数显示
|
||
|
||
public int currCount = 0; // 已结算轮次
|
||
public int count; // 总轮次(服务端 res 数量)
|
||
|
||
public PlayableDirector director; // 控制 Timeline
|
||
|
||
public List<GameObject> gameObjects; // 效果面板列表(随机激活一个)
|
||
|
||
public int count4; // 如果重复4次 从指定位置开始播放的帧数 timeline
|
||
public int count5; // 如果重复5次 从指定位置开始播放的帧数 timeline
|
||
public int count6; // 如果重复6次 从指定位置开始播放的帧数 timeline
|
||
|
||
/// <summary>PlayFastTimeline 是否已跳过帧(防重复跳帧)</summary>
|
||
protected bool _hasJumped;
|
||
|
||
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);
|
||
flxjKill = JsonConvert.DeserializeObject<LeiLongkillObj>(obj.ToString());
|
||
count = flxjKill.res.Count;
|
||
}
|
||
|
||
/// <summary>显示底分(成数)</summary>
|
||
public void SetChengshu()
|
||
{
|
||
chengshu.text = fishScore.ToString();
|
||
}
|
||
|
||
/// <summary>触发爆奖效果面板:累加倍数、随机激活效果面板(按 currCount 取 index)</summary>
|
||
public void SetxiaoGuo_Effect()
|
||
{
|
||
int index = currCount;
|
||
int addbeishu = flxjKill.res[index].score;
|
||
beishunum += addbeishu;
|
||
xiaoGuo_Effect.text = addbeishu.ToString();
|
||
|
||
// 随机激活一个效果面板
|
||
int temp = Random.Range(0, gameObjects.Count);
|
||
foreach (var item in gameObjects)
|
||
{
|
||
if (item.activeSelf)
|
||
item.SetActive(false);
|
||
}
|
||
gameObjects[temp].SetActive(true);
|
||
|
||
currCount++;
|
||
}
|
||
|
||
/// <summary>Timeline 快播:currCount>=3 时跳一次到 4/5/6 对应帧位置(子类可 override)</summary>
|
||
public virtual void PlayFastTimeline()
|
||
{
|
||
if (count <= 3) return;
|
||
if (director == null) return;
|
||
if (currCount < 3) return; // 没走完 3 轮不跳
|
||
if (_hasJumped) return; // 已经跳过不再跳
|
||
_hasJumped = true;
|
||
|
||
JumpToCountFrame();
|
||
}
|
||
|
||
/// <summary>按 count 跳到 4/5/6 对应的 Timeline 帧位置</summary>
|
||
protected void JumpToCountFrame()
|
||
{
|
||
if (director == null) return;
|
||
|
||
int jumpFrame = count switch
|
||
{
|
||
4 => count4,
|
||
5 => count5,
|
||
6 => count6,
|
||
_ => count4,
|
||
};
|
||
var timeline = director.playableAsset as TimelineAsset;
|
||
double fps = timeline != null ? timeline.editorSettings.frameRate : 30.0;
|
||
director.time = jumpFrame / fps;
|
||
director.Play();
|
||
}
|
||
|
||
/// <summary>更新累计倍数显示(子类可 override 加滚动动画,如 FLXJEvent)</summary>
|
||
public virtual void SetBeiShu()
|
||
{
|
||
beishu.text = beishunum.ToString();
|
||
}
|
||
|
||
/// <summary>结束爆奖:走基类统一结算(JiaFen + BJEndUI + die)</summary>
|
||
public void EndBJ()
|
||
{
|
||
OnScoreEnd();
|
||
}
|
||
}
|