From 3bd21c73384906267a2a4c48acdb96df77bd1f67 Mon Sep 17 00:00:00 2001 From: chai Date: Sun, 30 May 2021 11:05:38 +0800 Subject: *tween --- .../Tween/Editor/TweenAnimationInspector.cs | 125 ++++++++++++++++----- 1 file changed, 96 insertions(+), 29 deletions(-) (limited to 'Assets/UI_Extension/Scripts/Animation/Tween/Editor/TweenAnimationInspector.cs') diff --git a/Assets/UI_Extension/Scripts/Animation/Tween/Editor/TweenAnimationInspector.cs b/Assets/UI_Extension/Scripts/Animation/Tween/Editor/TweenAnimationInspector.cs index cc57055..bd98aa8 100644 --- a/Assets/UI_Extension/Scripts/Animation/Tween/Editor/TweenAnimationInspector.cs +++ b/Assets/UI_Extension/Scripts/Animation/Tween/Editor/TweenAnimationInspector.cs @@ -11,6 +11,13 @@ namespace TweenAnimation [CustomEditor(typeof(TweenAnimation), false)] public partial class TweenAnimationInspector : Editor { + static Dictionary s_TweenModuleClasses; + static string[] s_TweenModuleClassNames; + static Dictionary s_TweenModuleGUI; + + static int s_ModuleTabHash = "TweenModuleTab".GetHashCode(); + static int s_ModuleEnabledHash = "TweenModuleEnabled".GetHashCode(); + TweenModuleGUIStyles styles { get @@ -27,17 +34,8 @@ namespace TweenAnimation } } - float value = 20; - TweenAnimation animation; - bool m_ShowAnimationTab = true; - - static Dictionary s_TweenModuleClasses; - static string[] s_TweenModuleClassNames; - static Dictionary s_TweenModuleGUI; - - static int s_ModuleTabHash = "TweenModuleTab".GetHashCode(); - static int s_ModuleEnabledHash = "TweenModuleEnabled".GetHashCode(); + bool m_ShowAnimationTab = false; // 是否在时间轴上显示 bool m_ShowEvents; @@ -65,8 +63,24 @@ namespace TweenAnimation m_EventTimeSet.Clear(); m_SelectedEventTime = -1; + + m_Play = false; + EditorStop(); + + m_DragState = DragState.Release; + + if (m_PlaybackTimer == null) + m_PlaybackTimer = new PlaybackTimer(); } - + + public void OnDisable() + { + m_Play = false; + if (m_Play) + EditorStop(); + m_PlaybackTimer.Reset(); + } + public override void OnInspectorGUI() { animation = target as TweenAnimation; @@ -124,6 +138,9 @@ namespace TweenAnimation // 事件触发方向 animation.eventTriggeredDirection = (TweenAnimation.EventTriggeredDirection)ui.GUIEnumMask("Event Direction", animation.eventTriggeredDirection); + // 是否触发事件 + animation.triggerEvents = ui.GUIToggle("Trigger Events", animation.triggerEvents); + // 是否只触发一次 animation.triggerOnce = ui.GUIToggle("Trigger Once", animation.triggerOnce); @@ -134,7 +151,7 @@ namespace TweenAnimation // 时间轴 DrawRuler(1f, true); - + EventList(); } @@ -211,6 +228,8 @@ namespace TweenAnimation { if (module == null) return; + Event e = Event.current; + string name = module.name; string description = module.description; bool enabled = module.enabled; @@ -228,20 +247,32 @@ namespace TweenAnimation deleteRect.x = rect.x + rect.width - 18; deleteRect.width = 20; deleteRect.height = 20; - if (Event.current.type == EventType.MouseDown || Event.current.type == EventType.MouseUp || Event.current.type == EventType.Layout) - { - module.enabled = GUI.Toggle(checkRect, module.enabled, "", styles.checkmark); - if (GUI.Button(deleteRect, "-", styles.textBoldBig)) - animation.RemoveModule(module); - if (GUI.Button(headerRect, "", styles.headerBg)) - module.unfold = !module.unfold; - } - else if (Event.current.type == EventType.Repaint /*|| Event.current.type == EventType.Layout*/) - { - GUI.Button(headerRect, "", styles.headerBg); - GUI.Toggle(checkRect, enabled, "", styles.checkmark); - GUI.Button(deleteRect, "-", styles.textBoldBig); - } + //if (Event.current.type == EventType.MouseDown || Event.current.type == EventType.MouseUp || Event.current.type == EventType.Layout) + //{ + // module.enabled = GUI.Toggle(checkRect, module.enabled, "", styles.checkmark); + // if (GUI.Button(deleteRect, "-", styles.textBoldBig)) + // animation.RemoveModule(module); + // if (GUI.Button(headerRect, "", styles.headerBg)) + // module.unfold = !module.unfold; + //} + //else if (Event.current.type == EventType.Repaint /*|| Event.current.type == EventType.Layout*/) + //{ + // GUI.Button(headerRect, "", styles.headerBg); + // GUI.Toggle(checkRect, enabled, "", styles.checkmark); + // GUI.Button(deleteRect, "-", styles.textBoldBig); + //} + + //https://answers.unity.com/questions/1562998/how-to-draw-two-button-overlap-in-editor-window-an.html + Rect headerRegion = headerRect; + headerRegion.x += 20; + headerRegion.width -= 50; + GUI.enabled = !(e.isMouse && !headerRegion.Contains(e.mousePosition)); + if (GUI.Button(headerRect, "", styles.headerBg)) + module.unfold = !module.unfold; + GUI.enabled = true; + module.enabled = GUI.Toggle(checkRect, module.enabled, "", styles.checkmark); + if (GUI.Button(deleteRect, "-", styles.textBoldBig)) + animation.RemoveModule(module); Vector2 size = styles.text.CalcSize(new GUIContent(name)); GUI.Label(new Rect(rect.x + 15, rect.y + 2, size.x, 20), name, styles.text); @@ -398,7 +429,7 @@ namespace TweenAnimation for(int i = 0; i < animation.modules.Count; ++i) { TweenModule module = animation.modules[i]; - if(module.unfold) + if(/*module.unfold*/module.enabled) { float left = module.timeOffset / duration * rulerRect.width; float right = (module.timeOffset + module.duration) / duration * rulerRect.width; @@ -409,6 +440,14 @@ namespace TweenAnimation } } + // 绘制playback竖线 + if(bRepaint && (m_Play || m_Pause)) + { + float time = animation.HandleTime(m_PlaybackTimer.time); + float x = (time / animation.duration) * rulerRect.width + 5; + ui.DrawVerticalLineFast(x, yOffBase, yOffBase - (rulerRect.height), Color.red); + } + GL.PopMatrix(); GL.End(); @@ -420,8 +459,9 @@ namespace TweenAnimation if (i % stepSlice == 0 || stepSlice == 10 && i % (stepSlice / 2) == 0) { float time = i * timePerStep; // sec - Vector2 size = styles.text.CalcSize(new GUIContent(time.ToString("f2"))); - GUI.Label(new Rect(rulerRect.x + i * stepPixelWidth - size.x / 2, yOffBase + 2, 50, 15), time.ToString("f2"), styles.text ); + string timeStr = time == 0 ? "0" : time.ToString("f1"); + Vector2 size = styles.text.CalcSize(new GUIContent(timeStr)); + GUI.Label(new Rect(rulerRect.x + i * stepPixelWidth - size.x / 2, yOffBase + 2, 50, 15), timeStr, styles.text ); } } } @@ -499,6 +539,7 @@ namespace TweenAnimation { m_Pause = m_Stop = false; EditorPlay(); + m_PlaybackTimer.Resume(); } } GUI.color = col; @@ -512,7 +553,13 @@ namespace TweenAnimation { m_Pause = !m_Pause; if (m_Pause) + { + EditorPlay(); + if(!m_Play) + m_PlaybackTimer.Resume(); + m_PlaybackTimer.Pause(); m_Play = m_Stop = false; + } } GUI.color = col; @@ -521,10 +568,23 @@ namespace TweenAnimation if (GUI.Button(stopRect, "Stop", styles.miniRight)) { EditorStop(); + m_PlaybackTimer.Stop(); m_Pause = m_Play = false; } } + // playback time + { + if (m_Play || m_Pause) + { + Rect playbackTimeRect = new Rect(100, yOffBase + 23, 90, 20); ; + GUI.Label(playbackTimeRect, "Playback Time: " + m_PlaybackTimer.time.ToString("f1") + "s", styles.text); + } + } + + // 拖拽进度 + DragPlay(rulerRect); + GUI.EndGroup(); } @@ -594,6 +654,7 @@ namespace TweenAnimation unfoldRect.x = rect.x + rect.width - 19; unfoldRect.width = 13; unfoldRect.height = 13; + unfoldRect.y += 3; e.unfold = GUI.Button(unfoldRect, (e.unfold ? "▲" : "▼"), styles.textSmall) ? !e.unfold : e.unfold; if(e.unfold) { @@ -626,5 +687,11 @@ namespace TweenAnimation } } + static EditorWindow s_SceneView; + + private void OnSceneGUI() + { + } + } } \ No newline at end of file -- cgit v1.1-26-g67d0