145 lines
4.1 KiB
C#
145 lines
4.1 KiB
C#
//- 路上的点
|
||
//
|
||
|
||
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
|
||
}
|
||
} |