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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
|
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
namespace ActionTool
{
public class ActionPreviewEditor : EditorWindow
{
Texture m_UITextureStop;
Texture m_UITexturePause;
Texture m_UITexturePlay;
Texture m_UITextureNext;
Texture m_UITextureEnd;
Texture m_UITexturePrevious;
Texture m_UITextureStart;
GUIStyle m_StyleBold;
const float kToolbarControlMargin = 5;
const float kToolbarHeight = 50;
const float kToolbarControlSize = kToolbarHeight - kToolbarControlMargin * 2;
const float kTimeLineViewXOffset = 20;
const float kFrameWidth = 10;
const float kFrameHeight = 20;
ActionEditorStyles styles;
ActionEditorUI ui;
private void OnEnable()
{
titleContent = new GUIContent("Action Preview");
m_UITextureStop = (Texture)Resources.Load("button_control_stop");
m_UITexturePause = (Texture)Resources.Load("button_control_pause");
m_UITexturePlay = (Texture)Resources.Load("button_control_play");
m_UITextureNext = (Texture)Resources.Load("button_control_next");
m_UITextureEnd = (Texture)Resources.Load("button_control_end");
m_UITexturePrevious = (Texture)Resources.Load("button_control_previous");
m_UITextureStart = (Texture)Resources.Load("button_control_start");
styles = ActionEditorStyles.Get();
}
void Update()
{
ActionManager.UpdateFrame();
}
private void OnDisable()
{
ActionManager.PreviewWindow = null;
}
private void OnGUI()
{
if (ActionManager.CurrentAnimationName == null || ActionManager.CurrentAnimationName == "")
{
EditorGUILayout.HelpBox("选择动画", MessageType.Warning);
return;
}
if (styles == null) styles = ActionEditorStyles.Get();
if (ui == null) ui = ActionEditorUI.Get();
GUI_Toolbar();
GUI_Detail();
GUI_TimeLineView();
}
void GUI_Toolbar()
{
float x = 0, y = kToolbarControlMargin;
GUI_Toolbar_BG();
GUI_Toolbar_Start(ref x, ref y);
GUI_Toolbar_Previous(ref x, ref y);
GUI_Toolbar_Stop(ref x, ref y);
GUI_Toolbar_Pause(ref x, ref y);
GUI_Toolbar_Next(ref x, ref y);
GUI_Toolbar_End(ref x, ref y);
}
void GUI_Toolbar_BG()
{
GUI.DrawTexture(new Rect(0, 0, position.width, 50), EditorStyles.toolbar.normal.background);
}
void GUI_Toolbar_Start(ref float x, ref float y)
{
x += kToolbarControlMargin;
Rect rect = new Rect(x, y, kToolbarControlSize, kToolbarControlSize);
if(GUI.Button(rect, m_UITextureStart))
{
ActionManager.Start();
}
x += kToolbarControlSize;
}
void GUI_Toolbar_Previous(ref float x, ref float y)
{
x += kToolbarControlMargin;
Rect rect = new Rect(x, y, kToolbarControlSize, kToolbarControlSize);
if (GUI.Button(rect, m_UITexturePrevious))
{
ActionManager.Previous();
}
x += kToolbarControlSize;
}
void GUI_Toolbar_Stop(ref float x, ref float y)
{
x += kToolbarControlMargin;
Rect rect = new Rect(x, y, kToolbarControlSize, kToolbarControlSize);
if (GUI.Button(rect, m_UITextureStop))
{
ActionManager.Stop();
}
x += kToolbarControlSize;
}
void GUI_Toolbar_Pause(ref float x, ref float y)
{
x += kToolbarControlMargin;
Rect rect = new Rect(x, y, kToolbarControlSize, kToolbarControlSize);
Texture tex = ActionManager.IsPlay ? m_UITexturePlay : m_UITexturePause;
if (GUI.Button(rect, tex))
{
ActionManager.Pause();
}
x += kToolbarControlSize;
}
void GUI_Toolbar_Next(ref float x, ref float y)
{
x += kToolbarControlMargin;
Rect rect = new Rect(x, y, kToolbarControlSize, kToolbarControlSize);
if (GUI.Button(rect, m_UITextureNext))
{
ActionManager.Next();
}
x += kToolbarControlSize;
}
void GUI_Toolbar_End(ref float x, ref float y)
{
x += kToolbarControlMargin;
Rect rect = new Rect(x, y, kToolbarControlSize, kToolbarControlSize);
if (GUI.Button(rect, m_UITextureEnd))
{
ActionManager.End();
}
x += kToolbarControlSize;
}
void GUI_Detail()
{
float y = kToolbarHeight + 5;
float x = 5;
GUI.Label(new Rect(x, y, 105, 20), "Animation Name:");
x += 105;
GUI.Label(new Rect(x, y, 210, 20), ActionManager.CurrentAnimationName, styles.textBold);
x += 200;
}
void GUI_TimeLineView()
{
if (ActionManager.actionData == null)
return;
float y = 80;
GUI_FrameText(ref y);
GUI_Slider(ref y);
GUI_Grid(ref y);
GUI_Events(ref y);
}
void GUI_FrameText(ref float y)
{
ActionData action = ActionManager.actionData;
int sampleCount = (int)action.totalFrame + 1;
Rect rect = new Rect(0, y, 20, 15);
for(int i = 0; i < sampleCount; i++)
{
rect.x = kTimeLineViewXOffset + i * kFrameWidth - 7;
if(i % 5 == 0)
{
Color c = GUI.color;
GUI.color = i % 10 == 0 ? Color.yellow : GUI.color;
GUI.Label(rect, i.ToString(), styles.textSmall);
GUI.color = c;
}
}
y += 15;
}
void GUI_Slider( ref float y)
{
ActionData action = ActionManager.actionData;
Rect rect = new Rect(kTimeLineViewXOffset - 4, y, action.totalFrame * kFrameWidth + 8, 15);
float t = GUI.HorizontalSlider(rect,action.curAnimTimeNormal, 0, 1);
if(t != action.curAnimTimeNormal)
{
if(ActionManager.IsPlay)
ActionManager.Pause();
action.curAnimTimeNormal = t;
}
if(ActionManager.IsPlay)
{
this.Repaint();
}
y += 20;
}
void GUI_Grid(ref float y)
{
ActionData action = ActionManager.actionData;
int sampleCount = (int)action.totalFrame + 1;
Rect bgRect = new Rect(kTimeLineViewXOffset, y, action.totalFrame * kFrameWidth, ActionManager.kMaxEventsPerFrame * kFrameHeight);
GUI.Box(bgRect, "");
ui.defaultUIMaterail.SetPass(0);
GL.PushMatrix();
GL.LoadPixelMatrix();
bool bWin = Application.platform == RuntimePlatform.WindowsEditor;
if (bWin)
GL.Begin(GL.QUADS);
else
GL.Begin(GL.LINES);
Color lineColor = new Color(0.3f, 0.3f, 0.3f);
Color lineColor2 = new Color(0.5f, 0.5f, 0.5f);
for (int i = 0; i < ActionManager.kMaxEventsPerFrame + 1; i++)
{
ui.DrawHorizontalLineFast(y + i * kFrameHeight, kTimeLineViewXOffset, kTimeLineViewXOffset + action.totalFrame * kFrameWidth, lineColor);
}
for(int i = 0; i <= sampleCount; ++i)
{
Color c = i % 5 == 0 ? lineColor2 : lineColor;
float x = kTimeLineViewXOffset + i * kFrameWidth;
x = Mathf.Clamp(x, kTimeLineViewXOffset, kTimeLineViewXOffset + action.totalFrame * kFrameWidth);
ui.DrawVerticalLineFast(x, y, y + ActionManager.kMaxEventsPerFrame * kFrameHeight, c);
}
ui.DrawVerticalLineFast(kTimeLineViewXOffset + bgRect.width * action.curAnimTimeNormal, y, y + ActionManager.kMaxEventsPerFrame * kFrameHeight, Color.red);
GL.PopMatrix();
GL.End();
y += ActionManager.kMaxEventsPerFrame * kFrameHeight;
}
void GUI_Events(ref float y)
{
}
}
}
|