Initial Commit
This commit is contained in:
parent
53eb92e9af
commit
270ab7d11f
15341 changed files with 700234 additions and 0 deletions
|
@ -0,0 +1,119 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using UnityEditorInternal;
|
||||
using UnityEngine;
|
||||
using UnityObject = UnityEngine.Object;
|
||||
|
||||
namespace UnityEditor.Timeline
|
||||
{
|
||||
class ScriptableObjectViewPrefs<TViewModel> : IDisposable where TViewModel : ScriptableObject
|
||||
{
|
||||
const string k_DefaultFilePath = "Library/";
|
||||
const string k_Extension = ".pref";
|
||||
|
||||
readonly string m_RelativePath;
|
||||
readonly string m_AbsolutePath;
|
||||
readonly string m_FileName;
|
||||
ScriptableObject m_Asset;
|
||||
TViewModel m_ViewModel;
|
||||
|
||||
bool isSavable
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Asset != null &&
|
||||
m_ViewModel != null &&
|
||||
!string.IsNullOrEmpty(m_FileName);
|
||||
}
|
||||
}
|
||||
|
||||
public ScriptableObjectViewPrefs(ScriptableObject asset, string relativeSavePath)
|
||||
{
|
||||
m_Asset = asset;
|
||||
m_RelativePath = string.IsNullOrEmpty(relativeSavePath) ? k_DefaultFilePath : relativeSavePath;
|
||||
if (!m_RelativePath.EndsWith("/", StringComparison.Ordinal))
|
||||
m_RelativePath += "/";
|
||||
|
||||
m_AbsolutePath = Application.dataPath + "/../" + m_RelativePath;
|
||||
|
||||
var assetKey = GetAssetKey(asset);
|
||||
m_FileName = string.IsNullOrEmpty(assetKey) ? string.Empty : assetKey + k_Extension;
|
||||
}
|
||||
|
||||
public TViewModel viewModel
|
||||
{
|
||||
get
|
||||
{
|
||||
if (m_ViewModel == null)
|
||||
{
|
||||
if (m_Asset == null)
|
||||
m_ViewModel = CreateViewModel();
|
||||
else
|
||||
m_ViewModel = LoadViewModel() ?? CreateViewModel();
|
||||
}
|
||||
return m_ViewModel;
|
||||
}
|
||||
}
|
||||
|
||||
public void Save()
|
||||
{
|
||||
if (!isSavable)
|
||||
return;
|
||||
|
||||
// make sure the path exists or file write will fail
|
||||
if (!Directory.Exists(m_AbsolutePath))
|
||||
Directory.CreateDirectory(m_AbsolutePath);
|
||||
|
||||
const bool saveAsText = true;
|
||||
InternalEditorUtility.SaveToSerializedFileAndForget(new UnityObject[] { m_ViewModel }, m_RelativePath + m_FileName, saveAsText);
|
||||
}
|
||||
|
||||
public void DeleteFile()
|
||||
{
|
||||
if (!isSavable)
|
||||
return;
|
||||
|
||||
var path = m_AbsolutePath + m_FileName;
|
||||
|
||||
if (!File.Exists(path))
|
||||
return;
|
||||
|
||||
File.Delete(path);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (m_ViewModel != null)
|
||||
UnityObject.DestroyImmediate(m_ViewModel);
|
||||
|
||||
m_Asset = null;
|
||||
}
|
||||
|
||||
public static TViewModel CreateViewModel()
|
||||
{
|
||||
var model = ScriptableObject.CreateInstance<TViewModel>();
|
||||
model.hideFlags |= HideFlags.HideAndDontSave;
|
||||
return model;
|
||||
}
|
||||
|
||||
TViewModel LoadViewModel()
|
||||
{
|
||||
if (string.IsNullOrEmpty(m_FileName))
|
||||
return null;
|
||||
|
||||
var objects = InternalEditorUtility.LoadSerializedFileAndForget(m_RelativePath + m_FileName);
|
||||
if (objects.Length <= 0 || objects[0] == null)
|
||||
return null;
|
||||
|
||||
var model = (TViewModel)objects[0];
|
||||
model.hideFlags |= HideFlags.HideAndDontSave;
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
static string GetAssetKey(UnityObject asset)
|
||||
{
|
||||
return asset == null ? string.Empty : AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(asset));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 80ae83fdf1fb2c649bccb8c293b94556
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,115 @@
|
|||
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();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: d79cb9ecc0d4a6d428ab98a681a33897
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,184 @@
|
|||
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;
|
||||
}
|
||||
|
||||
public static int GetTrackHeightExtension(TrackAsset asset)
|
||||
{
|
||||
if (asset == null)
|
||||
return 0;
|
||||
|
||||
return GetTrackViewModelData(asset).trackHeightExtension;
|
||||
}
|
||||
|
||||
public static void SetTrackHeightExtension(TrackAsset asset, int height)
|
||||
{
|
||||
if (asset != null)
|
||||
GetTrackViewModelData(asset).trackHeightExtension = height;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 105515c1653548242b4fe973c0f375f7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Loading…
Add table
Add a link
Reference in a new issue