You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
97 lines
3.2 KiB
97 lines
3.2 KiB
using UnityEngine;
|
|
using UnityEngine.Playables;
|
|
using UnityEngine.Timeline;
|
|
|
|
namespace uc.Timeline
|
|
{
|
|
public sealed class MoviePlayerMixer : PlayableBehaviour
|
|
{
|
|
public override void OnBehaviourPlay(Playable playable, FrameData info)
|
|
{
|
|
//Debug.Log("MoviePlayerMixer OnBehaviourPlay");
|
|
base.OnBehaviourPlay(playable, info);
|
|
}
|
|
|
|
public override void OnBehaviourPause(Playable playable, FrameData info)
|
|
{
|
|
//Debug.Log("MoviePlayerMixer OnBehaviourPause");
|
|
base.OnBehaviourPlay(playable, info);
|
|
}
|
|
|
|
public override void ProcessFrame(Playable playable, FrameData info, object playerData)
|
|
{
|
|
base.ProcessFrame(playable, info, playerData);
|
|
|
|
// Get the brain that this track controls.
|
|
// Older versions of timeline sent the gameObject by mistake.
|
|
GameObject go = playerData as GameObject;
|
|
MoviePlayerBase movie = (go == null) ? (MoviePlayerBase)playerData : go.GetComponent<MoviePlayerBase>();
|
|
if (movie == null)
|
|
return;
|
|
|
|
//Debug.Log("MoviePlayerMixer ProcessFrame");
|
|
//Debug.Log(movie.gameObject.name);
|
|
|
|
bool should_play = false;
|
|
bool should_pause = true;
|
|
double time = -1;
|
|
|
|
//Debug.Log("play state: " + playable.GetPlayState());
|
|
//Debug.Log("input states: ");
|
|
for (int i = 0; i < playable.GetInputCount(); ++i)
|
|
{
|
|
Playable playerPlayable = playable.GetInput(i);
|
|
//Debug.Log(playerPlayable.GetPlayState());
|
|
|
|
float weight = playable.GetInputWeight(i);
|
|
if (playable.GetPlayState() == PlayState.Playing && weight > 0.0001f)
|
|
{
|
|
if(playerPlayable.GetPlayState() == PlayState.Playing)
|
|
{
|
|
should_play = true;
|
|
should_pause = false;
|
|
time = playerPlayable.GetTime();
|
|
//Debug.Log(time);
|
|
}
|
|
}
|
|
|
|
//Debug.Log(i + " " + playerPlayable.GetPlayState());
|
|
}
|
|
|
|
bool should_update_frame = time >= 0;
|
|
should_pause |= info.deltaTime == 0;
|
|
|
|
//Debug.Log("");
|
|
//Debug.Log(info.evaluationType);
|
|
//Debug.Log(info.seekOccurred);
|
|
//Debug.Log(info.timeHeld);
|
|
/*
|
|
if (info.evaluationType == FrameData.EvaluationType.Evaluate && should_update_frame)
|
|
{
|
|
should_play = true;
|
|
should_pause = true;
|
|
}
|
|
*/
|
|
|
|
if (should_play && movie.IsPlaying == false)
|
|
{
|
|
movie.Play();
|
|
}
|
|
|
|
if(should_update_frame)
|
|
{
|
|
uint target_frame = (uint)(movie.TotalNumFrames * time / movie.GetDuration);
|
|
int frame_dist = (int)target_frame - (int)movie.Frame;
|
|
if (Mathf.Abs(frame_dist) >= 2)
|
|
{
|
|
movie.Frame = target_frame;
|
|
}
|
|
}
|
|
|
|
if(should_pause && movie.IsPaused == false)
|
|
{
|
|
movie.Pause();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|