AnimationOffsetMenu.cs
3.12 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
using System.Linq;
using UnityEngine;
using UnityEngine.Timeline;
namespace UnityEditor.Timeline
{
static class AnimationOffsetMenu
{
public static GUIContent MatchPreviousMenuItem = EditorGUIUtility.TrTextContent("Match Offsets To Previous Clip");
public static GUIContent MatchNextMenuItem = EditorGUIUtility.TrTextContent("Match Offsets To Next Clip");
public static string MatchFieldsPrefix = "Match Offsets Fields/";
public static GUIContent ResetOffsetMenuItem = EditorGUIUtility.TrTextContent("Reset Offsets");
static bool EnforcePreviewMode(WindowState state)
{
state.previewMode = true; // try and set the preview mode
if (!state.previewMode)
{
Debug.LogError("Match clips cannot be completed because preview mode cannot be enabed");
return false;
}
return true;
}
internal static void MatchClipsToPrevious(WindowState state, TimelineClip[] clips)
{
if (!EnforcePreviewMode(state))
return;
clips = clips.OrderBy(x => x.start).ToArray();
foreach (var clip in clips)
{
var sceneObject = TimelineUtility.GetSceneGameObject(state.editSequence.director, clip.parentTrack);
if (sceneObject != null)
{
TimelineUndo.PushUndo(clip.asset, "Match Clip");
TimelineAnimationUtilities.MatchPrevious(clip, sceneObject.transform, state.editSequence.director);
}
}
InspectorWindow.RepaintAllInspectors();
TimelineEditor.Refresh(RefreshReason.ContentsModified);
}
internal static void MatchClipsToNext(WindowState state, TimelineClip[] clips)
{
if (!EnforcePreviewMode(state))
return;
clips = clips.OrderByDescending(x => x.start).ToArray();
foreach (var clip in clips)
{
var sceneObject = TimelineUtility.GetSceneGameObject(state.editSequence.director, clip.parentTrack);
if (sceneObject != null)
{
TimelineUndo.PushUndo(clip.asset, "Match Clip");
TimelineAnimationUtilities.MatchNext(clip, sceneObject.transform, state.editSequence.director);
}
}
InspectorWindow.RepaintAllInspectors();
TimelineEditor.Refresh(RefreshReason.ContentsModified);
}
public static void ResetClipOffsets(WindowState state, TimelineClip[] clips)
{
foreach (var clip in clips)
{
if (clip.asset is AnimationPlayableAsset)
{
TimelineUndo.PushUndo(clip.asset, "Reset Offsets");
var playableAsset = (AnimationPlayableAsset)clip.asset;
playableAsset.ResetOffsets();
}
}
state.rebuildGraph = true;
InspectorWindow.RepaintAllInspectors();
TimelineEditor.Refresh(RefreshReason.SceneNeedsUpdate);
}
}
}