From adb364a79f5dd69de08f72072cc2261131314e53 Mon Sep 17 00:00:00 2001 From: chai Date: Thu, 2 Sep 2021 13:01:49 +0800 Subject: +override rootmotion --- Assets/ActionTool/Editor/ActionData.cs | 21 ++++-- Assets/ActionTool/Editor/ActionManager.cs | 22 +++++- Assets/ActionTool/Editor/ActionPreviewEditor.cs | 83 +++++++++++++++++----- Assets/ActionTool/Editor/ActionRootMotionEditor.cs | 83 ++++++++++++++++++++++ .../Editor/ActionRootMotionEditor.cs.meta | 11 +++ 5 files changed, 196 insertions(+), 24 deletions(-) create mode 100644 Assets/ActionTool/Editor/ActionRootMotionEditor.cs create mode 100644 Assets/ActionTool/Editor/ActionRootMotionEditor.cs.meta (limited to 'Assets/ActionTool/Editor') diff --git a/Assets/ActionTool/Editor/ActionData.cs b/Assets/ActionTool/Editor/ActionData.cs index 5e519c3e..82eedee3 100644 --- a/Assets/ActionTool/Editor/ActionData.cs +++ b/Assets/ActionTool/Editor/ActionData.cs @@ -214,17 +214,30 @@ namespace ActionTool m_Animator.Update(0); m_Animator.speed = 0; - if(applyRootMotion && m_RootMotion) + if(applyRootMotion) { + var animData = ActionManager.animationData; + bool overrideRM = animData != null && animData.overrideRootMotion != null; + + if(!overrideRM && m_RootMotion) + { #if true - // Action Tool这里需要转换一下root motion的轴 - m_Animator.transform.position = RootMotionUtility.ExchangeXZ(m_RootMotion.GetRootMotion(normalizeTime)); + // Action Tool这里需要转换一下root motion的轴 + m_Animator.transform.position = RootMotionUtility.ExchangeXZ(m_RootMotion.GetRootMotion(normalizeTime)); #else Vector3 dis = m_RootMotion.GetRootMotionDistance(m_PrevNormalTime, normalizeTime); m_Animator.transform.position += RootMotionUtility.ExchangeXZ(dis); m_PrevNormalTime = normalizeTime; #endif - } + } + else if(overrideRM) + { + if(!ActionRootMotionEditor.IsRecord) + { + + } + } + } } public int GetCurrentFrame() diff --git a/Assets/ActionTool/Editor/ActionManager.cs b/Assets/ActionTool/Editor/ActionManager.cs index 52311140..7c3f1df4 100644 --- a/Assets/ActionTool/Editor/ActionManager.cs +++ b/Assets/ActionTool/Editor/ActionManager.cs @@ -28,6 +28,7 @@ namespace ActionTool public static ActionEventEditor EventEditWindow; public static ActionColliderFrameEditor ColliderFrameWindow; public static ActionColliderEditor ColliderWindow; + public static ActionRootMotionEditor RootMotionEditor; public static ActionToolSettings Settings; @@ -115,12 +116,22 @@ namespace ActionTool private static GameObject s_RootActionTool; private const string kRootActionTool = "RootActionTool"; - public const int kMaxEventsPerFrame = 10; - public static int eventAndBoxCount + public static int MaxEventsPerFrame // 所有帧里面事件最多有几个 { get { - return kMaxEventsPerFrame + (animationData != null ? animationData.GetBoxesCount() : 0); + if (animationData == null) + return 0; + return animationData.GetMaxAnimationEventsCount(); + } + } + + public static int GridRowCount + { + get + { + bool hasRM = animationData != null && animationData.overrideRootMotion != null; + return (MaxEventsPerFrame + 1) + (animationData != null ? animationData.GetBoxesCount() : 0) + (hasRM ? 1 : 0); } } @@ -481,5 +492,10 @@ namespace ActionTool animationData.DeleteEvent(animEvent); } + public static void EditRootMotionOverrideData() + { + RootMotionEditor = EditorWindow.GetWindow(true); + } + } } \ No newline at end of file diff --git a/Assets/ActionTool/Editor/ActionPreviewEditor.cs b/Assets/ActionTool/Editor/ActionPreviewEditor.cs index 73b01857..271c66da 100644 --- a/Assets/ActionTool/Editor/ActionPreviewEditor.cs +++ b/Assets/ActionTool/Editor/ActionPreviewEditor.cs @@ -240,6 +240,9 @@ namespace ActionTool void GUI_Detail(ref float y) { + var actionData = ActionManager.actionData; + var animationData = ActionManager.animationData; + float xl = 5, xr = xl + 105; GUI.Label(new Rect(xl, y, 105, 15), "Animation Name:", styles.textMiddle); @@ -281,7 +284,7 @@ namespace ActionTool y += 15; GUI.Label(new Rect(xl, y, 105, 15), "RootMotion:", styles.textMiddle); - if(ActionManager.actionData.rootMotion != null) + if(actionData.rootMotion != null && (animationData == null || animationData.overrideRootMotion == null)) { width = styles.textMiddleBold.CalcSize(new GUIContent(ActionManager.actionData.rootMotionPath)).x; GUI.Label(new Rect(xr, y, width, 15), ActionManager.actionData.rootMotionPath, styles.textMiddleBold); @@ -292,13 +295,40 @@ namespace ActionTool "Frame Count: " + rootMotion.frameCount ); } - if (GUI.Button(new Rect(xr + width + 10 + 60, y, 60, 15), "Override")) - { - } - } + if(animationData != null) + { + if (GUI.Button(new Rect(xr + width + 10 + 60, y, 60, 15), "Override")) + { + animationData.AddRootMotionOverriderData(); + } + } + } + else if(animationData != null && animationData.overrideRootMotion != null) + { + width = styles.textMiddle.CalcSize(new GUIContent("Override")).x; + GUI.Label(new Rect(xr, y, width, 15), "Override", styles.textMiddle); + if (GUI.Button(new Rect(xr + width + 10, y, 60, 15), "Edit")) + { + ActionManager.EditRootMotionOverrideData(); + } + Color bg = GUI.backgroundColor; + GUI.backgroundColor = Color.red; + if (GUI.Button(new Rect(xr + width + 10 + 70, y, 60, 15), "Delete")) + { + animationData.DeleteRootMotionOverrideData(); + } + GUI.backgroundColor = bg; + } else { - GUI.Label(new Rect(xr, y, 100, 15), "None", styles.textMiddleBold); + GUI.Label(new Rect(xr, y, 50, 15), "None", styles.textMiddleBold); + if(animationData != null) + { + if (GUI.Button(new Rect(xr + 60 + 10 + 60, y, 60, 15), "Override")) + { + animationData.AddRootMotionOverriderData(); + } + } } y += 15; } @@ -416,7 +446,7 @@ namespace ActionTool float y = iy; - float contentHeight = ActionManager.eventAndBoxCount * kFrameHeight + 40; + float contentHeight = ActionManager.GridRowCount * kFrameHeight + 40; Rect content = new Rect(0, 0, ((int)action.totalFrame + 1)* kFrameWidth + 30, contentHeight); float height = 300; if (position.height - kTimeLineViewYOffset > contentHeight + 15) @@ -432,6 +462,7 @@ namespace ActionTool GUI_Slider(ref y); GUI_Grid(ref y); GUI_Events(); + GUI_RM(); GUI_Boxes(); GUI_FrameLine(); @@ -484,12 +515,12 @@ namespace ActionTool ActionData action = ActionManager.actionData; int sampleCount = (int)action.totalFrame + 1; - Rect bgRect = new Rect(kTimeLineViewXOffset, y, sampleCount * kFrameWidth, ActionManager.eventAndBoxCount * kFrameHeight); + Rect bgRect = new Rect(kTimeLineViewXOffset, y, sampleCount * kFrameWidth, ActionManager.GridRowCount * kFrameHeight); GUI.Box(bgRect, ""); Color lineColor = new Color(0.3f, 0.3f, 0.3f); Color lineColor2 = new Color(0.5f, 0.5f, 0.5f); - for (int i = 0; i < ActionManager.eventAndBoxCount + 1; i++) + for (int i = 0; i < ActionManager.GridRowCount + 1; i++) { ui.DrawHorizontalLineFast(y + i * kFrameHeight, kTimeLineViewXOffset, kTimeLineViewXOffset + sampleCount * kFrameWidth, lineColor); } @@ -498,26 +529,44 @@ namespace ActionTool Color c = i % 5 == 0 ? lineColor2 : lineColor; float x = kTimeLineViewXOffset + i * kFrameWidth; //x = Mathf.Clamp(x, kTimeLineViewXOffset, kTimeLineViewXOffset + action.totalFrame * kFrameWidth); - ui.DrawVerticalLineFast(x, y, y + ActionManager.eventAndBoxCount * kFrameHeight, c); + ui.DrawVerticalLineFast(x, y, y + ActionManager.GridRowCount * kFrameHeight, c); } - y += ActionManager.eventAndBoxCount * kFrameHeight; + y += ActionManager.GridRowCount * kFrameHeight; } void GUI_FrameLine() { float y = m_GridY; ActionData action = ActionManager.actionData; - Rect bgRect = new Rect(kTimeLineViewXOffset, y, action.totalFrame * kFrameWidth, ActionManager.eventAndBoxCount * kFrameHeight); + Rect bgRect = new Rect(kTimeLineViewXOffset, y, action.totalFrame * kFrameWidth, ActionManager.GridRowCount * kFrameHeight); ui.defaultUIMaterail.SetPass(0); - ui.DrawVerticalLineFast(kTimeLineViewXOffset + bgRect.width * action.curAnimTimeNormal, y, y + ActionManager.eventAndBoxCount * kFrameHeight, Color.red); + ui.DrawVerticalLineFast(kTimeLineViewXOffset + bgRect.width * action.curAnimTimeNormal, y, y + ActionManager.GridRowCount * kFrameHeight, Color.red); + } + + void GUI_RM() + { + var animData = ActionManager.animationData; + if (animData == null || animData.overrideRootMotion == null) + return; + float y = m_GridY + (ActionManager.MaxEventsPerFrame + 1) * kFrameHeight; + Rect rect = new Rect(kTimeLineViewXOffset - 17, y - 1, 17, kFrameHeight); + if(GUI.Button(rect, "", styles.boxToggle)) + { + ActionManager.EditRootMotionOverrideData(); + } + Rect lb = rect; + lb.y += 3; + GUI.Label(lb, "RM", styles.textBoldSmall); + } void GUI_Boxes() { - float y = m_GridY + ActionManager.kMaxEventsPerFrame * kFrameHeight; - AnimationData animData = ActionManager.animationData; + var animData = ActionManager.animationData; + bool hasRM = animData != null && animData.overrideRootMotion != null; + float y = m_GridY + (ActionManager.MaxEventsPerFrame + 1 + (hasRM ? 1:0)) * kFrameHeight; if (animData == null) return; DrawBoxList(animData.hurtBoxes, ref y, Color.green); @@ -612,7 +661,7 @@ namespace ActionTool return; ActionData action = ActionManager.actionData; int sampleCount = (int)action.totalFrame + 1; - float y = m_GridY + ActionManager.kMaxEventsPerFrame * kFrameHeight; + float y = m_GridY + (ActionManager.MaxEventsPerFrame + 1) * kFrameHeight; Vector2 position = e.mousePosition; int boxCount = ActionManager.animationData.GetBoxesCount(); Rect boxRegion = new Rect(kTimeLineViewXOffset, y, action.totalFrame * kFrameWidth, boxCount * kFrameHeight); @@ -861,7 +910,7 @@ namespace ActionTool ActionData action = ActionManager.actionData; int sampleCount = (int)action.totalFrame + 1; Vector2 position = Event.current.mousePosition; - Rect eventRegion = new Rect(kTimeLineViewXOffset, m_GridY, sampleCount * kFrameWidth, TimelineEventProxy.kMaxEventsPerFrame * kFrameHeight); + Rect eventRegion = new Rect(kTimeLineViewXOffset, m_GridY, sampleCount * kFrameWidth, (ActionManager.MaxEventsPerFrame + 1) * kFrameHeight); if (!eventRegion.Contains(position)) return; diff --git a/Assets/ActionTool/Editor/ActionRootMotionEditor.cs b/Assets/ActionTool/Editor/ActionRootMotionEditor.cs new file mode 100644 index 00000000..ff0dae62 --- /dev/null +++ b/Assets/ActionTool/Editor/ActionRootMotionEditor.cs @@ -0,0 +1,83 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEditor; + +namespace ActionTool +{ + public class ActionRootMotionEditor : EditorWindow + { + ActionEditorStyles styles; + + public static bool IsRecord { get; private set; } + + const float kToolbarControlMargin = 5; + const float kToolbarHeight = 50; + const float kToolbarControlSize = kToolbarHeight - kToolbarControlMargin * 2; + float m_ToolbarOffset = 0; // <= 0 + + Texture m_UITextureRecord; + Texture m_UITextureTakeRecord; + + Texture2D tex; + + private void OnEnable() + { + maxSize = new Vector2(300, 80); + minSize = maxSize; + this.titleContent = new GUIContent("RootMotion Editor"); + + m_UITextureRecord = (Texture)Resources.Load("button_control_record"); + m_UITextureTakeRecord = (Texture)Resources.Load("button_control_takerecord"); + tex = new Texture2D(1, 1, TextureFormat.RGBA32, false); + tex.SetPixel(0, 0, new Color(1f, 0, 0) * 0.8f); + tex.Apply(); + } + + private void OnDisable() + { + + } + + private void Update() + { + + } + + private void OnGUI() + { + if(ActionManager.animationData == null || ActionManager.animationData.overrideRootMotion == null) + { + this.Close(); + return; + } + if (IsRecord) + { + GUI.DrawTexture(new Rect(0, 0, maxSize.x, maxSize.y), tex, ScaleMode.StretchToFill); + } + float x = m_ToolbarOffset, y = kToolbarControlMargin; + GUI_Record(ref x, ref y); + GUI_TakeRecord(ref x, ref y); + } + + void GUI_Record(ref float x, ref float y) + { + x += kToolbarControlMargin; + Rect rect = new Rect(x, y, kToolbarControlSize, kToolbarControlSize); + IsRecord = GUI.Toggle(rect, IsRecord, m_UITextureRecord, GUI.skin.button); + x += kToolbarControlSize; + } + + void GUI_TakeRecord(ref float x, ref float y) + { + x += kToolbarControlMargin; + Rect rect = new Rect(x, y, kToolbarControlSize, kToolbarControlSize); + if (GUI.Button(rect, m_UITextureTakeRecord)) + { + + } + x += kToolbarControlSize; + } + + } +} \ No newline at end of file diff --git a/Assets/ActionTool/Editor/ActionRootMotionEditor.cs.meta b/Assets/ActionTool/Editor/ActionRootMotionEditor.cs.meta new file mode 100644 index 00000000..599c18ad --- /dev/null +++ b/Assets/ActionTool/Editor/ActionRootMotionEditor.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 2e61eeb773ddf2e478e01d9b6a5ab786 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: -- cgit v1.1-26-g67d0