Files
5.24BuYu/Assets/MyGame/aa/Game/FLZY/BOSS/TimelineBeiShuEvent.cs
T
2026-08-25 17:00:03 +08:00

106 lines
4.0 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Playables;
using UnityEngine.Timeline;
using Random = UnityEngine.Random;
/// <summary>
/// Timeline 驱动的倍数型爆奖事件(分 n 次加爆奖倍数)。
/// 继承倍数二层类 BJBeishuEvent(累计倍数/底分/本轮加成字段与 SetBeiShu/EndBJ 已在其基类)。
/// FLXJ / GSL 共用流程:
/// Timeline 每轮触发 SetxiaoGuo_Effect(本轮加成倍数 + 随机激活效果面板)
/// → SetBeiShu(累计倍数显示)→ 最后一轮 EndBJ 结算(基类统一 JiaFen + BJEndUI + die)。
///
/// 两个子类的差异(由子类 override 保留):
/// FLXJEvent.SetBeiShu —— 数字滚动 + 缩放动画;GSL 直接显示
/// GSLDieEvent.PlayFastTimeline —— 无轮次守卫直接跳帧
///
/// ⭐ 字段名与原 FLXJEvent / GSLDieEvent 完全一致,预制体序列化数据无需重拖。
/// </summary>
public class TimelineBeiShuEvent : BJBeishuEvent
{
public LeiLongkillObj flxjKill; // 服务端下发的每轮加成倍数
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()
{
SetFieldText(chengshu, chengshu_UGUI, fishScore.ToString());
}
/// <summary>触发爆奖效果面板:累加倍数、随机激活效果面板(按 currCount 取 index)</summary>
public void SetxiaoGuo_Effect()
{
int index = currCount;
int addbeishu = flxjKill.res[index].score;
beishunum += addbeishu;
SetFieldText(xiaoGuo_Effect, xiaoGuo_UGUI, addbeishu.ToString());
// 随机激活一个效果面板
if (gameObjects != null && gameObjects.Count > 0)
{
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();
}
}