-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTimeMachineMixerBehaviour.cs
73 lines (64 loc) · 2.95 KB
/
TimeMachineMixerBehaviour.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Playables;
namespace neo.timelineExtensions
{
public class TimeMachineMixerBehaviour : PlayableBehaviour
{
public Dictionary<string, double> markerClips;
private PlayableDirector director;
public override void OnPlayableCreate(Playable playable)
{
director = (playable.GetGraph().GetResolver() as PlayableDirector);
}
public override void ProcessFrame(Playable playable, FrameData info, object playerData)
{
if (!Application.isPlaying)
{
return;
}
int inputCount = playable.GetInputCount();
for (int i = 0; i < inputCount; i++)
{
float inputWeight = playable.GetInputWeight(i);
ScriptPlayable<TimeMachineBehaviour> inputPlayable = (ScriptPlayable<TimeMachineBehaviour>)playable.GetInput(i);
TimeMachineBehaviour input = inputPlayable.GetBehaviour();
if (inputWeight > 0f)
{
if (!input.clipExecuted)
{
switch (input.action)
{
//case TimeMachineBehaviour.TimeMachineAction.Pause:
// if (input.ConditionMet())
// {
// GameManager.instance.PauseTimeline(director);
// input.clipExecuted = true; //this prevents the command to be executed every frame of this clip
// }
// break;
case TimeMachineBehaviour.TimeMachineAction.JumpToTime:
case TimeMachineBehaviour.TimeMachineAction.JumpToMarker:
if (input.ConditionMet())
{
//Rewind
if (input.action == TimeMachineBehaviour.TimeMachineAction.JumpToTime)
{
//Jump to time
(playable.GetGraph().GetResolver() as PlayableDirector).time = (double)input.timeToJumpTo;
}
else
{
//Jump to marker
double t = markerClips[input.markerToJumpTo];
(playable.GetGraph().GetResolver() as PlayableDirector).time = t;
}
input.clipExecuted = false; //we want the jump to happen again!
}
break;
}
}
}
}
}
}
}