|
@@ -0,0 +1,294 @@
|
|
|
+using System.Collections;
|
|
|
+using System.Collections.Generic;
|
|
|
+using Core.UI.UTool.UITween;
|
|
|
+using UnityEditor;
|
|
|
+using UnityEngine;
|
|
|
+
|
|
|
+[CustomEditor(typeof(UITweenController))]
|
|
|
+public class UITweenControllerInspector : Editor
|
|
|
+{
|
|
|
+ private UITweenController _uiTweenController;
|
|
|
+
|
|
|
+ // private float currValue;
|
|
|
+
|
|
|
+ public override void OnInspectorGUI()
|
|
|
+ {
|
|
|
+ _uiTweenController = serializedObject.targetObject as UITweenController;
|
|
|
+ if (_uiTweenController == null)
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ EditorGUILayout.BeginHorizontal();
|
|
|
+ EditorGUILayout.ObjectField("动画资源", _uiTweenController.TweenAssetInfo, typeof(TweenAssetInfo), false);
|
|
|
+
|
|
|
+ if (_uiTweenController.TweenAssetInfo == null)
|
|
|
+ {
|
|
|
+ if (GUILayout.Button("创建一个动画资源"))
|
|
|
+ {
|
|
|
+ string selectedFolder = EditorUtility.OpenFolderPanel("选择文件夹", "Assets/Res/", "");
|
|
|
+
|
|
|
+ if (!string.IsNullOrEmpty(selectedFolder))
|
|
|
+ {
|
|
|
+ string path = selectedFolder.Replace(Application.dataPath, "Assets");
|
|
|
+ _uiTweenController.TweenAssetInfo = ScriptableObject.CreateInstance<TweenAssetInfo>();
|
|
|
+ AssetDatabase.CreateAsset(_uiTweenController.TweenAssetInfo,
|
|
|
+ path + $"/TweenAssetInfo{_uiTweenController.gameObject.name}.asset");
|
|
|
+ AssetDatabase.SaveAssets();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ EditorGUILayout.EndHorizontal();
|
|
|
+ if (_uiTweenController.TweenAssetInfo == null)
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ _uiTweenController.SetMaxTime();
|
|
|
+ EditorGUI.BeginChangeCheck();
|
|
|
+ _uiTweenController.currTime = EditorGUILayout.Slider(_uiTweenController.currTime, 0, _uiTweenController.maxDuration);
|
|
|
+ if (EditorGUI.EndChangeCheck())
|
|
|
+ {
|
|
|
+ if (!_uiTweenController.isUpdate)
|
|
|
+ {
|
|
|
+ _uiTweenController.JumpToTime(_uiTweenController.currTime);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (GUILayout.Button("播放"))
|
|
|
+ {
|
|
|
+ _uiTweenController.StartPlay();
|
|
|
+ }
|
|
|
+
|
|
|
+ _uiTweenController.TargetFoldout = EditorGUILayout.Foldout(_uiTweenController.TargetFoldout,
|
|
|
+ "目标");
|
|
|
+ if (_uiTweenController.TargetFoldout)
|
|
|
+ {
|
|
|
+ EditorGUI.indentLevel++;
|
|
|
+ for (int i = 0; i < _uiTweenController.allTargets.Count; i++)
|
|
|
+ {
|
|
|
+ Object o = _uiTweenController.allTargets[i];
|
|
|
+ Color color = GUI.color;
|
|
|
+ if (o == null)
|
|
|
+ {
|
|
|
+ GUI.color = Color.red;
|
|
|
+ }
|
|
|
+
|
|
|
+ _uiTweenController.allTargets[i] =
|
|
|
+ EditorGUILayout.ObjectField($"第{i + 1}个对象{o}", o, typeof(Object), true);
|
|
|
+ GUI.color = color;
|
|
|
+ }
|
|
|
+
|
|
|
+ EditorGUI.indentLevel--;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (_uiTweenController.allTargets.Count > _uiTweenController.TweenAssetInfo.allTweenInfo.Count)
|
|
|
+ {
|
|
|
+ for (int i = _uiTweenController.allTargets.Count - 1;
|
|
|
+ i >= _uiTweenController.TweenAssetInfo.allTweenInfo.Count;
|
|
|
+ i--)
|
|
|
+ {
|
|
|
+ _uiTweenController.allTargets.RemoveAt(i);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (_uiTweenController.allTargets.Count < _uiTweenController.TweenAssetInfo.allTweenInfo.Count)
|
|
|
+ {
|
|
|
+ for (int i = _uiTweenController.allTargets.Count;
|
|
|
+ i < _uiTweenController.TweenAssetInfo.allTweenInfo.Count;
|
|
|
+ i++)
|
|
|
+ {
|
|
|
+ _uiTweenController.allTargets.Add(new Object());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ EditorGUI.BeginChangeCheck();
|
|
|
+ for (int i = 0; i < _uiTweenController.TweenAssetInfo.allTweenInfo.Count; i++)
|
|
|
+ {
|
|
|
+ TweenEntity tweenEntity = _uiTweenController.TweenAssetInfo.allTweenInfo[i];
|
|
|
+
|
|
|
+
|
|
|
+ Object o = _uiTweenController.allTargets[i];
|
|
|
+ DrawTweenEntity(tweenEntity, o, i);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (GUILayout.Button("添加动画"))
|
|
|
+ {
|
|
|
+ _uiTweenController.TweenAssetInfo.allTweenInfo.Add(new TweenEntity()
|
|
|
+ { TweenBasic = new TweenTransform() { } });
|
|
|
+ _uiTweenController.allTargets.Add(new Object());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (EditorGUI.EndChangeCheck())
|
|
|
+ {
|
|
|
+ EditorUtility.SetDirty(_uiTweenController.TweenAssetInfo);
|
|
|
+ AssetDatabase.SaveAssets();
|
|
|
+ }
|
|
|
+
|
|
|
+ serializedObject.ApplyModifiedProperties();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void DrawTweenEntity(TweenEntity tweenEntity, Object ob, int index)
|
|
|
+ {
|
|
|
+ Color color = GUI.color;
|
|
|
+ if (ob == null)
|
|
|
+ {
|
|
|
+ GUI.color = Color.red;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ tweenEntity.Foldout = EditorGUILayout.Foldout(tweenEntity.Foldout,
|
|
|
+ tweenEntity.TweenType.ToString());
|
|
|
+ GUI.color = color;
|
|
|
+ if (tweenEntity.Foldout)
|
|
|
+ {
|
|
|
+ EditorGUI.indentLevel++;
|
|
|
+ // 设置背景颜色
|
|
|
+ EditorGUILayout.BeginHorizontal();
|
|
|
+ ob = (Object)EditorGUILayout.ObjectField("目标", ob, typeof(Object));
|
|
|
+ _uiTweenController.allTargets[index] = ob;
|
|
|
+ if (GUILayout.Button("-"))
|
|
|
+ {
|
|
|
+ _uiTweenController.TweenAssetInfo.allTweenInfo.RemoveAt(index);
|
|
|
+ _uiTweenController.allTargets.RemoveAt(index);
|
|
|
+ }
|
|
|
+
|
|
|
+ EditorGUILayout.EndHorizontal();
|
|
|
+
|
|
|
+ tweenEntity.delay = EditorGUILayout.FloatField("延迟", tweenEntity.delay);
|
|
|
+ tweenEntity.duration = EditorGUILayout.FloatField("持续时间", tweenEntity.duration);
|
|
|
+ TweenType tweenType = tweenEntity.TweenType;
|
|
|
+ tweenEntity.TweenType = (TweenType)EditorGUILayout.EnumPopup("类型", tweenEntity.TweenType);
|
|
|
+ if (tweenType != tweenEntity.TweenType)
|
|
|
+ {
|
|
|
+ tweenEntity.Map[tweenType] = tweenEntity.TweenBasic;
|
|
|
+ tweenEntity.Claer();
|
|
|
+ switch (tweenEntity.TweenType)
|
|
|
+ {
|
|
|
+ case TweenType.RectTransform:
|
|
|
+ tweenEntity.TweenBasic = new TweenTransform();
|
|
|
+ break;
|
|
|
+ case TweenType.CanvasGroup:
|
|
|
+ tweenEntity.TweenCanvasGroup = new TweenCanvasGroup();
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ switch (tweenEntity.TweenType)
|
|
|
+ {
|
|
|
+ case TweenType.RectTransform:
|
|
|
+ EditorGUILayout.BeginHorizontal();
|
|
|
+ tweenEntity.TweenBasic.Foldout = EditorGUILayout.Foldout(tweenEntity.TweenBasic.Foldout,
|
|
|
+ "效果");
|
|
|
+ if (GUILayout.Button("+"))
|
|
|
+ {
|
|
|
+ tweenEntity.TweenBasic.TweenRectTransformInfos.Add(new TweenRectTransformInfo());
|
|
|
+ }
|
|
|
+
|
|
|
+ EditorGUILayout.EndHorizontal();
|
|
|
+ DrawTweenTransform(tweenEntity.TweenBasic, ob);
|
|
|
+ break;
|
|
|
+ case TweenType.CanvasGroup:
|
|
|
+ tweenEntity.TweenCanvasGroup.Foldout = EditorGUILayout.Foldout(tweenEntity.TweenCanvasGroup.Foldout,
|
|
|
+ "效果");
|
|
|
+ DrawTweenCanvasGroup(tweenEntity.TweenCanvasGroup, ob);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ EditorGUI.indentLevel--;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void DrawTweenCanvasGroup(TweenCanvasGroup tweenCanvasGroup, Object ob)
|
|
|
+ {
|
|
|
+ if (tweenCanvasGroup.Foldout)
|
|
|
+ {
|
|
|
+ EditorGUI.indentLevel++;
|
|
|
+
|
|
|
+ tweenCanvasGroup.TweenLerpType =
|
|
|
+ (TweenLerpType)EditorGUILayout.EnumPopup("插值类型", tweenCanvasGroup.TweenLerpType);
|
|
|
+ // tweenCanvasGroup.CanvasGroup =
|
|
|
+ // (CanvasGroup)EditorGUILayout.ObjectField("目标", tweenCanvasGroup.CanvasGroup, typeof(CanvasGroup));
|
|
|
+ switch (tweenCanvasGroup.TweenLerpType)
|
|
|
+ {
|
|
|
+ case TweenLerpType.Default:
|
|
|
+ tweenCanvasGroup.StartAlpha = EditorGUILayout.FloatField("起始透明度", tweenCanvasGroup.StartAlpha);
|
|
|
+ tweenCanvasGroup.EndAlpha = EditorGUILayout.FloatField("结束透明度", tweenCanvasGroup.EndAlpha);
|
|
|
+ break;
|
|
|
+ case TweenLerpType.Curve:
|
|
|
+ tweenCanvasGroup.startX = EditorGUILayout.CurveField("透明度", tweenCanvasGroup.startX);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ EditorGUI.indentLevel--;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void DrawTweenTransform(TweenTransform tweenTransform, Object ob)
|
|
|
+ {
|
|
|
+ if (tweenTransform.Foldout)
|
|
|
+ {
|
|
|
+ EditorGUI.indentLevel++;
|
|
|
+ EditorGUILayout.BeginHorizontal();
|
|
|
+ // tweenTransform.RectTransform =
|
|
|
+ // (RectTransform)EditorGUILayout.ObjectField("目标", tweenTransform.RectTransform, typeof(RectTransform));
|
|
|
+
|
|
|
+
|
|
|
+ EditorGUILayout.EndHorizontal();
|
|
|
+ EditorGUI.indentLevel++;
|
|
|
+ for (int i = 0; i < tweenTransform.TweenRectTransformInfos.Count; i++)
|
|
|
+ {
|
|
|
+ bool isDelect = DrawTweenRectTransformInfo(tweenTransform.TweenRectTransformInfos[i]);
|
|
|
+ if (isDelect)
|
|
|
+ {
|
|
|
+ tweenTransform.TweenRectTransformInfos.RemoveAt(i);
|
|
|
+ }
|
|
|
+
|
|
|
+ EditorGUILayout.Space(10);
|
|
|
+ }
|
|
|
+
|
|
|
+ EditorGUI.indentLevel--;
|
|
|
+ EditorGUI.indentLevel--;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private bool DrawTweenRectTransformInfo(TweenRectTransformInfo tweenRectTransformInfo)
|
|
|
+ {
|
|
|
+ bool isDele = false;
|
|
|
+ EditorGUILayout.BeginHorizontal();
|
|
|
+ tweenRectTransformInfo.TweenRectTransformType =
|
|
|
+ (TweenRectTransformType)EditorGUILayout.EnumPopup("类型", tweenRectTransformInfo.TweenRectTransformType);
|
|
|
+ if (GUILayout.Button("-"))
|
|
|
+ {
|
|
|
+ isDele = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ EditorGUILayout.EndHorizontal();
|
|
|
+
|
|
|
+ tweenRectTransformInfo.TweenLerpType =
|
|
|
+ (TweenLerpType)EditorGUILayout.EnumPopup("插值类型", tweenRectTransformInfo.TweenLerpType);
|
|
|
+ switch (tweenRectTransformInfo.TweenRectTransformType)
|
|
|
+ {
|
|
|
+ case TweenRectTransformType.Position:
|
|
|
+ case TweenRectTransformType.Rotation:
|
|
|
+ case TweenRectTransformType.Scale:
|
|
|
+ switch (tweenRectTransformInfo.TweenLerpType)
|
|
|
+ {
|
|
|
+ case TweenLerpType.Default:
|
|
|
+ tweenRectTransformInfo.Start = EditorGUILayout.Vector3Field("起始", tweenRectTransformInfo.Start);
|
|
|
+ tweenRectTransformInfo.End = EditorGUILayout.Vector3Field("结束", tweenRectTransformInfo.End);
|
|
|
+ break;
|
|
|
+ case TweenLerpType.Curve:
|
|
|
+ tweenRectTransformInfo.startX = EditorGUILayout.CurveField("X", tweenRectTransformInfo.startX);
|
|
|
+ tweenRectTransformInfo.startY = EditorGUILayout.CurveField("Y", tweenRectTransformInfo.startY);
|
|
|
+ tweenRectTransformInfo.startZ = EditorGUILayout.CurveField("Z", tweenRectTransformInfo.startZ);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ return isDele;
|
|
|
+ }
|
|
|
+}
|