TimelineUndo.cs
2.57 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
using System;
using System.Collections.Generic;
using System.Diagnostics;
using UnityEngine.Playables;
#if UNITY_EDITOR
using UnityEditor;
#endif
namespace UnityEngine.Timeline
{
static class TimelineUndo
{
public static void PushDestroyUndo(TimelineAsset timeline, Object thingToDirty, Object objectToDestroy, string operation)
{
#if UNITY_EDITOR
if (objectToDestroy == null || !DisableUndoGuard.enableUndo)
return;
if (thingToDirty != null)
EditorUtility.SetDirty(thingToDirty);
if (timeline != null)
EditorUtility.SetDirty(timeline);
Undo.DestroyObjectImmediate(objectToDestroy);
#else
if (objectToDestroy != null)
Object.Destroy(objectToDestroy);
#endif
}
[Conditional("UNITY_EDITOR")]
public static void PushUndo(Object thingToDirty, string operation)
{
#if UNITY_EDITOR
if (thingToDirty != null && DisableUndoGuard.enableUndo)
{
var track = thingToDirty as TrackAsset;
if (track != null)
track.MarkDirty();
EditorUtility.SetDirty(thingToDirty);
Undo.RegisterCompleteObjectUndo(thingToDirty, "Timeline " + operation);
}
#endif
}
[Conditional("UNITY_EDITOR")]
public static void RegisterCreatedObjectUndo(Object thingCreated, string operation)
{
#if UNITY_EDITOR
if (DisableUndoGuard.enableUndo)
{
Undo.RegisterCreatedObjectUndo(thingCreated, "Timeline " + operation);
}
#endif
}
#if UNITY_EDITOR
public struct DisableUndoGuard : IDisposable
{
internal static bool enableUndo = true;
static readonly Stack<bool> m_UndoStateStack = new Stack<bool>();
bool m_Disposed;
public DisableUndoGuard(bool disable)
{
m_Disposed = false;
m_UndoStateStack.Push(enableUndo);
enableUndo = !disable;
}
public void Dispose()
{
if (!m_Disposed)
{
if (m_UndoStateStack.Count == 0)
{
Debug.LogError("UnMatched DisableUndoGuard calls");
enableUndo = true;
return;
}
enableUndo = m_UndoStateStack.Pop();
m_Disposed = true;
}
}
}
#endif
}
}