备份CatanBuilding瘦身独立工程
This commit is contained in:
78
Assets/Scripts/GampPlay/FishingB/Weather.cs
Normal file
78
Assets/Scripts/GampPlay/FishingB/Weather.cs
Normal file
@@ -0,0 +1,78 @@
|
||||
using asap.core;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Playables;
|
||||
using UniRx;
|
||||
public class WeatherEvent
|
||||
{
|
||||
public int State;
|
||||
public bool IsPlay;
|
||||
}
|
||||
public class Weather : MonoBehaviour
|
||||
{
|
||||
public PlayableDirector director;
|
||||
IDisposable disposable;
|
||||
private void Start()
|
||||
{
|
||||
director = GetComponent<PlayableDirector>();
|
||||
if (director != null)
|
||||
{
|
||||
director.playOnAwake = false;
|
||||
director.extrapolationMode = DirectorWrapMode.Hold;
|
||||
director.Stop();
|
||||
director.initialTime = 0; // Start at the end of the timeline
|
||||
director.Evaluate();
|
||||
disposable = GContext.OnEvent<WeatherEvent>().Subscribe(OnWeatherEvent);
|
||||
}
|
||||
}
|
||||
void OnWeatherEvent(WeatherEvent e)
|
||||
{
|
||||
e.IsPlay = true;
|
||||
StopAllCoroutines();
|
||||
if (e.State == 1)
|
||||
{
|
||||
//timeline正着播
|
||||
director.initialTime = 0; // Start at the end of the timeline
|
||||
director.Evaluate();
|
||||
director.playableGraph.GetRootPlayable(0).SetSpeed(1); // Set playback speed to forward
|
||||
director.Play();
|
||||
}
|
||||
else if (e.State == 2)
|
||||
{
|
||||
if (director.time > director.duration / 3)
|
||||
{
|
||||
//director.Evaluate();
|
||||
//director.playableGraph.GetRootPlayable(0).SetSpeed(-1); // Set playback speed to reverse
|
||||
//director.Play();
|
||||
StartCoroutine(PlayBackwards());
|
||||
}
|
||||
else
|
||||
{
|
||||
director.initialTime = 0; // Start at the end of the timeline
|
||||
director.Evaluate();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
director.initialTime = 0;
|
||||
}
|
||||
}
|
||||
IEnumerator PlayBackwards()
|
||||
{
|
||||
// Play the timeline backwards
|
||||
while (director.time > 0)
|
||||
{
|
||||
director.time -= Time.deltaTime;
|
||||
//director.Evaluate();
|
||||
yield return null;
|
||||
}
|
||||
director.Stop();
|
||||
}
|
||||
private void OnDestroy()
|
||||
{
|
||||
disposable?.Dispose();
|
||||
disposable = null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user