A game about forced loneliness, made by TACStudios
at master 126 lines 4.6 kB view raw
1using System; 2using System.Collections.Generic; 3using UnityEditor.IMGUI.Controls; 4using UnityEngine; 5using UnityEngine.Serialization; 6using UnityEngine.Timeline; 7using UnityObject = UnityEngine.Object; 8 9namespace UnityEditor.Timeline 10{ 11 [Serializable] 12 class TrackViewModelData : ISerializationCallbackReceiver 13 { 14 public static readonly float DefaultinlineAnimationCurveHeight = 100.0f; 15 16 public bool collapsed = true; 17 public bool showMarkers = true; 18 19 public bool showInlineCurves = false; 20 public float inlineAnimationCurveHeight = DefaultinlineAnimationCurveHeight; 21 public int lastInlineCurveDataID = -1; 22 public TreeViewState inlineCurvesState = null; 23 public Rect inlineCurvesShownAreaInsideMargins = new Rect(1, 1, 1, 1); 24 public int trackHeightExtension; 25 26 public Dictionary<int, long> markerTimeStamps = new Dictionary<int, long>(); 27 [SerializeField] List<int> m_MarkerTimeStampsKeys; 28 [SerializeField] List<long> m_MarkerTimeStampsValues; 29 30 public void OnBeforeSerialize() 31 { 32 if (markerTimeStamps == null) 33 return; 34 35 m_MarkerTimeStampsKeys = new List<int>(markerTimeStamps.Count); 36 m_MarkerTimeStampsValues = new List<long>(markerTimeStamps.Count); 37 38 foreach (var kvp in markerTimeStamps) 39 { 40 m_MarkerTimeStampsKeys.Add(kvp.Key); 41 m_MarkerTimeStampsValues.Add(kvp.Value); 42 } 43 } 44 45 public void OnAfterDeserialize() 46 { 47 markerTimeStamps = new Dictionary<int, long>(); 48 49 if (m_MarkerTimeStampsKeys == null || m_MarkerTimeStampsValues == null || 50 m_MarkerTimeStampsKeys.Count != m_MarkerTimeStampsValues.Count) 51 return; 52 53 for (int i = 0; i < m_MarkerTimeStampsKeys.Count; ++i) 54 markerTimeStamps.Add(m_MarkerTimeStampsKeys[i], m_MarkerTimeStampsValues[i]); 55 } 56 } 57 58 [Serializable] 59 partial class TimelineAssetViewModel : ScriptableObject, ISerializationCallbackReceiver 60 { 61 public const float DefaultTrackScale = 1.0f; 62 public const float DefaultVerticalScroll = 0; 63 public static readonly Vector2 TimeAreaDefaultRange = new Vector2(-WindowConstants.timeAreaShownRangePadding, 5.0f); // in seconds. Hack: using negative value to force the UI to have a left margin at 0. 64 public static readonly PlayRange NoPlayRangeSet = new PlayRange(double.MaxValue, double.MaxValue); 65 66 67 public Vector2 timeAreaShownRange = TimeAreaDefaultRange; 68 public float trackScale = DefaultTrackScale; 69 public bool playRangeEnabled; 70 71 public PlayRange timeAreaPlayRange 72 { 73 get { return m_TimeAreaPlayRange; } 74 set { m_TimeAreaPlayRange = value; } 75 } 76 77 public double windowTime; 78 public float verticalScroll = DefaultVerticalScroll; 79 public float sequencerHeaderWidth = WindowConstants.defaultHeaderWidth; 80 81 public Dictionary<TrackAsset, TrackViewModelData> tracksViewModelData = new Dictionary<TrackAsset, TrackViewModelData>(); 82 83 [SerializeField] PlayRange m_TimeAreaPlayRange; 84 85 // Used only for serialization of the dictionary 86 [SerializeField] List<TrackAsset> m_Keys = new List<TrackAsset>(); 87 [SerializeField] List<TrackViewModelData> m_Vals = new List<TrackViewModelData>(); 88 89 public void OnBeforeSerialize() 90 { 91 m_Keys.Clear(); 92 m_Vals.Clear(); 93 foreach (var data in tracksViewModelData) 94 { 95 // Assets that don't save, will create nulls when deserialized 96 if (data.Key != null && data.Value != null && (data.Key.hideFlags & HideFlags.DontSave) == 0) 97 { 98 m_Keys.Add(data.Key); 99 m_Vals.Add(data.Value); 100 } 101 } 102 } 103 104 public void OnAfterDeserialize() 105 { 106 UpgradeIfNecessary(); 107 m_Version = (int)Versions.Current; 108 } 109 110 public void OnEnable() 111 { 112 if (m_Keys.Count == m_Vals.Count) 113 { 114 tracksViewModelData.Clear(); 115 for (int i = 0; i < m_Keys.Count; i++) 116 { 117 if (m_Keys[i] != null) // if the asset is overwritten the tracks can be null 118 tracksViewModelData[m_Keys[i]] = m_Vals[i]; 119 } 120 } 121 122 m_Keys.Clear(); 123 m_Vals.Clear(); 124 } 125 } 126}