From 2683c04adcaff44f9504248d2c983cd86bd4b3ad Mon Sep 17 00:00:00 2001 From: chai Date: Mon, 31 May 2021 09:43:09 +0800 Subject: *tween --- .../Tween/Editor/TweenAnimationInspector.cs | 78 +++++++++++++++++++--- 1 file changed, 68 insertions(+), 10 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 9780e8c..741458e 100644 --- a/Assets/UI_Extension/Scripts/Animation/Tween/Editor/TweenAnimationInspector.cs +++ b/Assets/UI_Extension/Scripts/Animation/Tween/Editor/TweenAnimationInspector.cs @@ -48,12 +48,16 @@ namespace TweenAnimation HashSet m_EventTimeSet; float m_SelectedEventTime; + Dictionary m_CallbackUnfold; + public void OnEnable() { - if(s_TweenModuleGUI == null) + animation = target as TweenAnimation; + + if (s_TweenModuleGUI == null) s_TweenModuleGUI = new Dictionary(); - m_ShowAnimationTab = true; + m_ShowAnimationTab = false; m_ShowEvents = true; m_ShowModules = true; @@ -70,7 +74,9 @@ namespace TweenAnimation m_DragState = DragState.Release; if (m_PlaybackTimer == null) - m_PlaybackTimer = new PlaybackTimer(); + m_PlaybackTimer = new PlaybackTimer(animation); + + m_CallbackUnfold = new Dictionary(); } public void OnDisable() @@ -113,12 +119,12 @@ namespace TweenAnimation } GUI.Label(new Rect(rect.x + 10, rect.y + 3, 100, 20), "Tween Animation", styles.headerTitle); - Vector2 size = styles.text.CalcSize(new GUIContent(animation.description)); - GUI.Label(new Rect(rect.x + rect.width - size.x - 10, rect.y + 3, 100, 20), animation.description, styles.text); + Vector2 size = styles.text.CalcSize(new GUIContent(animation.name)); + GUI.Label(new Rect(rect.x + rect.width - size.x - 10, rect.y + 3, 100, 20), animation.name, styles.text); if (m_ShowAnimationTab) { - animation.description = ui.GUIText("Description", animation.description); + animation.name = ui.GUIText("Name", animation.name); // 播放风格 animation.playbackStyle = (TweenAnimation.PlaybackStyle) ui.GUIEnum("Playback Style", animation.playbackStyle); @@ -136,7 +142,10 @@ namespace TweenAnimation animation.duration = Mathf.Clamp(duration, 0, float.MaxValue); // 事件触发方向 - animation.eventTriggeredDirection = (TweenAnimation.EventTriggeredDirection)ui.GUIEnumMask("Event Direction", animation.eventTriggeredDirection); + if(animation.playbackStyle == TweenAnimation.PlaybackStyle.PingPong) + { + animation.eventTriggeredDirection = (TweenAnimation.EventTriggeredDirection)ui.GUIEnumMask("Event Direction", animation.eventTriggeredDirection); + } // 是否触发事件 animation.triggerEvents = ui.GUIToggle("Trigger Events", animation.triggerEvents); @@ -151,7 +160,11 @@ namespace TweenAnimation // 时间轴 DrawRuler(1f, true); - + + // default event callbacks + DefaultEventCallbacks(); + + // event list EventList(); } @@ -554,9 +567,11 @@ namespace TweenAnimation m_Pause = !m_Pause; if (m_Pause) { - EditorPlay(); if(!m_Play) + { + EditorPlay(); m_PlaybackTimer.Resume(); + } m_PlaybackTimer.Pause(); m_Play = m_Stop = false; } @@ -588,6 +603,49 @@ namespace TweenAnimation GUI.EndGroup(); } + void DefaultEventCallbacks() + { + Rect evetRect = ui.GetControlRect(15); + + Rect labelRect = evetRect; + labelRect.x += 2; + GUI.Label(labelRect, "Callbacks", styles.textBold); + + EventCallback("onStart"); + EventCallback("onEnd"); + EventCallback("onTurnStart"); + EventCallback("onTurnEnd"); + } + + void EventCallback(string callbackName) + { + Rect rect = ui.GetControlRect(15); + + Rect labelRect = rect; + labelRect.x += 20; + GUI.Label(labelRect, callbackName, styles.text); + + Rect unfoldRect = rect; + unfoldRect.x = rect.x + rect.width - 19; + unfoldRect.width = 13; + unfoldRect.height = 13; + unfoldRect.y += 3; + bool unfold; + if(!m_CallbackUnfold.TryGetValue(callbackName, out unfold)) + { + m_CallbackUnfold.Add(callbackName, false); + } + m_CallbackUnfold[callbackName]= GUI.Button(unfoldRect, (m_CallbackUnfold[callbackName] ? "▲" : "▼"), styles.textSmall) ? !m_CallbackUnfold[callbackName] : m_CallbackUnfold[callbackName]; + if(m_CallbackUnfold[callbackName]) + { + var prop = serializedObject.FindProperty(callbackName); + if(prop != null) + { + EditorGUILayout.PropertyField(prop); + } + } + } + void EventList() { Rect evetRect = ui.GetControlRect(15); @@ -629,7 +687,7 @@ namespace TweenAnimation // event time Rect timeLabelRect = rect; - timeLabelRect.x += 25; + timeLabelRect.x += 20; timeLabelRect.width = 30; timeLabelRect.height = 13; GUI.Label(timeLabelRect, "time:", e.time == m_SelectedEventTime ? styles.textBold : styles.text); -- cgit v1.1-26-g67d0