using CinemaDirector.Helpers; using System; using System.Collections.Generic; using UnityEngine; namespace CinemaDirector { [Serializable, CutsceneItemAttribute("Curve Clip", "MultiActor Curve Clip", CutsceneItemGenre.MultiActorCurveClipItem)] public class CinemaMultiActorCurveClip : CinemaClipCurve, IRevertable { // Options for reverting in editor. [SerializeField] private RevertMode editorRevertMode = RevertMode.Revert; // Options for reverting during runtime. [SerializeField] private RevertMode runtimeRevertMode = RevertMode.Revert; public List Components = new List(); public List Properties = new List(); public CinemaMultiActorCurveClip() { CurveData.Add(new MemberClipCurveData()); } public void SampleTime(float time) { if (Firetime <= time && time <= Firetime + Duration) { MemberClipCurveData data = CurveData[0]; if (data == null) return; if (data.PropertyType == PropertyTypeInfo.None) { return; } for (int i = 0; i < Components.Count; i++) { object value = null; switch (data.PropertyType) { case PropertyTypeInfo.Color: Color c; c.r = data.Curve1.Evaluate(time); c.g = data.Curve2.Evaluate(time); c.b = data.Curve3.Evaluate(time); c.a = data.Curve4.Evaluate(time); value = c; break; case PropertyTypeInfo.Double: case PropertyTypeInfo.Float: case PropertyTypeInfo.Int: case PropertyTypeInfo.Long: value = data.Curve1.Evaluate(time); break; case PropertyTypeInfo.Quaternion: Quaternion q; q.x = data.Curve1.Evaluate(time); q.y = data.Curve2.Evaluate(time); q.z = data.Curve3.Evaluate(time); q.w = data.Curve4.Evaluate(time); value = q; break; case PropertyTypeInfo.Vector2: Vector2 v2; v2.x = data.Curve1.Evaluate(time); v2.y = data.Curve2.Evaluate(time); value = v2; break; case PropertyTypeInfo.Vector3: Vector3 v3; v3.x = data.Curve1.Evaluate(time); v3.y = data.Curve2.Evaluate(time); v3.z = data.Curve3.Evaluate(time); value = v3; break; case PropertyTypeInfo.Vector4: Vector4 v4; v4.x = data.Curve1.Evaluate(time); v4.y = data.Curve2.Evaluate(time); v4.z = data.Curve3.Evaluate(time); v4.w = data.Curve4.Evaluate(time); value = v4; break; } if (Components[i] != null && Properties[i] != null && Properties[i] != "None") { Components[i].GetType().GetProperty(Properties[i]).SetValue(Components[i], value, null); } } } } public List Actors { get { List actors = new List(); if (transform.parent != null) { MultiCurveTrack track = transform.parent.GetComponent(); MultiActorTrackGroup trackgroup = (track.TrackGroup as MultiActorTrackGroup); actors = trackgroup.Actors; } return actors; } } /// /// Cache the initial state of the curve clip manipulated values. /// /// The Info necessary to revert this clip. public RevertInfo[] CacheState() { List reverts = new List(); for (int i = 0; i < Actors.Count; i++) { if (Components[i] != null && Properties[i] != null && Properties[i] != "None") { Component component = Components[i]; reverts.Add(new RevertInfo(this, component, Properties[i], Components[i].GetType().GetProperty(Properties[i]).GetValue(Components[i], null))); } } return reverts.ToArray(); } internal void Revert() { } /// /// Option for choosing when this curve clip will Revert to initial state in Editor. /// public RevertMode EditorRevertMode { get { return editorRevertMode; } set { editorRevertMode = value; } } /// /// Option for choosing when this curve clip will Revert to initial state in Runtime. /// public RevertMode RuntimeRevertMode { get { return runtimeRevertMode; } set { runtimeRevertMode = value; } } } }