using asap.core; using GameCore; using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Playables; using UniRx; // 不要删,下个可直接拿来用 public class ChallengeMatchPlayEvent { public int step;//当前步骤减一 } #if UNITY_EDITOR public class ChallengeMatchPlayGMEvent { public int step;//当前步骤减一 } #endif public class ChallengeMatchScene : MonoBehaviour { public PlayableDirector playableDirector; double _targetTime; bool _isPlaying; protected CompositeDisposable disposables = new CompositeDisposable(); private void Start() { playableDirector.played += OnTimelinePlayed; playableDirector.paused += OnTimelinePaused; playableDirector.stopped += OnTimelineStopped; } void OnEnable() { _isPlaying = false; GContext.OnEvent().Subscribe(e => { OnPlay(e.step); }).AddTo(disposables); #if UNITY_EDITOR GContext.OnEvent().Subscribe(e => { OnGMPlay(e.step); }).AddTo(disposables); #endif // FishingChallengeCenter FCC = GContext.container.Resolve(); var fishingChallengeManager = GContext.container.Resolve(); int step = fishingChallengeManager.fishingChallengeData.step - 1; if (step < 0) { step = 0; } playableDirector.initialTime = step * 1.5f; playableDirector.Evaluate(); } #if UNITY_EDITOR void OnGMPlay(int step) { step = step - 1; if (step < 0) { step = 0; } playableDirector.Stop(); playableDirector.initialTime = step * 1.5f; playableDirector.Evaluate(); } #endif void OnPlay(int step) { playableDirector.Play(); _targetTime = step * 1.5f; } private void Update() { if (_isPlaying) { if (playableDirector.time >= _targetTime) { playableDirector.Pause(); } } } void OnTimelinePlayed(PlayableDirector director) { _isPlaying = true; } void OnTimelinePaused(PlayableDirector director) { _isPlaying = false; } void OnTimelineStopped(PlayableDirector director) { _isPlaying = false; } void OnDisable() { disposables?.Dispose(); disposables = null; } }