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/ActionPreviewEditor.cs | 83 ++++++++++++++++++++----- 1 file changed, 66 insertions(+), 17 deletions(-) (limited to 'Assets/ActionTool/Editor/ActionPreviewEditor.cs') 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; -- cgit v1.1-26-g67d0