diff options
author | chai <chaifix@163.com> | 2021-05-31 09:43:09 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2021-05-31 09:43:09 +0800 |
commit | 2683c04adcaff44f9504248d2c983cd86bd4b3ad (patch) | |
tree | 1ab3e0ac80b3ace9a8cb1a1f897dbb73d2612d52 /Assets/UI_Extension/Scripts/Animation/Tween/Editor/TweenControllerInspector.cs | |
parent | 293def05f43c55fce6e90d6b1907c9d9fc63facc (diff) |
*tween
Diffstat (limited to 'Assets/UI_Extension/Scripts/Animation/Tween/Editor/TweenControllerInspector.cs')
-rw-r--r-- | Assets/UI_Extension/Scripts/Animation/Tween/Editor/TweenControllerInspector.cs | 123 |
1 files changed, 123 insertions, 0 deletions
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); + } + + } + + } +} |