Files
ft/Client/Assets/Scripts/GampPlay/ChallengeMatch/Road/ChallengeRegionRoad.cs
2026-06-29 21:18:33 +08:00

145 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 System;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.Playables;
namespace GampPlay.ChallengeMatch.Road
{
//-
public class ChallengeRegionRoad : MonoBehaviour
{
[Header("Timeline配置")]
public PlayableDirector AppearTimeline;//出现表现timeline
public PlayableDirector BreakTimeline;//销毁表现timeline
[Header("下一段路")]
public ChallengeRegionRoad NextRegionRoad;
[Header("破坏障碍物的时间")]
public float AppearJumpDelay = 2f;//播放出现表现timeline同时延迟多久播放头像动画
//-
private float _speed = 1.0f;
#region Game Logic
private async Task OnUnLocking()
{
ELog("OnUnlocking");
AppearTimeline.initialTime = 0;
AppearTimeline.Play();
await Awaiters.Seconds(SpeedUpSeconds(AppearJumpDelay));
}
public float SpeedUpSeconds(float seconds)
{
return _speed * seconds;
}
private async Task OnBreaking()
{
ELog("OnBreaking");
BreakTimeline.initialTime = 0;
BreakTimeline?.Play();
NextRegionRoad?.Prepare();
// await Awaiters.Seconds(SpeedUpSeconds(AppearJumpDelay));
}
private void OnLocked()
{
ELog("OnLocked-> ");
gameObject.SetActive(true);
//-
AppearTimeline.initialTime = 0;
AppearTimeline.Evaluate();
// AppearTimeline.Stop();
// /
BreakTimeline.time = BreakTimeline.duration;
BreakTimeline.Evaluate();
// BreakTimeline.Stop();
}
private void OnUnlocked()
{
ELog($"OnUnlocked-> {BreakTimeline.duration}");
gameObject.SetActive(true);
AppearTimeline.time = AppearTimeline.duration;
AppearTimeline.Evaluate();
// AppearTimeline.Stop();
AppearTimeline.Pause(); // 暂停,保持不动
BreakTimeline.time = BreakTimeline.duration;
// BreakTimeline.time = BreakTimeline.duration;
BreakTimeline.Evaluate();
// BreakTimeline.Stop();
BreakTimeline.Pause();
NextRegionRoad?.Prepare();
}
public void Prepare()
{
gameObject.SetActive(true);
// BreakTimeline.initialTime = 0;
BreakTimeline.time = 0;
BreakTimeline.Evaluate();
// BreakTimeline.Stop();
BreakTimeline.Pause();
}
private void OnBroken()
{
ELog("OnBroken");
gameObject.SetActive(false);
}
public async Task UpdateState(CBoxState state)
{
ELog($"UpdateState -> {state}");
switch (state)
{
case CBoxState.UnLocked:
OnUnlocked();
break;
case CBoxState.Broken:
OnBroken();
break;
case CBoxState.Locked:
OnLocked();
break;
case CBoxState.UnLocking:
await OnUnLocking();
break;
case CBoxState.Attacking:
await OnBreaking();
break;
default:
throw new ArgumentOutOfRangeException(nameof(state), state, null);
}
}
public void UpdateTimeController(ChallengeSetAnimationEvent e)
{
_speed = e.speed;
}
#endregion
#region Log
public void ELog(string message)
{
#if UNITY_EDITOR
Debug.Log($"<color=red> {nameof(ChallengeRegionRoad)}: {gameObject.name} => {message} </color>");
#endif
}
public void Log(string message)
{
Debug.Log($"<color=red> {nameof(ChallengeRegionRoad)} : {gameObject.name} => {message} </color>");
}
#endregion
}
}