From de78537f8edc6cb162ba58520956255f7e53769d Mon Sep 17 00:00:00 2001 From: chai Date: Sun, 29 Aug 2021 12:54:37 +0800 Subject: =?UTF-8?q?*=E8=BD=B4=E5=90=91=E6=94=B9=E4=B8=BAxy?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/Scripts/Unit/AnimationData.cs | 1 + .../Scripts/Unit/Collider/ColliderBox_Hurtbox.cs | 5 +- Assets/Scripts/Unit/Collider/ColliderData.cs | 2 +- Assets/Scripts/Unit/Component/UnitAnimation.cs | 35 +++++- Assets/Scripts/Unit/Component/UnitState.cs | 135 ++++++++++++++++++--- Assets/Scripts/Unit/RootMotion/RootMotionData.cs | 12 ++ Assets/Scripts/Unit/UnitRootMotion.cs | 6 +- 7 files changed, 170 insertions(+), 26 deletions(-) (limited to 'Assets/Scripts/Unit') diff --git a/Assets/Scripts/Unit/AnimationData.cs b/Assets/Scripts/Unit/AnimationData.cs index 32845da1..4d229346 100644 --- a/Assets/Scripts/Unit/AnimationData.cs +++ b/Assets/Scripts/Unit/AnimationData.cs @@ -12,6 +12,7 @@ public enum EAnimationToogle { Combo = 0, // 连击 SuperArmor = 1, //霸体 + Break = 2, // 打断 } [Serializable] diff --git a/Assets/Scripts/Unit/Collider/ColliderBox_Hurtbox.cs b/Assets/Scripts/Unit/Collider/ColliderBox_Hurtbox.cs index 62c61006..788b457a 100644 --- a/Assets/Scripts/Unit/Collider/ColliderBox_Hurtbox.cs +++ b/Assets/Scripts/Unit/Collider/ColliderBox_Hurtbox.cs @@ -1,7 +1,4 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using UnityEngine; +using UnityEngine; public partial class ColliderBox { diff --git a/Assets/Scripts/Unit/Collider/ColliderData.cs b/Assets/Scripts/Unit/Collider/ColliderData.cs index 4c8e5bed..58743aff 100644 --- a/Assets/Scripts/Unit/Collider/ColliderData.cs +++ b/Assets/Scripts/Unit/Collider/ColliderData.cs @@ -101,7 +101,7 @@ public class ColliderData frame.frame = frameIndex; frame.active = true; frame.position = Vector3.zero; - frame.size = new Vector3(1,1,0.5f); + frame.size = new Vector3(0.5f,1,1); frames.Add(frame); frames.Sort((a, b) => { if (a == null) diff --git a/Assets/Scripts/Unit/Component/UnitAnimation.cs b/Assets/Scripts/Unit/Component/UnitAnimation.cs index a6a7f3eb..4532023d 100644 --- a/Assets/Scripts/Unit/Component/UnitAnimation.cs +++ b/Assets/Scripts/Unit/Component/UnitAnimation.cs @@ -286,6 +286,9 @@ public class UnitAnimation : UnitComponent public AnimatorLayerInfo[] layers { get { return m_LayerInfo; } } private readonly AnimatorLayerInfo[] m_LayerInfo = new AnimatorLayerInfo[(int)ELayer.Count]; + public bool applyRootMotion { get; set; }// 动态设置root motion + public bool applyRootCurve { get; set; } // 程序生成的root motion + public bool isInTransition { get @@ -309,6 +312,8 @@ public class UnitAnimation : UnitComponent { LogHelper.LogError("没有挂Animator组件"); } + + applyRootMotion = true; } public override void OnUpdate() @@ -317,8 +322,12 @@ public class UnitAnimation : UnitComponent UpdateLayer(); UpdateAnimation(); - UpdateRootMotion(); - } + + if(applyRootMotion) + UpdateRootMotion(); + if(applyRootCurve) + UpdateRootCurve(); + } void UpdateLayer() { @@ -342,7 +351,13 @@ public class UnitAnimation : UnitComponent m_Owner.unitRootMotion.UpdateRootMotion(); } - public void AnimIdle() + void UpdateRootCurve() + { + + } + + + public void AnimIdle() { #if ANIM_CROSS_FADE m_Animator.CrossFade("Idle", 0.2f, 0); @@ -394,7 +409,19 @@ public class UnitAnimation : UnitComponent #endif } - public void AnimLanding() + public void AnimAirDash() + { + if (layers[0].stateInfo.IsName("AirDash")) + { + m_Animator.Play("AirDash", 0, 0); + } + else + { + m_Animator.CrossFade("AirDash", 0.05f); + } + } + + public void AnimLanding() { #if ANIM_CROSS_FADE m_Animator.CrossFade("Landing", 0.05f); diff --git a/Assets/Scripts/Unit/Component/UnitState.cs b/Assets/Scripts/Unit/Component/UnitState.cs index 7a731b02..bc934f43 100644 --- a/Assets/Scripts/Unit/Component/UnitState.cs +++ b/Assets/Scripts/Unit/Component/UnitState.cs @@ -20,6 +20,7 @@ public class UnitState : UnitComponent // Attack , AirAttack , + AirDash , // HitAir , HitAirHit , @@ -63,6 +64,11 @@ public class UnitState : UnitComponent } + public struct AirDashParam + { + + } + public struct JumpParam { } @@ -114,6 +120,21 @@ public class UnitState : UnitComponent IEnumerator Nein() { yield break; } void OnNienExit(EUnitState nextState) { } + public void TurnAround(bool bRight) + { + m_Owner.transform.rotation = Quaternion.Euler(0, bRight ? 0 : 180, 0); + } + + public void TurnLeft() + { + TurnAround(false); + } + + public void TurnRight() + { + TurnAround(true); + } + #region Idle IEnumerator Idle(IdleParam param) @@ -212,14 +233,36 @@ public class UnitState : UnitComponent yield return null; // 等待animator更新 while (true) { - bool canAttack = m_Owner.unitAnimation.layers[0].IsToggleOpen(EAnimationToogle.Combo); - if(canAttack && Input.GetKeyDown("j") ) - { - ++id; - m_Owner.unitAnimation.AnimAirAttack(id); - yield return null; // 等待animator更新 - yield return new WaitForTransitionDone(m_Owner.unitAnimation); - } + bool canCombo = m_Owner.unitAnimation.layers[0].IsToggleOpen(EAnimationToogle.Combo); + if(canCombo) + { + if (InputManager.Instance.TryCommand(0.5f, KeyCode.A, KeyCode.A)) + { + TurnLeft(); + ChangeState(EUnitState.AirDash, new AirDashParam()); + } + if (InputManager.Instance.TryCommand(0.5f, KeyCode.D, KeyCode.D)) + { + TurnRight(); + ChangeState(EUnitState.AirDash, new AirDashParam()); + } + + if (Input.GetKeyDown("j")) + { + if (Input.GetKey("a")) + { + TurnAround(false); + } + if (Input.GetKey("d")) + { + TurnAround(true); + } + ++id; + m_Owner.unitAnimation.AnimAirAttack(id); + yield return null; // 等待animator更新 + yield return new WaitForTransitionDone(m_Owner.unitAnimation); + } + } bool reachEnd = m_Owner.unitAnimation.layers[0].playbackNomralizedTime == 1; if (reachEnd) @@ -236,11 +279,63 @@ public class UnitState : UnitComponent } - #endregion + #endregion + + #region AirDash + + IEnumerator AirDash(AirDashParam param) + { + m_Owner.unitAnimation.AnimAirDash(); + yield return null; + while(true) + { + bool reachEnd = m_Owner.unitAnimation.layers[0].playbackNomralizedTime == 1; + if (reachEnd) + { + ChangeState(EUnitState.Landing, new LandingParam()); + } + + bool canCombo = m_Owner.unitAnimation.layers[0].IsToggleOpen(EAnimationToogle.Combo); + if(canCombo) + { + if (InputManager.Instance.TryCommand(0.5f, KeyCode.A, KeyCode.A)) + { + TurnLeft(); + m_Owner.unitAnimation.AnimAirDash(); + } + if (InputManager.Instance.TryCommand(0.5f, KeyCode.D, KeyCode.D)) + { + TurnRight(); + m_Owner.unitAnimation.AnimAirDash(); + } + + if (Input.GetKeyDown("j")) + { + if (Input.GetKey("a")) + { + TurnAround(false); + } + if (Input.GetKey("d")) + { + TurnAround(true); + } + ChangeState(EUnitState.AirAttack, new SkillParam()); + } + } + + yield return null; + } + } + + void OnAirDashExit(EUnitState next) + { + } + + #endregion - #region Jump + #region Jump - IEnumerator Jump(JumpParam param) + IEnumerator Jump(JumpParam param) { unitAnimation.AnimJump(); yield return null; @@ -271,18 +366,28 @@ public class UnitState : UnitComponent m_Owner.unitAnimation.AnimLanding(); yield return null; yield return new WaitForTransitionDone(m_Owner.unitAnimation); - float vy = 0; + float vy = 2; float g = 9.8f; bool landingGround = false; + float vz = 5; while (true) { Vector3 pos = m_Owner.transform.position; vy += g * Time.deltaTime; pos.y -= vy * Time.deltaTime; pos.y = Mathf.Max(0, pos.y); - m_Owner.transform.position = pos; - Debug.Log(pos.y); - if(pos.y > 0 && pos.y <= 1 && !landingGround) + if (Input.GetKey("a")) + { + TurnAround(false); + pos.x -= vz * Time.deltaTime; + } + if (Input.GetKey("d")) + { + TurnAround(true); + pos.x += vz * Time.deltaTime; + } + m_Owner.transform.position = pos; + if (pos.y > 0 && pos.y <= 1 && !landingGround) { landingGround = true; m_Owner.unitAnimation.AnimLandingGround(); diff --git a/Assets/Scripts/Unit/RootMotion/RootMotionData.cs b/Assets/Scripts/Unit/RootMotion/RootMotionData.cs index 84a42ec1..f60689ad 100644 --- a/Assets/Scripts/Unit/RootMotion/RootMotionData.cs +++ b/Assets/Scripts/Unit/RootMotion/RootMotionData.cs @@ -40,3 +40,15 @@ public class RootMotionData : ScriptableObject } } + +public static class RootMotionUtility +{ + // zy平面的移动改为xy平面的移动 + public static Vector3 ExchangeXZ(Vector3 dest) + { + float z = dest.z; + dest.z = dest.x; + dest.x = z; + return dest; + } +} diff --git a/Assets/Scripts/Unit/UnitRootMotion.cs b/Assets/Scripts/Unit/UnitRootMotion.cs index c4d4b2c9..8c6edaa0 100644 --- a/Assets/Scripts/Unit/UnitRootMotion.cs +++ b/Assets/Scripts/Unit/UnitRootMotion.cs @@ -70,8 +70,9 @@ public class UnitRootMotion : UnitComponent public void UpdateRootMotion() { + // 因为Unti被旋转了90度,所以这里的deltaPosition的forward是x方向了 Vector3 dest = m_Owner.unitAnimation.animator.deltaPosition; - dest.x = 0; //限制x轴始终在x=0 + dest.z = 0; var state = m_Owner.unitAnimation.layers[0].stateInfo; if(state.IsTag("IgnoreY")) @@ -79,7 +80,8 @@ public class UnitRootMotion : UnitComponent dest.y = 0; } - m_Owner.transform.position += dest; + //m_Owner.transform.position += RootMotionUtility.ExchangeXZ(dest); // 不需要exchangeXZ + m_Owner.transform.position += dest; } #endif -- cgit v1.1-26-g67d0