AnimationClipActions.cs
3.73 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
using System.Collections.Generic;
using System.Linq;
using JetBrains.Annotations;
using UnityEditor.Timeline.Actions;
using UnityEngine;
using UnityEngine.Timeline;
using UnityEngine.Playables;
namespace UnityEditor.Timeline
{
[ApplyDefaultUndo("Match Offsets")]
[MenuEntry("Match Offsets To Previous Clip", MenuPriority.CustomClipActionSection.matchPrevious), UsedImplicitly]
class MatchOffsetsPreviousAction : ClipAction
{
public override bool Execute(IEnumerable<TimelineClip> clips)
{
if (clips == null || !clips.Any())
return false;
AnimationOffsetMenu.MatchClipsToPrevious(clips.Where(x => IsValidClip(x, TimelineEditor.inspectedDirector)).ToArray());
return true;
}
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;
}
public override ActionValidity Validate(IEnumerable<TimelineClip> clips)
{
if (!clips.All(TimelineAnimationUtilities.IsAnimationClip))
return ActionValidity.NotApplicable;
var director = TimelineEditor.inspectedDirector;
if (TimelineEditor.inspectedDirector == null)
return ActionValidity.NotApplicable;
if (clips.Any(c => IsValidClip(c, director)))
return ActionValidity.Valid;
return ActionValidity.NotApplicable;
}
}
[ApplyDefaultUndo("Match Offsets")]
[MenuEntry("Match Offsets To Next Clip", MenuPriority.CustomClipActionSection.matchNext), UsedImplicitly]
class MatchOffsetsNextAction : ClipAction
{
public override bool Execute(IEnumerable<TimelineClip> clips)
{
AnimationOffsetMenu.MatchClipsToNext(clips.Where(x => IsValidClip(x, TimelineEditor.inspectedDirector)).ToArray());
return true;
}
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;
}
public override ActionValidity Validate(IEnumerable<TimelineClip> clips)
{
if (!clips.All(TimelineAnimationUtilities.IsAnimationClip))
return ActionValidity.NotApplicable;
var director = TimelineEditor.inspectedDirector;
if (TimelineEditor.inspectedDirector == null)
return ActionValidity.NotApplicable;
if (clips.Any(c => IsValidClip(c, director)))
return ActionValidity.Valid;
return ActionValidity.NotApplicable;
}
}
[ApplyDefaultUndo]
[MenuEntry("Reset Offsets", MenuPriority.CustomClipActionSection.resetOffset), UsedImplicitly]
class ResetOffsets : ClipAction
{
public override bool Execute(IEnumerable<TimelineClip> clips)
{
AnimationOffsetMenu.ResetClipOffsets(clips.Where(TimelineAnimationUtilities.IsAnimationClip).ToArray());
return true;
}
public override ActionValidity Validate(IEnumerable<TimelineClip> clips)
{
if (!clips.All(TimelineAnimationUtilities.IsAnimationClip))
return ActionValidity.NotApplicable;
return ActionValidity.Valid;
}
}
}