From 7a73788fec18aa8648a4ff7d1d86760b22908513 Mon Sep 17 00:00:00 2001 From: chai Date: Thu, 2 Sep 2021 16:50:41 +0800 Subject: *misc --- Assets/ActionTool/Editor/ActionData.cs | 40 +++++++++++++-------- Assets/ActionTool/Editor/ActionEditorStyles.cs | 10 ++++++ Assets/ActionTool/Editor/ActionManager.cs | 3 +- Assets/ActionTool/Editor/ActionPreviewEditor.cs | 28 ++++++++++++--- Assets/ActionTool/Editor/ActionRootMotionEditor.cs | 41 +++++++++++++++++++--- 5 files changed, 97 insertions(+), 25 deletions(-) (limited to 'Assets/ActionTool') diff --git a/Assets/ActionTool/Editor/ActionData.cs b/Assets/ActionTool/Editor/ActionData.cs index 82eedee3..13324342 100644 --- a/Assets/ActionTool/Editor/ActionData.cs +++ b/Assets/ActionTool/Editor/ActionData.cs @@ -52,8 +52,9 @@ namespace ActionTool private double m_PrevLocalTime; private float m_PrevNormalTime; + private int m_PrevAnimEventFrame; // 上次的帧数(整数) - private bool m_NotApplyCurves; + private bool m_NotApplyCurves; public bool applyCurves { get { return !m_NotApplyCurves; } set { m_NotApplyCurves = !value; } } // 是否开启curve控制速度 private bool m_NotApplyCurve; public bool applyCurve { get { return !m_NotApplyCurve; } set { m_NotApplyCurve = !value; } } // 是否开启curve控制速度 @@ -209,36 +210,47 @@ namespace ActionTool float normalizeTime = m_CurAnimFrame / m_TotalFrame; - m_Animator.speed = 1; - m_Animator.Play(kStateName, 0, normalizeTime); - m_Animator.Update(0); - m_Animator.speed = 0; - if(applyRootMotion) { var animData = ActionManager.animationData; - bool overrideRM = animData != null && animData.overrideRootMotion != null; + bool overrideRM = animData != null && animData.overrideRootMotion == true; 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; + 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) { - + m_Animator.transform.position = animData.rootMotionOverrideData.GetPosition(m_CurAnimFrame); + } + else // 只在第一次播到这一帧的时候设置位置,否则场景里没法编辑位置 + { + int curAnimEventFrame = (int)m_CurAnimFrame; + normalizeTime = curAnimEventFrame / m_TotalFrame; + if (curAnimEventFrame != m_PrevAnimEventFrame) + { + m_Animator.transform.position = animData.rootMotionOverrideData.GetPosition(curAnimEventFrame); + } + m_PrevAnimEventFrame = curAnimEventFrame; } } } - } + + m_Animator.speed = 1; + m_Animator.Play(kStateName, 0, normalizeTime); + m_Animator.Update(0); + m_Animator.speed = 0; + + } public int GetCurrentFrame() { diff --git a/Assets/ActionTool/Editor/ActionEditorStyles.cs b/Assets/ActionTool/Editor/ActionEditorStyles.cs index 3b03cde8..896db183 100644 --- a/Assets/ActionTool/Editor/ActionEditorStyles.cs +++ b/Assets/ActionTool/Editor/ActionEditorStyles.cs @@ -21,12 +21,15 @@ namespace ActionTool public GUIStyle foldout; + public GUIStyle keyButton; + public Texture2D selectIcon; public Texture2D keyFrameIcon; public Texture2D addFileIcon; public Texture2D saveFileIcon; public Texture2D deleteIcon; public Texture2D infoIcon; + public Texture2D keyIcon; private static ActionEditorStyles s_instance; public static ActionEditorStyles Get() @@ -49,6 +52,7 @@ namespace ActionTool saveFileIcon = EditorGUIUtility.FindTexture("d_Collab.FileUpdated"); deleteIcon = EditorGUIUtility.FindTexture("d_P4_DeletedLocal"); infoIcon = EditorGUIUtility.FindTexture("console.infoicon"); + keyIcon = EditorGUIUtility.FindTexture("d_animationkeyframe"); InitStyle(out textBoldBig, GUI.skin.label, s => { s.fontStyle = FontStyle.Bold; @@ -96,6 +100,12 @@ namespace ActionTool s.focused.textColor = Color.yellow; s.hover.textColor = Color.yellow; }); + InitStyle(out keyButton, GUI.skin.button, s => { + s.normal.background = keyIcon; + s.active.background = keyIcon; + s.hover.background = keyIcon; + s.focused.background = keyIcon; + }); InitStyle(out toggleSmallBold, GUI.skin.toggle, s => { s.fontSize = 10; //s.fontStyle = FontStyle.Bold; diff --git a/Assets/ActionTool/Editor/ActionManager.cs b/Assets/ActionTool/Editor/ActionManager.cs index 7c3f1df4..fd9c15d2 100644 --- a/Assets/ActionTool/Editor/ActionManager.cs +++ b/Assets/ActionTool/Editor/ActionManager.cs @@ -55,6 +55,7 @@ namespace ActionTool private static GameObject s_CurrentUnit; private static string s_CurrentAnimationName; + public static GameObject unitInstance { get { return s_UnitInstance; } } private static GameObject s_UnitInstance; private static Animator s_Animator; private static AnimatorOverrideController s_OverrideContorller; @@ -130,7 +131,7 @@ namespace ActionTool { get { - bool hasRM = animationData != null && animationData.overrideRootMotion != null; + bool hasRM = animationData != null && animationData.overrideRootMotion == true; return (MaxEventsPerFrame + 1) + (animationData != null ? animationData.GetBoxesCount() : 0) + (hasRM ? 1 : 0); } } diff --git a/Assets/ActionTool/Editor/ActionPreviewEditor.cs b/Assets/ActionTool/Editor/ActionPreviewEditor.cs index 271c66da..1e4204c2 100644 --- a/Assets/ActionTool/Editor/ActionPreviewEditor.cs +++ b/Assets/ActionTool/Editor/ActionPreviewEditor.cs @@ -80,6 +80,9 @@ namespace ActionTool void Update() { ActionManager.UpdateFrame(); + + if(ActionManager.RootMotionEditor != null) + ActionManager.RootMotionEditor.Repaint(); } private void OnDisable() @@ -284,7 +287,7 @@ namespace ActionTool y += 15; GUI.Label(new Rect(xl, y, 105, 15), "RootMotion:", styles.textMiddle); - if(actionData.rootMotion != null && (animationData == null || animationData.overrideRootMotion == null)) + if(actionData.rootMotion != null && (animationData == null || animationData.overrideRootMotion == false)) { width = styles.textMiddleBold.CalcSize(new GUIContent(ActionManager.actionData.rootMotionPath)).x; GUI.Label(new Rect(xr, y, width, 15), ActionManager.actionData.rootMotionPath, styles.textMiddleBold); @@ -303,7 +306,7 @@ namespace ActionTool } } } - else if(animationData != null && animationData.overrideRootMotion != null) + else if(animationData != null && animationData.overrideRootMotion == true) { width = styles.textMiddle.CalcSize(new GUIContent("Override")).x; GUI.Label(new Rect(xr, y, width, 15), "Override", styles.textMiddle); @@ -548,7 +551,7 @@ namespace ActionTool void GUI_RM() { var animData = ActionManager.animationData; - if (animData == null || animData.overrideRootMotion == null) + if (animData == null || animData.overrideRootMotion == false) return; float y = m_GridY + (ActionManager.MaxEventsPerFrame + 1) * kFrameHeight; Rect rect = new Rect(kTimeLineViewXOffset - 17, y - 1, 17, kFrameHeight); @@ -559,13 +562,28 @@ namespace ActionTool Rect lb = rect; lb.y += 3; GUI.Label(lb, "RM", styles.textBoldSmall); - + // + var rmData = animData.rootMotionOverrideData; + if (rmData == null) + return; + for(int i = 0; i < rmData.positions.Count; ++i) + { + var posData = rmData.positions[i]; + if (posData == null) + continue; + int frame = posData.frame; + Vector2 pos = new Vector2(kTimeLineViewXOffset + frame * kFrameWidth, y); + if(GUI.Button(new Rect(pos.x - 1, pos.y + 3, kFrameWidth + 1, kFrameWidth), "", styles.keyButton)) + { + ActionManager.actionData.SetCurrentAnimTime(frame); + } + } } void GUI_Boxes() { var animData = ActionManager.animationData; - bool hasRM = animData != null && animData.overrideRootMotion != null; + bool hasRM = animData != null && animData.overrideRootMotion == true; float y = m_GridY + (ActionManager.MaxEventsPerFrame + 1 + (hasRM ? 1:0)) * kFrameHeight; if (animData == null) return; diff --git a/Assets/ActionTool/Editor/ActionRootMotionEditor.cs b/Assets/ActionTool/Editor/ActionRootMotionEditor.cs index ff0dae62..5d539b52 100644 --- a/Assets/ActionTool/Editor/ActionRootMotionEditor.cs +++ b/Assets/ActionTool/Editor/ActionRootMotionEditor.cs @@ -9,6 +9,7 @@ namespace ActionTool { ActionEditorStyles styles; + // isrecord的时候playbackFrame是整数 public static bool IsRecord { get; private set; } const float kToolbarControlMargin = 5; @@ -18,25 +19,30 @@ namespace ActionTool Texture m_UITextureRecord; Texture m_UITextureTakeRecord; + Texture m_UITextureTrashCan; Texture2D tex; private void OnEnable() { - maxSize = new Vector2(300, 80); + maxSize = new Vector2(300, 100); minSize = maxSize; this.titleContent = new GUIContent("RootMotion Editor"); m_UITextureRecord = (Texture)Resources.Load("button_control_record"); m_UITextureTakeRecord = (Texture)Resources.Load("button_control_takerecord"); + m_UITextureTrashCan = EditorGUIUtility.FindTexture("d_TreeEditor.Trash"); + tex = new Texture2D(1, 1, TextureFormat.RGBA32, false); - tex.SetPixel(0, 0, new Color(1f, 0, 0) * 0.8f); + tex.SetPixel(0, 0, new Color(1f, 0, 0) * 0.5f); tex.Apply(); + + IsRecord = false; } private void OnDisable() { - + IsRecord = false; } private void Update() @@ -46,7 +52,7 @@ namespace ActionTool private void OnGUI() { - if(ActionManager.animationData == null || ActionManager.animationData.overrideRootMotion == null) + if(ActionManager.animationData == null || ActionManager.animationData.overrideRootMotion == false) { this.Close(); return; @@ -58,6 +64,10 @@ namespace ActionTool float x = m_ToolbarOffset, y = kToolbarControlMargin; GUI_Record(ref x, ref y); GUI_TakeRecord(ref x, ref y); + GUI_Delete(ref x, ref y); + GUI.enabled = false; + EditorGUI.Vector3Field(new Rect(0, kToolbarHeight, position.width, 20), "Position: ", ActionManager.unitInstance.transform.position); + GUI.enabled = true; } void GUI_Record(ref float x, ref float y) @@ -70,14 +80,35 @@ namespace ActionTool void GUI_TakeRecord(ref float x, ref float y) { + if (!IsRecord) + GUI.enabled = false; x += kToolbarControlMargin; Rect rect = new Rect(x, y, kToolbarControlSize, kToolbarControlSize); if (GUI.Button(rect, m_UITextureTakeRecord)) { - + Vector3 pos = ActionManager.unitInstance.transform.position; + int frame = (int)ActionManager.actionData.curAnimFrame; + ActionManager.animationData.rootMotionOverrideData.SetPosition(frame, pos); + ActionManager.PreviewWindow.Repaint(); } + GUI.enabled = true; x += kToolbarControlSize; } + void GUI_Delete(ref float x, ref float y) + { + if (!IsRecord) + GUI.enabled = false; + x += kToolbarControlMargin; + Rect rect = new Rect(x, y, kToolbarControlSize, kToolbarControlSize); + if (GUI.Button(rect, m_UITextureTrashCan)) + { + int frame = (int)ActionManager.actionData.curAnimFrame; + ActionManager.animationData.rootMotionOverrideData.RemovePositionAtFrame(frame); + ActionManager.PreviewWindow.Repaint(); + } + GUI.enabled = true; + x += kToolbarControlSize; + } } } \ No newline at end of file -- cgit v1.1-26-g67d0