Tanoda
EventClip.cs
Go to the documentation of this file.
1/******************************************************************************
2 * Copyright (C) Ultraleap, Inc. 2011-2020. *
3 * *
4 * Use subject to the terms of the Apache License 2.0 available at *
5 * http://www.apache.org/licenses/LICENSE-2.0, or another agreement *
6 * between Ultraleap and you, your company or other organization. *
7 ******************************************************************************/
8
10using UnityEngine;
11using UnityEngine.Playables;
12using UnityEngine.Timeline;
13
14namespace Leap.Unity.Recording {
15
16 public class EventClip : PlayableAsset, ITimelineClipAsset {
17
18 #region Inspector
19
21
22 public ExposedReference<GameObject> recipient;
23 public string message = "MyMethod";
24
25 [Header("Event Argument")]
26 [SerializeField, OnEditorChange("argumentType")]
27 private SerializedArgumentType _argumentType = SerializedArgumentType.None;
29 get {
30 return _argumentType;
31 }
32 set {
33 _argumentType = value;
34 if (!_userSetScrubType) {
35 if (value == SerializedArgumentType.None) {
36 _eventScrubType = EventScrubType.Trigger;
37 }
38 else {
39 _eventScrubType = EventScrubType.StateChange;
40 }
41 }
42 }
43 }
44 public Color colorArg = Color.magenta;
45 public float floatArg = 0F;
46 public int intArg = 0;
48 [TextArea]
49 public string stringArg = "";
50 public Vector2 vector2Arg = Vector2.zero;
51 public Vector3 vector3Arg = Vector3.zero;
52 public Vector4 vector4Arg = Vector4.zero;
53
54 [Header("Scrubbing Behavior (Play-mode Only, Optional)")]
55 [SerializeField, OnEditorChange("eventScrubType")]
56 [Tooltip("This field only affects event-firing behavior when moving the playhead "
57 + "backwards across an event clip. Trigger events, such as sound effects, will "
58 + "only fire when the playhead moves forward past a clip's start time. "
59 + "State changes, such as setting an object's Color or a Text value, will fire "
60 + "the previous event when the playhead scrubs backward across a given event's "
61 + "start time, reflecting the state of the object since the last state change. "
62 + "Cumulative State Change events work like State Change events, but fire "
63 + "all events from the first event up to and including the previous event.")]
64 private EventScrubType _eventScrubType = EventScrubType.Trigger;
66 get {
67 return _eventScrubType;
68 }
69 set {
70 _userSetScrubType = true;
71 _eventScrubType = value;
72 }
73 }
74 [SerializeField, HideInInspector]
75 private bool _userSetScrubType = false;
76
77 #endregion
78
79 #region Clip Behavior
80
81 public ClipCaps clipCaps {
82 get { return ClipCaps.None; }
83 }
84
85 public override double duration {
86 get { return 0.5F; }
87 }
88
89 #endregion
90
91 #region PlayableAsset Implementation
92
93 public override Playable CreatePlayable(PlayableGraph graph, GameObject owner) {
94 var playable = ScriptPlayable<EventPlayableBehaviour>.Create(graph, inputCount: 0);
95 this.behaviour = playable.GetBehaviour();
96 this.behaviour.recipient = recipient.Resolve(graph.GetResolver());
97 this.behaviour.message = message;
98 this.behaviour.argument = getArgument();
99
100 return playable;
101 }
102
103 private object getArgument() {
104 switch (_argumentType) {
105 case SerializedArgumentType.Color:
106 return colorArg;
107 case SerializedArgumentType.Float:
108 return floatArg;
109 case SerializedArgumentType.Int:
110 return intArg;
111 case SerializedArgumentType.Quaternion:
112 return quaternionArg;
113 case SerializedArgumentType.String:
114 return stringArg;
115 case SerializedArgumentType.Vector2:
116 return vector2Arg;
117 case SerializedArgumentType.Vector3:
118 return vector3Arg;
119 case SerializedArgumentType.Vector4:
120 return vector4Arg;
121 default:
122 return null;
123 }
124 }
125
126 #endregion
127
128 #region Public Methods
129
130 public void FireEvent() {
131 if (this.behaviour == null) {
132 Debug.LogError("Unable to fire event: PlayableBehaviour has not been constructed. "
133 + "Are you attempting to invoke the clip from outside a PlayableGraph "
134 + "context?");
135 return;
136 }
137
138 this.behaviour.FireEvent();
139 }
140
141 #endregion
142
143 }
144
145 #region Enums
146
148 None,
149 Color,
150 Float,
151 Int,
153 String,
154 Vector2,
155 Vector3,
156 Vector4
157 }
158
159 public enum EventScrubType {
160 Trigger,
162 }
163
164 #endregion
165
166}
UnityEngine.Debug Debug
Definition: TanodaServer.cs:19
UnityEngine.Color Color
Definition: TestScript.cs:32
EventPlayableBehaviour behaviour
Definition: EventClip.cs:20
override double duration
Definition: EventClip.cs:85
EventScrubType eventScrubType
Definition: EventClip.cs:65
ExposedReference< GameObject > recipient
Definition: EventClip.cs:22
override Playable CreatePlayable(PlayableGraph graph, GameObject owner)
Definition: EventClip.cs:93
SerializedArgumentType argumentType
Definition: EventClip.cs:28