From 754ceacd8ab62e7094f1827ae45ea16a502725ad Mon Sep 17 00:00:00 2001 From: chai Date: Fri, 6 Aug 2021 19:02:03 +0800 Subject: *curve --- Assets/ActionTool/Editor/ActionData.cs | 12 ++-- Assets/ActionTool/Editor/ActionManager.cs | 4 +- Assets/ActionTool/Editor/ActionPreviewEditor.cs | 53 +++++++++++++++-- .../ActionTool/Editor/ActionToolSettingsEditor.cs | 2 +- Assets/ActionTool/Editor/AnimationCurveEditor.cs | 54 +++++++++++++++++ .../ActionTool/Editor/AnimationCurveEditor.cs.meta | 11 ++++ Assets/ActionTool/Editor/AnimationToggleEditor.cs | 69 ++++++++++++++++++++++ .../Editor/AnimationToggleEditor.cs.meta | 11 ++++ 8 files changed, 201 insertions(+), 15 deletions(-) create mode 100644 Assets/ActionTool/Editor/AnimationCurveEditor.cs create mode 100644 Assets/ActionTool/Editor/AnimationCurveEditor.cs.meta create mode 100644 Assets/ActionTool/Editor/AnimationToggleEditor.cs create mode 100644 Assets/ActionTool/Editor/AnimationToggleEditor.cs.meta (limited to 'Assets/ActionTool/Editor') diff --git a/Assets/ActionTool/Editor/ActionData.cs b/Assets/ActionTool/Editor/ActionData.cs index 6993b378..600eccc5 100644 --- a/Assets/ActionTool/Editor/ActionData.cs +++ b/Assets/ActionTool/Editor/ActionData.cs @@ -20,7 +20,7 @@ namespace ActionTool private AnimationEventBase m_CurEventInfo; // 当前正在编辑的event - private UnitTimeline m_Timeline; + private TimelineEventProxy m_TimelineEventProxy; #region metadata private float m_TotalFrame; //timeline采样的总帧数 @@ -82,7 +82,7 @@ namespace ActionTool m_PrevLocalTime = 0; m_Animator.Play(kStateName, 0, 0); m_RootMotion = rootmotion; - m_Timeline = m_Animator.gameObject.GetOrAddComponent(); + m_TimelineEventProxy = new TimelineEventProxy(animator.gameObject.transform); } public void SetCurrentAnimTime(float time) @@ -161,7 +161,7 @@ namespace ActionTool AnimationData animData = ActionManager.animationData; if (animData) { - AnimationCurve curve = animData.curve; + AnimationCurve curve = animData.speedCurve; deltaFrame *= curve.Evaluate(normalizeTime); } } @@ -220,11 +220,11 @@ namespace ActionTool public void RunEvent() { - if (m_Timeline != null) - m_Timeline.ExecuteAnimationEvents(ActionManager.animationData, m_CurAnimFrame); + if (m_TimelineEventProxy != null) + m_TimelineEventProxy.ExecuteAnimationEvents(ActionManager.animationData, m_CurAnimFrame); } - public void CreateEvent(UnitTimeline.EEventType eventtype, int startFrame) + public void CreateEvent(TimelineEventProxy.EEventType eventtype, int startFrame) { var classes = Assembly .GetAssembly(typeof(AnimationEventBase)) diff --git a/Assets/ActionTool/Editor/ActionManager.cs b/Assets/ActionTool/Editor/ActionManager.cs index deb7e3a1..af3935a7 100644 --- a/Assets/ActionTool/Editor/ActionManager.cs +++ b/Assets/ActionTool/Editor/ActionManager.cs @@ -435,7 +435,7 @@ namespace ActionTool public static void AddNewEvent(object param) { EventParam eventParam = (EventParam )param; - string eventName = eventParam.eventName; // UnitTimeline.EEventType + string eventName = eventParam.eventName; // TimelineEventProxy.EEventType int frame = eventParam.frame; Debug.Log("[ActionTool] Add new event " + eventName); if (animationData == null) @@ -443,7 +443,7 @@ namespace ActionTool Debug.LogError("[ActionTool] 没有animation data数据"); return; } - Type type = UnitTimeline.GetTypeByName(eventName); + Type type = TimelineEventProxy.GetTypeByName(eventName); if(type == null) { Debug.LogError("[ActionTool] 没有创建对应的类, " + eventName); diff --git a/Assets/ActionTool/Editor/ActionPreviewEditor.cs b/Assets/ActionTool/Editor/ActionPreviewEditor.cs index dc855fad..32731deb 100644 --- a/Assets/ActionTool/Editor/ActionPreviewEditor.cs +++ b/Assets/ActionTool/Editor/ActionPreviewEditor.cs @@ -102,7 +102,10 @@ namespace ActionTool float y = kToolbarHeight + 5; GUI_Detail(ref y); + GUI_Toggle(ref y); + GUI_Curves(ref y); GUI_Curve(ref y); + y += 5; GUI_Setting(ref y); GUI_TimeLineView(ref y); } @@ -293,19 +296,57 @@ namespace ActionTool float x = 5; GUI.Label(new Rect(x, y, 105, 15), "Speed Curve:", styles.textMiddle); x += 105; - animData.curve = EditorGUI.CurveField(new Rect(x, y, 210, 15), animData.curve); + animData.speedCurve = EditorGUI.CurveField(new Rect(x, y, 210, 15), animData.speedCurve); ui.DrawVerticalLineFast(x + 210 * ActionManager.actionData.curAnimTimeNormal, y , y + 15, Color.red); - y += 20; + y += 15; } - void GUI_Setting(ref float y) + void GUI_Toggle(ref float y) + { + AnimationData animData = ActionManager.animationData; + if (animData == null) + return; + var toggles = animData.toggles; + float x = 5; + GUI.Label(new Rect(x, y, 105, 15), "Toggles:", styles.textMiddle); + x += 105; + GUI.Label(new Rect(x, y, 10, 15), (toggles != null ? toggles.Count : 0).ToString(), styles.textMiddleBold); + //if(toggles != null && toggles.Count > 0) + //{ + x += 20; + if(GUI.Button(new Rect(x, y, 50, 15), "Edit")) + { + EditorWindow.GetWindow(true); + } + //} + y += 15; + } + void GUI_Curves(ref float y) + { + AnimationData animData = ActionManager.animationData; + if (animData == null) + return; + var curves = animData.curves; + float x = 5; + GUI.Label(new Rect(x, y, 105, 15), "Curves:", styles.textMiddle); + x += 105; + GUI.Label(new Rect(x, y, 10, 15), (curves != null ? curves.Count : 0).ToString(), styles.textMiddleBold); + x += 20; + if (GUI.Button(new Rect(x, y, 50, 15), "Edit")) + { + EditorWindow.GetWindow(true); + } + y += 15; + } + + void GUI_Setting(ref float y) { ActionData action = ActionManager.actionData; float x = 5; action.applyRootMotion = GUI.Toggle(new Rect(x, y, 120, 15), action.applyRootMotion, "Apply RootMotion", styles.toggleSmallBold); x += 130; - action.applyCurve = GUI.Toggle(new Rect(x, y, 120, 15), action.applyCurve, "Apply Curve", styles.toggleSmallBold); + action.applyCurve = GUI.Toggle(new Rect(x, y, 120, 15), action.applyCurve, "Apply SpeedCurve", styles.toggleSmallBold); y += 20; } @@ -735,7 +776,7 @@ namespace ActionTool ActionData action = ActionManager.actionData; Vector2 position = Event.current.mousePosition; - Rect eventRegion = new Rect(kTimeLineViewXOffset, m_GridY, action.totalFrame * kFrameWidth, UnitTimeline.kMaxEventsPerFrame * kFrameHeight); + Rect eventRegion = new Rect(kTimeLineViewXOffset, m_GridY, action.totalFrame * kFrameWidth, TimelineEventProxy.kMaxEventsPerFrame * kFrameHeight); if (!eventRegion.Contains(position)) return; @@ -743,7 +784,7 @@ namespace ActionTool int frame = (int)(pos.x / kFrameWidth); GenericMenu eventMenu = new GenericMenu(); - foreach(var name in Enum.GetNames(typeof(UnitTimeline.EEventType))) + foreach(var name in Enum.GetNames(typeof(TimelineEventProxy.EEventType))) { GUIContent item = null; string shortName = name.Replace("Event", ""); diff --git a/Assets/ActionTool/Editor/ActionToolSettingsEditor.cs b/Assets/ActionTool/Editor/ActionToolSettingsEditor.cs index 2afde647..c35688dd 100644 --- a/Assets/ActionTool/Editor/ActionToolSettingsEditor.cs +++ b/Assets/ActionTool/Editor/ActionToolSettingsEditor.cs @@ -35,7 +35,7 @@ public class ActionToolSettingsEditor : Editor EditorGUI.BeginChangeCheck(); - foreach (var name in Enum.GetNames(typeof(UnitTimeline.EEventType))) + foreach (var name in Enum.GetNames(typeof(TimelineEventProxy.EEventType))) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField(name); diff --git a/Assets/ActionTool/Editor/AnimationCurveEditor.cs b/Assets/ActionTool/Editor/AnimationCurveEditor.cs new file mode 100644 index 00000000..fe19d2cf --- /dev/null +++ b/Assets/ActionTool/Editor/AnimationCurveEditor.cs @@ -0,0 +1,54 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEditor; + +namespace ActionTool +{ + + [CustomPropertyDrawer(typeof(CurveDictionary))] + public class CurveDictionaryDrawer : SerializableDictionaryPropertyDrawer { } + + public class AnimationCurveEditor : EditorWindow + { + + SerializedObject obj; + + private void OnEnable() + { + titleContent = new GUIContent("Curves"); + maxSize = new Vector2(300, 200); + minSize = maxSize; + } + + private void OnDisable() + { + } + + private void Update() + { + } + + private void OnGUI() + { + AnimationData animData = ActionManager.animationData; + if (animData == null) + { + this.Close(); + return; + } + + if (obj == null || obj.targetObject != animData) + { + obj = new SerializedObject(animData); + } + + var curves = obj.FindProperty("curves"); + EditorGUILayout.PropertyField(curves, true); + if (obj.ApplyModifiedProperties()) + { + } + } + } + +} diff --git a/Assets/ActionTool/Editor/AnimationCurveEditor.cs.meta b/Assets/ActionTool/Editor/AnimationCurveEditor.cs.meta new file mode 100644 index 00000000..fb35d0db --- /dev/null +++ b/Assets/ActionTool/Editor/AnimationCurveEditor.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: e9fc645a569609847964fd93876b8d5d +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ActionTool/Editor/AnimationToggleEditor.cs b/Assets/ActionTool/Editor/AnimationToggleEditor.cs new file mode 100644 index 00000000..fc153567 --- /dev/null +++ b/Assets/ActionTool/Editor/AnimationToggleEditor.cs @@ -0,0 +1,69 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEditor; + +namespace ActionTool +{ + + + [CustomPropertyDrawer(typeof(ToggleTimeDictionary))] + public class ToggleTimeDictionaryDrawer : SerializableDictionaryPropertyDrawer { } + + public class AnimationToggleEditor : EditorWindow + { + + SerializedObject obj; + + private void OnEnable() + { + titleContent = new GUIContent("Toggles"); + maxSize = new Vector2(300, 200); + minSize = maxSize; + } + + private void OnDisable() + { + } + + private void Update() + { + } + + private void OnGUI() + { + AnimationData animData = ActionManager.animationData; + if (animData == null) + { + this.Close(); + return; + } + + if (obj == null || obj.targetObject != animData) + { + obj = new SerializedObject(animData); + } + + var toggles = obj.FindProperty("toggles"); + EditorGUILayout.PropertyField(toggles, true); + + if(obj.ApplyModifiedProperties()) + { + if (animData.toggles != null && animData.toggles.Count > 0) + { + List keys = new List(animData.toggles.Keys); + for(int i = 0; i < keys.Count; ++i) + { + Vector2 minMax = animData.toggles[keys[i]]; + minMax.x = Mathf.Clamp(minMax.x, 0, 1); + minMax.y = Mathf.Clamp(minMax.y, 0, 1); + minMax.x = Mathf.Clamp(minMax.x, 0, minMax.y); + minMax.y = Mathf.Clamp(minMax.y, minMax.x, 1); + animData.toggles[keys[i]] = minMax; + } + } + } + } + } + +} diff --git a/Assets/ActionTool/Editor/AnimationToggleEditor.cs.meta b/Assets/ActionTool/Editor/AnimationToggleEditor.cs.meta new file mode 100644 index 00000000..2be25d40 --- /dev/null +++ b/Assets/ActionTool/Editor/AnimationToggleEditor.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 11f79c8cc79fb9e449a43bf66fd1c8f0 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: -- cgit v1.1-26-g67d0