summaryrefslogtreecommitdiff
path: root/Assets/UI_Extension/Scripts/Animation/Tween/Editor
diff options
context:
space:
mode:
Diffstat (limited to 'Assets/UI_Extension/Scripts/Animation/Tween/Editor')
-rw-r--r--Assets/UI_Extension/Scripts/Animation/Tween/Editor/PlaybackTimer.cs17
-rw-r--r--Assets/UI_Extension/Scripts/Animation/Tween/Editor/TweenAnimationInspector.cs78
-rw-r--r--Assets/UI_Extension/Scripts/Animation/Tween/Editor/TweenAnimationInspector_Play.cs3
-rw-r--r--Assets/UI_Extension/Scripts/Animation/Tween/Editor/TweenControllerInspector.cs123
-rw-r--r--Assets/UI_Extension/Scripts/Animation/Tween/Editor/TweenControllerInspector.cs.meta11
5 files changed, 216 insertions, 16 deletions
diff --git a/Assets/UI_Extension/Scripts/Animation/Tween/Editor/PlaybackTimer.cs b/Assets/UI_Extension/Scripts/Animation/Tween/Editor/PlaybackTimer.cs
index 69b91f7..533fbc8 100644
--- a/Assets/UI_Extension/Scripts/Animation/Tween/Editor/PlaybackTimer.cs
+++ b/Assets/UI_Extension/Scripts/Animation/Tween/Editor/PlaybackTimer.cs
@@ -2,18 +2,24 @@
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
+
namespace TweenAnimation
{
public class PlaybackTimer
{
- // 考虑了Pause的playback时间,没考虑playback limit
+ // 动画
+ private TweenAnimation m_Animation;
+
+ // 考虑了Pause的playback逻辑时间,考虑了playbackLimit
public float time
{
get
{
+ float t = realTime;
if (m_PauseRealTime != -1)
- return m_PauseRealTime - m_StartRealTime;
- return realTime;
+ t = m_PauseRealTime - m_StartRealTime;
+ t = m_Animation.ApplyLimit(t);
+ return t;
}
}
@@ -30,8 +36,9 @@ namespace TweenAnimation
private float m_PauseRealTime;
- public PlaybackTimer()
+ public PlaybackTimer(TweenAnimation animation)
{
+ m_Animation = animation;
Reset();
}
@@ -48,6 +55,8 @@ namespace TweenAnimation
public void Pause()
{
m_PauseRealTime = (float)EditorApplication.timeSinceStartup;
+ float t = m_Animation.ApplyLimit(m_PauseRealTime - m_StartRealTime);
+ m_PauseRealTime = m_StartRealTime + t;
}
public void Stop()
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<float> m_EventTimeSet;
float m_SelectedEventTime;
+ Dictionary<string, bool> m_CallbackUnfold;
+
public void OnEnable()
{
- if(s_TweenModuleGUI == null)
+ animation = target as TweenAnimation;
+
+ if (s_TweenModuleGUI == null)
s_TweenModuleGUI = new Dictionary<string, MethodInfo>();
- 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<string, bool>();
}
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);
diff --git a/Assets/UI_Extension/Scripts/Animation/Tween/Editor/TweenAnimationInspector_Play.cs b/Assets/UI_Extension/Scripts/Animation/Tween/Editor/TweenAnimationInspector_Play.cs
index 647c828..e74aa74 100644
--- a/Assets/UI_Extension/Scripts/Animation/Tween/Editor/TweenAnimationInspector_Play.cs
+++ b/Assets/UI_Extension/Scripts/Animation/Tween/Editor/TweenAnimationInspector_Play.cs
@@ -17,14 +17,13 @@ namespace TweenAnimation
get
{
return m_PlaybackTimer.time;
- float t = animation.ApplyLimit(m_PlaybackTimer.time);
- return t;
}
}
// 编辑器下播放动画
void EditorPlay()
{
+ animation.BeforePlay();
EditorApplication.update -= Update;
EditorApplication.update += Update;
}
diff --git a/Assets/UI_Extension/Scripts/Animation/Tween/Editor/TweenControllerInspector.cs b/Assets/UI_Extension/Scripts/Animation/Tween/Editor/TweenControllerInspector.cs
new file mode 100644
index 0000000..e83e87e
--- /dev/null
+++ b/Assets/UI_Extension/Scripts/Animation/Tween/Editor/TweenControllerInspector.cs
@@ -0,0 +1,123 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+using UnityEditor;
+
+namespace TweenAnimation
+{
+ [CustomEditor(typeof(TweenController), false)]
+ public class TweenControllerInspector : Editor
+ {
+ private TweenController controller;
+
+ public override void OnInspectorGUI()
+ {
+ controller = target as TweenController;
+ if (controller == null)
+ return;
+
+ GUI.changed = false;
+
+ // automatically play on enable
+ Rect autoRect = GUILayoutUtility.GetRect(0f, 20f);
+ autoRect.width = 150;
+ GUI.Label(autoRect, "Auto Play When Enabled");
+ autoRect.x = 190;
+ controller.autoPlayOnEnable = GUI.Toggle(autoRect, controller.autoPlayOnEnable, "");
+
+ // default animation
+ if(controller.autoPlayOnEnable)
+ {
+ Rect defaultRect = GUILayoutUtility.GetRect(0f, 20f);
+ float width = defaultRect.width;
+ defaultRect.width = 150;
+ GUI.Label(defaultRect, "Default Animation");
+ defaultRect.x = 190;
+ defaultRect.width = width - 172;
+ int index = -1;
+ int count = 0;
+ for(int i = 0; i < controller.animations.Count;i++)
+ {
+ if (controller.animations[i] != null)
+ ++count;
+ }
+ string[] displayName = new string[count];
+ for(int i = 0, j = 0; i < controller.animations.Count; ++i)
+ {
+ if (controller.animations[i] == null)
+ continue;
+ if (controller.animations[i].name == controller.defaultAnimation)
+ index = j;
+ displayName[j++] = controller.animations[i].name;
+ }
+ index = EditorGUI.Popup(defaultRect, index, displayName);
+ if(index >= 0 && index < displayName.Length)
+ controller.defaultAnimation = displayName[index];
+ }
+
+ Rect hintRect = GUILayoutUtility.GetRect(0f, 20f);
+ GUI.Label(hintRect, "Animations");
+
+ // animation list
+ if(controller.animations.Count > 0)
+ {
+ List<int> deleted = new List<int>();
+ for (int i = 0; i < controller.animations.Count; ++i)
+ {
+ var animation = controller.animations[i];
+ Rect rect = GUILayoutUtility.GetRect(0f, 20f);
+ Rect buttonRect = rect;
+ buttonRect.width = 20;
+ if (GUI.Button(buttonRect, "-"))
+ {
+ deleted.Add(i);
+ break;
+ }
+ Rect nameRect = rect;
+ nameRect.x = 60;
+ nameRect.width = 100;
+ if (animation)
+ GUI.Label(nameRect, animation.name);
+ else
+ GUI.Label(nameRect, "");
+ Rect animationRect = rect;
+ animationRect.width = rect.width - 178;
+ animationRect.x = 190;
+ var newAnimation = EditorGUI.ObjectField(animationRect, animation, typeof(TweenAnimation), true) as TweenAnimation;
+ if (newAnimation != animation && controller.animations.Contains(newAnimation))
+ {
+ Debug.LogError("Tween Animation'" + newAnimation + "' already added.");
+ }
+ else
+ controller.animations[i] = newAnimation;
+ }
+
+ if (deleted.Count > 0)
+ {
+ List<TweenAnimation> temp = controller.animations;
+ controller.animations = new List<TweenAnimation>();
+ for (int i = 0; i < temp.Count; ++i)
+ {
+ if (!deleted.Contains(i))
+ controller.animations.Add(temp[i]);
+ }
+ }
+
+ GUILayout.Space(3);
+ }
+ // add new
+ Rect addRect = GUILayoutUtility.GetRect(0f, 20f);
+ if (GUI.Button(addRect, "+New Animation"))
+ {
+ controller.animations.Add(null);
+ }
+
+ if(GUI.changed)
+ {
+ EditorUtility.SetDirty(controller);
+ }
+
+ }
+
+ }
+}
diff --git a/Assets/UI_Extension/Scripts/Animation/Tween/Editor/TweenControllerInspector.cs.meta b/Assets/UI_Extension/Scripts/Animation/Tween/Editor/TweenControllerInspector.cs.meta
new file mode 100644
index 0000000..cbcef84
--- /dev/null
+++ b/Assets/UI_Extension/Scripts/Animation/Tween/Editor/TweenControllerInspector.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 7d62716461ba0fc4c9295d14af916587
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant: