MovingItems.cs
3.97 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
using System;
using System.Linq;
using UnityEngine;
using UnityEngine.Timeline;
namespace UnityEditor.Timeline
{
class MovingItems : ItemsPerTrack
{
TrackAsset m_ReferenceTrack;
readonly bool m_AllowTrackSwitch;
readonly Rect[] m_ItemsBoundsOnTrack;
readonly Vector2[] m_ItemsMouseOffsets;
static readonly Rect s_InvisibleBounds = new Rect(float.MaxValue, float.MaxValue, 0.0f, 0.0f);
public TrackAsset originalTrack { get; }
public override TrackAsset targetTrack
{
get
{
if (m_AllowTrackSwitch)
return m_ReferenceTrack;
return originalTrack;
}
}
public bool canDrop;
public double start
{
get { return m_ItemsGroup.start; }
set { m_ItemsGroup.start = value; }
}
public double end
{
get { return m_ItemsGroup.end; }
}
public Rect[] onTrackItemsBounds
{
get { return m_ItemsBoundsOnTrack; }
}
public MovingItems(WindowState state, TrackAsset parentTrack, ITimelineItem[] items, TrackAsset referenceTrack, Vector2 mousePosition, bool allowTrackSwitch)
: base(parentTrack, items)
{
originalTrack = parentTrack;
m_ReferenceTrack = referenceTrack;
m_AllowTrackSwitch = allowTrackSwitch;
m_ItemsBoundsOnTrack = new Rect[items.Length];
m_ItemsMouseOffsets = new Vector2[items.Length];
for (int i = 0; i < items.Length; ++i)
{
var itemGUi = items[i].gui;
if (itemGUi != null)
{
m_ItemsBoundsOnTrack[i] = itemGUi.rect;
m_ItemsMouseOffsets[i] = mousePosition - m_ItemsBoundsOnTrack[i].position;
}
}
canDrop = true;
}
public void SetReferenceTrack(TrackAsset track)
{
m_ReferenceTrack = track;
}
public bool HasAnyDetachedParents()
{
return m_ItemsGroup.items.Any(x => x.parentTrack == null);
}
public void RefreshBounds(WindowState state, Vector2 mousePosition)
{
for (int i = 0; i < m_ItemsGroup.items.Length; ++i)
{
var item = m_ItemsGroup.items[i];
var itemGUI = item.gui;
if (item.parentTrack != null)
{
m_ItemsBoundsOnTrack[i] = itemGUI.visible ? itemGUI.rect : s_InvisibleBounds;
}
else
{
if (targetTrack != null)
{
var trackGUI = (TimelineTrackGUI)TimelineWindow.instance.allTracks.FirstOrDefault(t => t.track == targetTrack);
if (trackGUI == null) return;
var trackRect = trackGUI.boundingRect;
m_ItemsBoundsOnTrack[i] = itemGUI.RectToTimeline(trackRect, state);
}
else
{
m_ItemsBoundsOnTrack[i].position = mousePosition - m_ItemsMouseOffsets[i];
}
}
}
}
public void Draw(bool isValid)
{
for (int i = 0; i < m_ItemsBoundsOnTrack.Length; ++i)
{
var rect = m_ItemsBoundsOnTrack[i];
DrawItemInternal(m_ItemsGroup.items[i], rect, isValid);
}
}
static void DrawItemInternal(ITimelineItem item, Rect rect, bool isValid)
{
var clipGUI = item.gui as TimelineClipGUI;
if (clipGUI != null)
{
if (isValid)
{
clipGUI.DrawGhostClip(rect);
}
else
{
clipGUI.DrawInvalidClip(rect);
}
}
}
}
}