/
AlembicShotAsset.cs
69 lines (55 loc) · 2.44 KB
/
AlembicShotAsset.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
#if UNITY_2017_1_OR_NEWER
using System;
using UnityEngine;
using UnityEngine.Playables;
using UnityEngine.Timeline;
namespace UTJ.Alembic
{
public class AlembicShotAsset : PlayableAsset, ITimelineClipAsset
{
AlembicStreamPlayer m_Stream;
[Tooltip("Alambic asset to play")]
public ExposedReference<AlembicStreamPlayer> m_StreamPlayer;
[Tooltip("Amount of time to clip off the start of the alembic asset from playback.")]
[SerializeField] public float m_StartOffset;
[Tooltip("Amount of time to clip off the end of the alembic asset from playback.")]
[SerializeField] public float m_EndOffset;
[Tooltip("Use to compress/dilute time play back.")]
[SerializeField] public float m_TimeScale = 1f;
[Tooltip("Controls how playback cycles throught the stream.")]
[SerializeField] public AlembicPlaybackSettings.CycleType m_Cycle = AlembicPlaybackSettings.CycleType.Hold;
[Tooltip("Portion, in seconds, of the alembic stream used by the shot.")]
[ReadOnly] public float m_AlembicLength = 0;
[Tooltip("Auto active/deactivate GameObject on Play/Pause")]
[SerializeField] public bool m_AutoActivateTarget = true;
public ClipCaps clipCaps { get { return ClipCaps.None; } }
public override Playable CreatePlayable(PlayableGraph graph, GameObject owner)
{
var playable = ScriptPlayable<AlembicShotPlayable>.Create(graph);
var behaviour = playable.GetBehaviour();
m_Stream = m_StreamPlayer.Resolve(graph.GetResolver());
behaviour.streamPlayer = m_Stream;
behaviour.m_StartTimeOffset = m_StartOffset;
behaviour.m_EndTimeClipOff = m_EndOffset;
behaviour.m_TimeScale = m_TimeScale;
behaviour.m_Cycle = m_Cycle;
behaviour.m_AutoActivateTarget = m_AutoActivateTarget;
return playable;
}
public override double duration
{
get
{
var t = m_Stream == null ? 0 : m_Stream.m_PlaybackSettings.m_duration;
m_AlembicLength = t;
if (m_Cycle == AlembicPlaybackSettings.CycleType.Hold || m_Cycle == AlembicPlaybackSettings.CycleType.Reverse)
return (t - m_StartOffset - m_EndOffset) * m_TimeScale;
else
{
return base.duration;
}
}
}
}
}
#endif