Files
5.24BuYu/Assets/MyGame/aa/Game/FLZY/BOSS/FLXJ/FLXJEvent.cs
T
2026-07-05 17:39:30 +08:00

138 lines
4.1 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 DG.Tweening;
using Newtonsoft.Json;
using System;
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.Playables;
using UnityEngine.Timeline;
using Random = UnityEngine.Random;
public class FLXJEvent : BJEventBase
{
public LeiLongkillObj flxjKill;
public TextMeshProUGUI beishu;
public int beishunum;
public TextMeshProUGUI chengshu;
public TextMeshProUGUI xiaoGuo_Effect;
public int currCount = 0;
public int count;
public PlayableDirector director; // 控制 Timeline
public List<GameObject> gameObjects;
public int count4; // 如果重复4次 从指定位置开始播放的帧数 timeline
public int count5; // 如果重复5次 从指定位置开始播放的帧数 timeline
public int count6; // 如果重复6次 从指定位置开始播放的帧数 timeline
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);
flxjKill = JsonConvert.DeserializeObject<LeiLongkillObj>(obj.ToString());
count = flxjKill.res.Count;
}
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 对应帧位置</summary>
public void PlayFastTimeline()
{
if (count <= 3) return;
if (director == null) return;
if (currCount < 3) return; // 没走完 3 轮不跳
if (_hasJumped) return; // 已经跳过不再跳
_hasJumped = true;
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();
}
private bool _hasJumped;
public void SetBeiShu()
{
int.TryParse(beishu.text, out int prev);
StopAllCoroutinesForBeiShu();
_beiShuCoroutine = StartCoroutine(BeiShuEffect(prev, beishunum));
}
private Coroutine _beiShuCoroutine;
private void StopAllCoroutinesForBeiShu()
{
if (_beiShuCoroutine != null)
StopCoroutine(_beiShuCoroutine);
}
private IEnumerator BeiShuEffect(int from, int to)
{
float duration = 0.5f;
float elapsed = 0f;
Vector3 normalScale = beishu.transform.localScale;
Vector3 bigScale = normalScale * 1.5f;
// 放大
beishu.transform.DOScale(bigScale, duration * 0.3f).SetEase(Ease.OutBack);
while (elapsed < duration)
{
elapsed += Time.deltaTime;
float t = elapsed / duration;
int val = (int)Mathf.Lerp(from, to, t);
beishu.text = val.ToString();
yield return null;
}
beishu.text = to.ToString();
// 迅速缩小回正常
beishu.transform.DOScale(normalScale, 0.15f).SetEase(Ease.InBack);
}
public void EndBJ()
{
if (bjEndUI != null)
{
var uiPos = GetSeatPosition() + Vector3.up * bjEndUIOffsetY;
var endUI = Instantiate(bjEndUI, uiPos, Quaternion.identity, UIManager.Instance.uiRoot);
endUI.Init(bJbeishu, maxScore);
bjEndUI = null; // 防止 OnScoreEnd 重复创建
}
OnScoreEnd();
}
}