TimelineWindowViewPrefs.cs
5.28 KB
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
using UnityEngine;
using UnityEngine.Timeline;
using UnityObject = UnityEngine.Object;
using ViewModelsMap = System.Collections.Generic.Dictionary<UnityEngine.Timeline.TimelineAsset, UnityEditor.Timeline.ScriptableObjectViewPrefs<UnityEditor.Timeline.TimelineAssetViewModel>>;
using ViewModelsList = System.Collections.Generic.List<UnityEditor.Timeline.ScriptableObjectViewPrefs<UnityEditor.Timeline.TimelineAssetViewModel>>;
namespace UnityEditor.Timeline
{
static class TimelineWindowViewPrefs
{
public const string FilePath = "Library/Timeline";
static readonly ViewModelsMap k_ViewModelsMap = new ViewModelsMap();
static readonly ViewModelsList k_UnassociatedViewModels = new ViewModelsList();
public static int viewModelCount
{
get { return k_ViewModelsMap.Count + k_UnassociatedViewModels.Count; }
}
public static TimelineAssetViewModel GetOrCreateViewModel(TimelineAsset asset)
{
if (asset == null)
return CreateUnassociatedViewModel();
ScriptableObjectViewPrefs<TimelineAssetViewModel> vm;
if (k_ViewModelsMap.TryGetValue(asset, out vm))
return vm.viewModel;
return CreateViewModel(asset).viewModel;
}
public static TimelineAssetViewModel CreateUnassociatedViewModel()
{
var vm = new ScriptableObjectViewPrefs<TimelineAssetViewModel>(null, FilePath);
k_UnassociatedViewModels.Add(vm);
return vm.viewModel;
}
static ScriptableObjectViewPrefs<TimelineAssetViewModel> CreateViewModel(TimelineAsset asset)
{
var vm = new ScriptableObjectViewPrefs<TimelineAssetViewModel>(asset, FilePath);
k_ViewModelsMap.Add(asset, vm);
return vm;
}
public static void SaveViewModel(TimelineAsset asset)
{
if (asset == null)
return;
ScriptableObjectViewPrefs<TimelineAssetViewModel> vm;
if (!k_ViewModelsMap.TryGetValue(asset, out vm))
vm = CreateViewModel(asset);
vm.Save();
}
public static void SaveAll()
{
foreach (var kvp in k_ViewModelsMap)
kvp.Value.Save();
}
public static void UnloadViewModel(TimelineAsset asset)
{
ScriptableObjectViewPrefs<TimelineAssetViewModel> vm;
if (k_ViewModelsMap.TryGetValue(asset, out vm))
{
vm.Dispose();
k_ViewModelsMap.Remove(asset);
}
}
public static void UnloadAllViewModels()
{
foreach (var kvp in k_ViewModelsMap)
kvp.Value.Dispose();
foreach (var vm in k_UnassociatedViewModels)
vm.Dispose();
k_ViewModelsMap.Clear();
k_UnassociatedViewModels.Clear();
}
public static TrackViewModelData GetTrackViewModelData(TrackAsset track)
{
if (track == null)
return new TrackViewModelData();
if (track.timelineAsset == null)
return new TrackViewModelData();
var prefs = GetOrCreateViewModel(track.timelineAsset);
TrackViewModelData trackData;
if (prefs.tracksViewModelData.TryGetValue(track, out trackData))
{
return trackData;
}
trackData = new TrackViewModelData();
prefs.tracksViewModelData[track] = trackData;
return trackData;
}
public static bool IsTrackCollapsed(TrackAsset track)
{
if (track == null)
return true;
return GetTrackViewModelData(track).collapsed;
}
public static void SetTrackCollapsed(TrackAsset track, bool collapsed)
{
if (track == null)
return;
GetTrackViewModelData(track).collapsed = collapsed;
}
public static bool IsShowMarkers(TrackAsset track)
{
if (track == null)
return true;
return GetTrackViewModelData(track).showMarkers;
}
public static void SetTrackShowMarkers(TrackAsset track, bool collapsed)
{
if (track == null)
return;
GetTrackViewModelData(track).showMarkers = collapsed;
}
public static bool GetShowInlineCurves(TrackAsset track)
{
if (track == null)
return false;
return GetTrackViewModelData(track).showInlineCurves;
}
public static void SetShowInlineCurves(TrackAsset track, bool inlineOn)
{
if (track == null)
return;
GetTrackViewModelData(track).showInlineCurves = inlineOn;
}
public static float GetInlineCurveHeight(TrackAsset asset)
{
if (asset == null)
return TrackViewModelData.DefaultinlineAnimationCurveHeight;
return GetTrackViewModelData(asset).inlineAnimationCurveHeight;
}
public static void SetInlineCurveHeight(TrackAsset asset, float height)
{
if (asset != null)
GetTrackViewModelData(asset).inlineAnimationCurveHeight = height;
}
}
}