File size: 4,306 Bytes
18a519f | 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 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 | using System;
using System.Collections.Generic;
using UnityEditor.IMGUI.Controls;
using UnityEngine;
using UnityEngine.Timeline;
using UnityObject = UnityEngine.Object;
namespace UnityEditor.Timeline
{
[Serializable]
class TrackViewModelData : ISerializationCallbackReceiver
{
public static readonly float DefaultinlineAnimationCurveHeight = 100.0f;
public bool collapsed = true;
public bool showMarkers = true;
public bool showInlineCurves = false;
public float inlineAnimationCurveHeight = DefaultinlineAnimationCurveHeight;
public int lastInlineCurveDataID = -1;
public TreeViewState inlineCurvesState = null;
public Rect inlineCurvesShownAreaInsideMargins = new Rect(1, 1, 1, 1);
public int trackHeightExtension;
public Dictionary<int, long> markerTimeStamps = new Dictionary<int, long>();
[SerializeField] List<int> m_MarkerTimeStampsKeys;
[SerializeField] List<long> m_MarkerTimeStampsValues;
public void OnBeforeSerialize()
{
if (markerTimeStamps == null)
return;
m_MarkerTimeStampsKeys = new List<int>(markerTimeStamps.Count);
m_MarkerTimeStampsValues = new List<long>(markerTimeStamps.Count);
foreach (var kvp in markerTimeStamps)
{
m_MarkerTimeStampsKeys.Add(kvp.Key);
m_MarkerTimeStampsValues.Add(kvp.Value);
}
}
public void OnAfterDeserialize()
{
markerTimeStamps = new Dictionary<int, long>();
if (m_MarkerTimeStampsKeys == null || m_MarkerTimeStampsValues == null ||
m_MarkerTimeStampsKeys.Count != m_MarkerTimeStampsValues.Count)
return;
for (int i = 0; i < m_MarkerTimeStampsKeys.Count; ++i)
markerTimeStamps.Add(m_MarkerTimeStampsKeys[i], m_MarkerTimeStampsValues[i]);
}
}
[Serializable]
class TimelineAssetViewModel : ScriptableObject, ISerializationCallbackReceiver
{
public const float DefaultTrackScale = 1.0f;
public const float DefaultVerticalScroll = 0;
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.
public static readonly Vector2 NoPlayRangeSet = new Vector2(float.MaxValue, float.MaxValue);
public Vector2 timeAreaShownRange = TimeAreaDefaultRange;
public float trackScale = DefaultTrackScale;
public bool playRangeEnabled;
public Vector2 timeAreaPlayRange = NoPlayRangeSet;
public double windowTime;
public float verticalScroll = DefaultVerticalScroll;
public float sequencerHeaderWidth = WindowConstants.defaultHeaderWidth;
public Dictionary<TrackAsset, TrackViewModelData> tracksViewModelData = new Dictionary<TrackAsset, TrackViewModelData>();
// Used only for serialization of the dictionary
[SerializeField] List<TrackAsset> m_Keys = new List<TrackAsset>();
[SerializeField] List<TrackViewModelData> m_Vals = new List<TrackViewModelData>();
public void OnBeforeSerialize()
{
m_Keys.Clear();
m_Vals.Clear();
foreach (var data in tracksViewModelData)
{
// Assets that don't save, will create nulls when deserializeds
if (data.Key != null && data.Value != null && (data.Key.hideFlags & HideFlags.DontSave) == 0)
{
m_Keys.Add(data.Key);
m_Vals.Add(data.Value);
}
}
}
public void OnAfterDeserialize()
{
}
public void OnEnable()
{
if (m_Keys.Count == m_Vals.Count)
{
tracksViewModelData.Clear();
for (int i = 0; i < m_Keys.Count; i++)
{
if (m_Keys[i] != null) // if the asset is overwritten the tracks can be null
tracksViewModelData[m_Keys[i]] = m_Vals[i];
}
}
m_Keys.Clear();
m_Vals.Clear();
}
}
}
|