AnimationClipActions.cs
3.76 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
using System.ComponentModel;
using System.Linq;
using JetBrains.Annotations;
using UnityEngine;
using UnityEngine.Timeline;
using UnityEngine.Playables;
using ClipAction = UnityEditor.Timeline.ItemAction<UnityEngine.Timeline.TimelineClip>;
namespace UnityEditor.Timeline
{
[MenuEntry("Match Offsets To Previous Clip", MenuOrder.CustomClipAction.AnimClipMatchPrevious), UsedImplicitly]
class MatchOffsetsPreviousAction : ClipAction
{
public override bool Execute(WindowState state, TimelineClip[] items)
{
AnimationOffsetMenu.MatchClipsToPrevious(state, items.Where(x => IsValidClip(x, TimelineEditor.inspectedDirector)).ToArray());
return true;
}
private static bool IsValidClip(TimelineClip clip, PlayableDirector director)
{
return clip != null &&
clip.parentTrack != null &&
(clip.asset as AnimationPlayableAsset) != null &&
clip.parentTrack.clips.Any(x => x.start < clip.start) &&
TimelineUtility.GetSceneGameObject(director, clip.parentTrack) != null;
}
protected override MenuActionDisplayState GetDisplayState(WindowState state, TimelineClip[] items)
{
if (!items.All(TimelineAnimationUtilities.IsAnimationClip))
return MenuActionDisplayState.Hidden;
var director = TimelineEditor.inspectedDirector;
if (TimelineEditor.inspectedDirector == null)
return MenuActionDisplayState.Hidden;
if (items.Any(c => IsValidClip(c, director)))
return MenuActionDisplayState.Visible;
return MenuActionDisplayState.Hidden;
}
}
[MenuEntry("Match Offsets To Next Clip", MenuOrder.CustomClipAction.AnimClipMatchNext), UsedImplicitly]
class MatchOffsetsNextAction : ClipAction
{
public override bool Execute(WindowState state, TimelineClip[] items)
{
AnimationOffsetMenu.MatchClipsToNext(state, items.Where(x => IsValidClip(x, TimelineEditor.inspectedDirector)).ToArray());
return true;
}
private static bool IsValidClip(TimelineClip clip, PlayableDirector director)
{
return clip != null &&
clip.parentTrack != null &&
(clip.asset as AnimationPlayableAsset) != null &&
clip.parentTrack.clips.Any(x => x.start > clip.start) &&
TimelineUtility.GetSceneGameObject(director, clip.parentTrack) != null;
}
protected override MenuActionDisplayState GetDisplayState(WindowState state, TimelineClip[] items)
{
if (!items.All(TimelineAnimationUtilities.IsAnimationClip))
return MenuActionDisplayState.Hidden;
var director = TimelineEditor.inspectedDirector;
if (TimelineEditor.inspectedDirector == null)
return MenuActionDisplayState.Hidden;
if (items.Any(c => IsValidClip(c, director)))
return MenuActionDisplayState.Visible;
return MenuActionDisplayState.Hidden;
}
}
[MenuEntry("Reset Offsets", MenuOrder.CustomClipAction.AnimClipResetOffset), UsedImplicitly]
class ResetOffsets : ClipAction
{
public override bool Execute(WindowState state, TimelineClip[] items)
{
AnimationOffsetMenu.ResetClipOffsets(state, items.Where(TimelineAnimationUtilities.IsAnimationClip).ToArray());
return true;
}
protected override MenuActionDisplayState GetDisplayState(WindowState state, TimelineClip[] items)
{
if (!items.All(TimelineAnimationUtilities.IsAnimationClip))
return MenuActionDisplayState.Hidden;
return MenuActionDisplayState.Visible;
}
}
}