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 ++++++++-- .../PC/Erika/AnimationData/Air_Combo03_Z0_2.asset | 89 +++++++++++++++++++++- .../Bundle/Unit/PC/Erika/AnimationData/rise4.asset | 5 +- Assets/Scripts/Unit/AnimationData.cs | 81 ++++++++++++++++++-- 8 files changed, 261 insertions(+), 36 deletions(-) (limited to 'Assets') 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 diff --git a/Assets/Bundle/Unit/PC/Erika/AnimationData/Air_Combo03_Z0_2.asset b/Assets/Bundle/Unit/PC/Erika/AnimationData/Air_Combo03_Z0_2.asset index 264b57d6..5685d300 100644 --- a/Assets/Bundle/Unit/PC/Erika/AnimationData/Air_Combo03_Z0_2.asset +++ b/Assets/Bundle/Unit/PC/Erika/AnimationData/Air_Combo03_Z0_2.asset @@ -10,16 +10,99 @@ MonoBehaviour: m_Enabled: 1 m_EditorHideFlags: 0 m_Script: {fileID: 11500000, guid: cab6406109041434e890f22d6455172f, type: 3} - m_Name: Air_Combo03_Z0_2 + m_Name: Air_Combo03_Z0_2(Clone) m_EditorClassIdentifier: animationName: Air_Combo03_Z0_2 animationPath: Assets/Bundle/Unit/PC/Erika/AnimationClip/Air_Combo03_Z0_2.anim animationEvents: [] - hurtBoxes: [] - hitBoxes: [] + hurtBoxes: + - collider: + type: 1 + pivot: 0 + multiHit: 0 + hitResponse: 0 + hitBack: {x: 0, y: 0, z: 0} + freezeFramesSelf: 0 + freezeFramesOther: 0 + sparkPath: + sparkAnchor: 0 + sparkOffset: {x: 0, y: 0, z: 0} + sparkScale: {x: 1, y: 1, z: 1} + multiSparks: 0 + spark2Path: + spark2Anchor: 0 + spark2Offset: {x: 0, y: 0, z: 0} + spark3Path: + spark3Anchor: 0 + spark3Offset: {x: 0, y: 0, z: 0} + selfEffect: 0 + otherEffect: 0 + zoomCamera: 0 + shakeScreen: 0 + shakeOffset: {x: 0, y: 0} + shakeStrength: 0 + colorDrift: 0 + blur: 0 + soundPath: + useGravity: 0 + multiple: 0 + frames: [] + hitBoxes: + - collider: + type: 0 + pivot: 1 + multiHit: 0 + hitResponse: 0 + hitBack: {x: 0, y: 0, z: 0} + freezeFramesSelf: 0 + freezeFramesOther: 0 + sparkPath: + sparkAnchor: 0 + sparkOffset: {x: 0, y: 0, z: 0} + sparkScale: {x: 1, y: 1, z: 1} + multiSparks: 0 + spark2Path: + spark2Anchor: 0 + spark2Offset: {x: 0, y: 0, z: 0} + spark3Path: + spark3Anchor: 0 + spark3Offset: {x: 0, y: 0, z: 0} + selfEffect: 0 + otherEffect: 0 + zoomCamera: 0 + shakeScreen: 0 + shakeOffset: {x: 0, y: 0} + shakeStrength: 0 + colorDrift: 0 + blur: 0 + soundPath: + useGravity: 0 + multiple: 0 + frames: [] throwBoxes: [] blockBoxes: [] defendBoxes: [] + overrideRootMotion: 1 + rootMotionOverrideData: + positions: + - position: {x: 0, y: 0, z: 0} + frame: 0 + - position: {x: 0, y: 0, z: 0} + frame: 8 + - position: {x: 0.3, y: 0.02, z: 0} + frame: 11 + - position: {x: 0.72, y: 0.02, z: 0} + frame: 13 + - position: {x: 1.37, y: 0.09, z: 0} + frame: 16 + - position: {x: 1.77, y: 0.08, z: 0} + frame: 19 + - position: {x: 2.62, y: 0.15, z: 0} + frame: 22 + - position: {x: 2.95, y: 0.01, z: 0} + frame: 48 + - position: {x: 2.95, y: 0.01, z: 0} + frame: 50 speedCurve: serializedVersion: 2 m_Curve: diff --git a/Assets/Bundle/Unit/PC/Erika/AnimationData/rise4.asset b/Assets/Bundle/Unit/PC/Erika/AnimationData/rise4.asset index 77c72e71..7f2ba611 100644 --- a/Assets/Bundle/Unit/PC/Erika/AnimationData/rise4.asset +++ b/Assets/Bundle/Unit/PC/Erika/AnimationData/rise4.asset @@ -10,7 +10,7 @@ MonoBehaviour: m_Enabled: 1 m_EditorHideFlags: 0 m_Script: {fileID: 11500000, guid: cab6406109041434e890f22d6455172f, type: 3} - m_Name: rise4(Clone) + m_Name: rise4 m_EditorClassIdentifier: animationName: rise4 animationPath: Assets/Bundle/Unit/PC/Erika/AnimationClip/rise4.anim @@ -20,7 +20,8 @@ MonoBehaviour: throwBoxes: [] blockBoxes: [] defendBoxes: [] - overrideRootMotion: + overrideRootMotion: 1 + rootMotionOverrideData: positions: [] speedCurve: serializedVersion: 2 diff --git a/Assets/Scripts/Unit/AnimationData.cs b/Assets/Scripts/Unit/AnimationData.cs index 80891d83..30762b39 100644 --- a/Assets/Scripts/Unit/AnimationData.cs +++ b/Assets/Scripts/Unit/AnimationData.cs @@ -82,8 +82,13 @@ public class RootMotionOverrideData [Serializable] public class PosData { - [SerializeField] Vector3 position; - [SerializeField] float frame; + [SerializeField] public Vector3 position; + [SerializeField] public int frame; + public PosData(int frame, Vector3 pos) + { + this.frame = frame; + this.position = pos; + } } [SerializeField] public List positions; public RootMotionOverrideData() @@ -92,7 +97,68 @@ public class RootMotionOverrideData } public Vector3 GetPosition(float frame) { - return Vector3.zero; + if (positions == null || positions.Count == 0) + return Vector3.zero; + positions.Sort((p1, p2) => { + if (p1.frame < p2.frame) + return -1; + if (p1.frame > p2.frame) + return 1; + return 0; + }); + int prev = 0; + int next = 0; + for(int i = 0;i < positions.Count; ++i) + { + if(positions[i].frame > frame) + { + break; + } + prev = i; + next = Mathf.Clamp(i + 1, 0, positions.Count - 1); + } + float t = 0; + if(prev != next) + { + t = (frame - positions[prev].frame) / (positions[next].frame - positions[prev].frame); + } + Vector3 pos = Vector3.Lerp(positions[prev].position, positions[next].position, t); + return pos; + } + + public Vector3 GetRootMotionDistance(float prevFrame, float curFrame) + { + Vector3 p1 = GetPosition(prevFrame); + Vector3 p2 = GetPosition(curFrame); + return p2 - p1; + } + + public void SetPosition(int frame, Vector3 position) + { + if(positions == null) + { + positions = new List(); + } + PosData pd = positions.Find(s => s.frame == frame); + if(pd != null) + { + pd.position = position; + } + else + { + positions.Add(new PosData(frame, position)); + } + } + + public void RemovePositionAtFrame(float frame) + { + if (positions == null) + return; + PosData pd = positions.Find(s => s.frame == frame); + if(pd != null) + { + positions.Remove(pd); + } } } @@ -111,7 +177,8 @@ public class AnimationData : ScriptableObject public List blockBoxes; public List defendBoxes; - public RootMotionOverrideData overrideRootMotion; + public bool overrideRootMotion; + public RootMotionOverrideData rootMotionOverrideData; // 对应的进度的播放速度,默认是1 [UnityEngine.Serialization.FormerlySerializedAs("curve")] @@ -393,12 +460,14 @@ public class AnimationData : ScriptableObject public void AddRootMotionOverriderData( ) { - this.overrideRootMotion = new RootMotionOverrideData(); + this.overrideRootMotion = true; + this.rootMotionOverrideData = new RootMotionOverrideData(); } public void DeleteRootMotionOverrideData() { - this.overrideRootMotion = null; + this.overrideRootMotion = false; + this.rootMotionOverrideData = null; } #if UNITY_EDITOR -- cgit v1.1-26-g67d0