AnimationTrackDrawer.cs
3.28 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
using System;
using System.ComponentModel;
using System.Linq;
using JetBrains.Annotations;
using UnityEngine;
using UnityEditor;
using UnityEngine.Timeline;
namespace UnityEditor.Timeline
{
[CustomTrackDrawer(typeof(AnimationTrack)), UsedImplicitly]
class AnimationTrackDrawer : TrackDrawer
{
internal static class Styles
{
public static readonly GUIContent AnimationButtonOnTooltip = EditorGUIUtility.TrTextContent("", "Avatar Mask enabled\nClick to disable");
public static readonly GUIContent AnimationButtonOffTooltip = EditorGUIUtility.TrTextContent("", "Avatar Mask disabled\nClick to enable");
}
public override bool DrawTrackHeaderButton(Rect rect, TrackAsset track, WindowState state)
{
var animTrack = track as AnimationTrack;
bool hasAvatarMask = animTrack != null && animTrack.avatarMask != null;
if (hasAvatarMask)
{
var style = animTrack.applyAvatarMask
? DirectorStyles.Instance.avatarMaskOn
: DirectorStyles.Instance.avatarMaskOff;
var tooltip = animTrack.applyAvatarMask
? Styles.AnimationButtonOnTooltip
: Styles.AnimationButtonOffTooltip;
if (GUI.Button(rect, tooltip, style))
{
animTrack.applyAvatarMask = !animTrack.applyAvatarMask;
if (state != null)
state.rebuildGraph = true;
}
}
return hasAvatarMask;
}
public override void DrawRecordingBackground(Rect trackRect, TrackAsset trackAsset, Vector2 visibleTime, WindowState state)
{
base.DrawRecordingBackground(trackRect, trackAsset, visibleTime, state);
DrawBorderOfAddedRecordingClip(trackRect, trackAsset, visibleTime, (WindowState)state);
}
static void DrawBorderOfAddedRecordingClip(Rect trackRect, TrackAsset trackAsset, Vector2 visibleTime, WindowState state)
{
if (!state.IsArmedForRecord(trackAsset))
return;
AnimationTrack animTrack = trackAsset as AnimationTrack;
if (animTrack == null || !animTrack.inClipMode)
return;
// make sure there is no clip but we can add one
TimelineClip clip = null;
if (trackAsset.FindRecordingClipAtTime(state.editSequence.time, out clip) || clip != null)
return;
float yMax = trackRect.yMax;
float yMin = trackRect.yMin;
double startGap = 0;
double endGap = 0;
trackAsset.GetGapAtTime(state.editSequence.time, out startGap, out endGap);
if (double.IsInfinity(endGap))
endGap = visibleTime.y;
if (startGap > visibleTime.y || endGap < visibleTime.x)
return;
startGap = Math.Max(startGap, visibleTime.x);
endGap = Math.Min(endGap, visibleTime.y);
float xMin = state.TimeToPixel(startGap);
float xMax = state.TimeToPixel(endGap);
var r = Rect.MinMaxRect(xMin, yMin, xMax, yMax);
ClipDrawer.DrawClipSelectionBorder(r, ClipBorder.Recording(), ClipBlends.kNone);
}
}
}