From a0577c8f3415b3173f8d57af631785b43c18d086 Mon Sep 17 00:00:00 2001 From: chai Date: Thu, 8 Jul 2021 22:52:08 +0800 Subject: *Action Editor --- Assets/ActionTool/Editor/ActionPreviewEditor.cs | 138 ++++++++++++++++++++---- 1 file changed, 118 insertions(+), 20 deletions(-) (limited to 'Assets/ActionTool/Editor/ActionPreviewEditor.cs') diff --git a/Assets/ActionTool/Editor/ActionPreviewEditor.cs b/Assets/ActionTool/Editor/ActionPreviewEditor.cs index 9b557128..d0934cf9 100644 --- a/Assets/ActionTool/Editor/ActionPreviewEditor.cs +++ b/Assets/ActionTool/Editor/ActionPreviewEditor.cs @@ -8,22 +8,25 @@ namespace ActionTool public class ActionPreviewEditor : EditorWindow { - private Texture m_UITextureStop; - private Texture m_UITexturePause; - private Texture m_UITexturePlay; - private Texture m_UITextureNext; - private Texture m_UITextureEnd; - private Texture m_UITexturePrevious; - private Texture m_UITextureStart; + Texture m_UITextureStop; + Texture m_UITexturePause; + Texture m_UITexturePlay; + Texture m_UITextureNext; + Texture m_UITextureEnd; + Texture m_UITexturePrevious; + Texture m_UITextureStart; - private GUIStyle m_StyleBold; + GUIStyle m_StyleBold; - private const float kToolbarControlMargin = 5; - private const float kToolbarHeight = 50; - private const float kToolbarControlSize = kToolbarHeight - kToolbarControlMargin * 2; + 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; - private ActionEditorStyles styles; - private ActionEditorUI ui; + ActionEditorStyles styles; + ActionEditorUI ui; private void OnEnable() { @@ -40,6 +43,11 @@ namespace ActionTool styles = ActionEditorStyles.Get(); } + void Update() + { + ActionManager.UpdateFrame(); + } + private void OnDisable() { ActionManager.PreviewWindow = null; @@ -58,6 +66,7 @@ namespace ActionTool GUI_Toolbar(); GUI_Detail(); + GUI_TimeLineView(); } void GUI_Toolbar() @@ -83,7 +92,7 @@ namespace ActionTool Rect rect = new Rect(x, y, kToolbarControlSize, kToolbarControlSize); if(GUI.Button(rect, m_UITextureStart)) { - + ActionManager.Start(); } x += kToolbarControlSize; } @@ -94,7 +103,7 @@ namespace ActionTool Rect rect = new Rect(x, y, kToolbarControlSize, kToolbarControlSize); if (GUI.Button(rect, m_UITexturePrevious)) { - + ActionManager.Previous(); } x += kToolbarControlSize; } @@ -105,7 +114,7 @@ namespace ActionTool Rect rect = new Rect(x, y, kToolbarControlSize, kToolbarControlSize); if (GUI.Button(rect, m_UITextureStop)) { - + ActionManager.Stop(); } x += kToolbarControlSize; } @@ -128,7 +137,7 @@ namespace ActionTool Rect rect = new Rect(x, y, kToolbarControlSize, kToolbarControlSize); if (GUI.Button(rect, m_UITextureNext)) { - + ActionManager.Next(); } x += kToolbarControlSize; } @@ -139,7 +148,7 @@ namespace ActionTool Rect rect = new Rect(x, y, kToolbarControlSize, kToolbarControlSize); if (GUI.Button(rect, m_UITextureEnd)) { - + ActionManager.End(); } x += kToolbarControlSize; } @@ -153,12 +162,101 @@ namespace ActionTool 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 Update() + void GUI_FrameText(ref float y) { - ActionManager.UpdateFrame(); + 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) + { + } } -- cgit v1.1-26-g67d0