104 lines
2.5 KiB
C#
104 lines
2.5 KiB
C#
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<ChallengeMatchPlayEvent>().Subscribe(e => { OnPlay(e.step); }).AddTo(disposables);
|
|
#if UNITY_EDITOR
|
|
GContext.OnEvent<ChallengeMatchPlayGMEvent>().Subscribe(e => { OnGMPlay(e.step); }).AddTo(disposables);
|
|
#endif
|
|
|
|
|
|
// FishingChallengeCenter FCC = GContext.container.Resolve<FishingChallengeCenter>();
|
|
var fishingChallengeManager = GContext.container.Resolve<FishingChallengeManager>();
|
|
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;
|
|
}
|
|
}
|