From e2b42bc614a08b526a7ba2bce8a338a3eb9468c3 Mon Sep 17 00:00:00 2001 From: chai <215380520@qq.com> Date: Tue, 15 Nov 2022 12:38:33 +0800 Subject: - PCAnimation - MonsterAnimation --- Erika/Assets/Scripts/Unit/AnimationType.cs | 7 +++ Erika/Assets/Scripts/Unit/AnimatorState.cs | 1 + .../Components/UnitAnimation/MonsterAnimation.cs | 8 ++- .../Unit/Components/UnitAnimation/PCAnimation.cs | 12 +++- .../Unit/Components/UnitAnimation/UnitMotion.cs | 56 ++++++++++++++++-- .../Unit/Components/UnitState/Erika/PCState.cs | 2 - .../Components/UnitState/Erika/PCState_States.cs | 54 ++++++++--------- .../Unit/Components/UnitState/MonsterState.cs | 68 +++++++++++----------- .../Scripts/Unit/Controller/MonsterController.cs | 4 +- .../Assets/Scripts/Unit/Controller/PCController.cs | 4 +- .../Scripts/Unit/Controller/UnitController.cs | 5 +- Erika/Assets/Scripts/Unit/UnitMotionData.cs | 22 +++++++ 12 files changed, 163 insertions(+), 80 deletions(-) diff --git a/Erika/Assets/Scripts/Unit/AnimationType.cs b/Erika/Assets/Scripts/Unit/AnimationType.cs index eb57168a..365e580e 100644 --- a/Erika/Assets/Scripts/Unit/AnimationType.cs +++ b/Erika/Assets/Scripts/Unit/AnimationType.cs @@ -35,5 +35,12 @@ public enum EAnimationType Throw = 40, Block = 41, + + /// + /// 技能 + /// + Skill = 60, + + _END } diff --git a/Erika/Assets/Scripts/Unit/AnimatorState.cs b/Erika/Assets/Scripts/Unit/AnimatorState.cs index bb7685aa..62d59239 100644 --- a/Erika/Assets/Scripts/Unit/AnimatorState.cs +++ b/Erika/Assets/Scripts/Unit/AnimatorState.cs @@ -4,6 +4,7 @@ using UnityEngine; /// /// 在Animator controller里的state名,在override controller时会进行替换 +/// 这个设计的目的是为了动作的按需加载 /// public enum EAnimatorState { diff --git a/Erika/Assets/Scripts/Unit/Components/UnitAnimation/MonsterAnimation.cs b/Erika/Assets/Scripts/Unit/Components/UnitAnimation/MonsterAnimation.cs index 2ead987d..67efc301 100644 --- a/Erika/Assets/Scripts/Unit/Components/UnitAnimation/MonsterAnimation.cs +++ b/Erika/Assets/Scripts/Unit/Components/UnitAnimation/MonsterAnimation.cs @@ -1,4 +1,6 @@ -using System.Collections; +#if false + +using System.Collections; using System.Collections.Generic; using UnityEngine; @@ -105,3 +107,7 @@ public class MonsterAnimation : UnitMotion } } + + +#endif + diff --git a/Erika/Assets/Scripts/Unit/Components/UnitAnimation/PCAnimation.cs b/Erika/Assets/Scripts/Unit/Components/UnitAnimation/PCAnimation.cs index 30dba3eb..568716f3 100644 --- a/Erika/Assets/Scripts/Unit/Components/UnitAnimation/PCAnimation.cs +++ b/Erika/Assets/Scripts/Unit/Components/UnitAnimation/PCAnimation.cs @@ -1,4 +1,6 @@ -#define ANIM_CROSS_FADE +#if false + +#define ANIM_CROSS_FADE using System; using System.Collections; using System.Collections.Generic; @@ -234,12 +236,16 @@ public class PCAnimation : UnitMotion private void Play(EActionState animState, float normalizedTime = float.NegativeInfinity) { - base.Play(animState.ToString(), normalizedTime); + //base.Play(animState.ToString(), normalizedTime); } private void CrossFade(EActionState animState, float normalizedTransitionDuration, float normalizedTimeOffset = float.NegativeInfinity, float normalizedTransitionTime = 0.0f) { - base.CrossFade(animState.ToString(), normalizedTransitionDuration, normalizedTimeOffset, normalizedTransitionTime); + //base.CrossFade(animState.ToString(), normalizedTransitionDuration, normalizedTimeOffset, normalizedTransitionTime); } } + + +#endif + diff --git a/Erika/Assets/Scripts/Unit/Components/UnitAnimation/UnitMotion.cs b/Erika/Assets/Scripts/Unit/Components/UnitAnimation/UnitMotion.cs index 49995d19..96abc075 100644 --- a/Erika/Assets/Scripts/Unit/Components/UnitAnimation/UnitMotion.cs +++ b/Erika/Assets/Scripts/Unit/Components/UnitAnimation/UnitMotion.cs @@ -58,7 +58,7 @@ public class UnitMotion : UnitComponent { if (m_Dirty) { - //m_CachedAnimationData = m_ActionData.GetAnimationData(currentAction); + m_CachedAnimationData = m_MotionData.GetAnimationData(currentMotionID); m_Dirty = false; } return m_CachedAnimationData; @@ -187,8 +187,44 @@ public class UnitMotion : UnitComponent return m_MotionData.GetMotionDataByAnimationType(type); } + /// + /// 是否有某个类型的动作,用于gameplay逻辑 + /// + /// + /// + public bool HasAnimationType(EAnimationType type) + { + return m_MotionData.HasMotionAnimationType(type); + } + + /// + /// 是否有某个id的动作 + /// + /// + /// + public bool HasMotionId(int uid) + { + return m_MotionData.HasMotionId(uid); + } + #region 播放动作,对外屏蔽Animator + /// + /// 过渡到某个类型的动作 + /// + /// + /// + /// + /// + public void CrossFade(EAnimationType animType, float normalizedTransitionDuration, float normalizedTimeOffset = float.NegativeInfinity, float normalizedTransitionTime = 0.0f) + { + if (!m_MotionData.HasMotionAnimationType(animType)) + return; + + MotionData motion = m_MotionData.GetMotionDataByAnimationType(animType); + CrossFade(motion.uid, normalizedTransitionDuration, normalizedTimeOffset, normalizedTransitionTime); + } + /// /// CrossFade过渡到目标动作 /// @@ -231,11 +267,19 @@ public class UnitMotion : UnitComponent } } - /// - /// 直接播放目标动作 - /// - /// - public void PlayMotion(int motionId) + public void Play(EAnimationType animType) + { + if (!m_MotionData.HasMotionAnimationType(animType)) + return; + MotionData motion = m_MotionData.GetMotionDataByAnimationType(animType); + PlayMotion(motion); + } + + /// + /// 直接播放目标动作 + /// + /// + public void PlayMotion(int motionId) { MotionData motion = m_MotionData.GetMotionDataById(motionId); PlayMotion(motion); diff --git a/Erika/Assets/Scripts/Unit/Components/UnitState/Erika/PCState.cs b/Erika/Assets/Scripts/Unit/Components/UnitState/Erika/PCState.cs index e551451b..083f5a17 100644 --- a/Erika/Assets/Scripts/Unit/Components/UnitState/Erika/PCState.cs +++ b/Erika/Assets/Scripts/Unit/Components/UnitState/Erika/PCState.cs @@ -55,8 +55,6 @@ public partial class PCState : UnitState owner.onTimelineEvent -= OnTimeLineEvent; base.Release(); } - - PCAnimation pcAnimation { get { return m_Owner.pcAnimation; } } public void ChangeState(EUnitState nextState, T param = default, bool bForce = false) { diff --git a/Erika/Assets/Scripts/Unit/Components/UnitState/Erika/PCState_States.cs b/Erika/Assets/Scripts/Unit/Components/UnitState/Erika/PCState_States.cs index e445ef92..260906a0 100644 --- a/Erika/Assets/Scripts/Unit/Components/UnitState/Erika/PCState_States.cs +++ b/Erika/Assets/Scripts/Unit/Components/UnitState/Erika/PCState_States.cs @@ -43,7 +43,7 @@ public partial class PCState : UnitState IEnumerator Idle(IdleParam param) { - m_Owner.pcAnimation.AnimIdle(); + //m_Owner.pcAnimation.AnimIdle(); yield return new WaitForTransitionDone(owner.unitAnimation); m_Owner.SetYPosition(0); while (true) @@ -103,7 +103,7 @@ public partial class PCState : UnitState m_Owner.Turn(param.isRight); } //if (Input.GetKey(param.key)) - m_Owner.pcAnimation.AnimMove(); + //m_Owner.pcAnimation.AnimMove(); while (Input.GetKey(param.key)) { TryAttackToAir(); @@ -115,7 +115,7 @@ public partial class PCState : UnitState void OnMoveExit(EUnitState nextState) { - m_Owner.pcAnimation.animator.ResetTrigger("ToMove"); + //m_Owner.pcAnimation.animator.ResetTrigger("ToMove"); } #endregion @@ -126,7 +126,7 @@ public partial class PCState : UnitState { const int total = 4; int id = 0; - m_Owner.pcAnimation.AnimAttack(id++); + //m_Owner.pcAnimation.AnimAttack(id++); yield return null; while (true) { @@ -148,9 +148,9 @@ public partial class PCState : UnitState { TryTurnAround(); - m_Owner.pcAnimation.AnimAttack(id++); - yield return null; - yield return new WaitForTransitionDone(m_Owner.pcAnimation); + //m_Owner.pcAnimation.AnimAttack(id++); + //yield return null; + //yield return new WaitForTransitionDone(m_Owner.pcAnimation); } } @@ -174,7 +174,7 @@ public partial class PCState : UnitState IEnumerator AttackToAir(SkillParam param) { - m_Owner.pcAnimation.AnimAttackToAir(param.offset); + //m_Owner.pcAnimation.AnimAttackToAir(param.offset); yield return null; InputManager.Instance.ClearCommand(); while (true) @@ -213,7 +213,7 @@ public partial class PCState : UnitState { int total = 5; int id = 0; - m_Owner.pcAnimation.AnimAirAttack(id++); + //m_Owner.pcAnimation.AnimAirAttack(id++); yield return null; InputManager.Instance.ClearCommand(); while (true) @@ -232,10 +232,10 @@ public partial class PCState : UnitState { TryTurnAround(); - m_Owner.pcAnimation.AnimAirAttack(id++); - id %= total; - //yield return null; // 等待animator更新 - yield return new WaitForTransitionDone(m_Owner.pcAnimation); + //m_Owner.pcAnimation.AnimAirAttack(id++); + //id %= total; + ////yield return null; // 等待animator更新 + //yield return new WaitForTransitionDone(m_Owner.pcAnimation); } } @@ -260,7 +260,7 @@ public partial class PCState : UnitState IEnumerator AirDash(AirDashParam param) { - m_Owner.pcAnimation.AnimAirDash(); + //m_Owner.pcAnimation.AnimAirDash(); yield return null; while (true) { @@ -298,9 +298,9 @@ public partial class PCState : UnitState IEnumerator Jump(JumpParam param) { - pcAnimation.AnimJump(); - yield return null; - yield return new WaitForTransitionDone(pcAnimation); + //pcAnimation.AnimJump(); + //yield return null; + //yield return new WaitForTransitionDone(pcAnimation); while (true) { if (InputManager.Instance.TryCommand(0.5f, KeyCode.A, KeyCode.A)) @@ -320,12 +320,12 @@ public partial class PCState : UnitState ChangeState(EUnitState.Landing, new LandingParam()); yield break; } - bool canAttack = m_Owner.pcAnimation.IsToggleOpen(EAnimationToogle.Combo); - if (Input.GetKeyDown("j") && canAttack) - { - ChangeState(EUnitState.AirAttack, new SkillParam()); - yield break; - } + //bool canAttack = m_Owner.pcAnimation.IsToggleOpen(EAnimationToogle.Combo); + //if (Input.GetKeyDown("j") && canAttack) + //{ + // ChangeState(EUnitState.AirAttack, new SkillParam()); + // yield break; + //} yield return null; } } @@ -340,9 +340,9 @@ public partial class PCState : UnitState IEnumerator Landing(LandingParam param) { - m_Owner.pcAnimation.AnimLanding(); - yield return null; - yield return new WaitForTransitionDone(m_Owner.pcAnimation); + //m_Owner.pcAnimation.AnimLanding(); + //yield return null; + //yield return new WaitForTransitionDone(m_Owner.pcAnimation); float vy = 0; float g = -9.8f; bool landingGround = false; @@ -384,7 +384,7 @@ public partial class PCState : UnitState if (pos.y > 0 && pos.y <= 1 && !landingGround) { landingGround = true; - m_Owner.pcAnimation.AnimLandingGround(); + //m_Owner.pcAnimation.AnimLandingGround(); } if (pos.y <= 0) { diff --git a/Erika/Assets/Scripts/Unit/Components/UnitState/MonsterState.cs b/Erika/Assets/Scripts/Unit/Components/UnitState/MonsterState.cs index a4a31bde..dcdb7281 100644 --- a/Erika/Assets/Scripts/Unit/Components/UnitState/MonsterState.cs +++ b/Erika/Assets/Scripts/Unit/Components/UnitState/MonsterState.cs @@ -94,7 +94,7 @@ public class MonsterState : UnitState //else // idle //{ m_Owner.SetYPosition(0); - m_Owner.monsterAnimation.AnimIdle(); + //m_Owner.monsterAnimation.AnimIdle(); while (true) { yield return null; @@ -112,15 +112,15 @@ public class MonsterState : UnitState IEnumerator HitLight(HitLightParam param) { ((MonsterController)owner).FacePC(); - m_Owner.monsterAnimation.AnimHitBackHeavy(); + //m_Owner.monsterAnimation.AnimHitBackHeavy(); yield return null; while (true) { - bool reachEnd = m_Owner.monsterAnimation.playbackNormalizedTime == 1; - if(reachEnd) - { - ChangeState(EUnitState.Idle, new IdleParam()); - } + //bool reachEnd = m_Owner.monsterAnimation.playbackNormalizedTime == 1; + //if(reachEnd) + //{ + // ChangeState(EUnitState.Idle, new IdleParam()); + //} yield return null; } } @@ -136,16 +136,16 @@ public class MonsterState : UnitState IEnumerator HitAir(HitAirParam param) { ((MonsterController)owner).FacePC(); - m_Owner.monsterAnimation.AnimHitAir(); + //m_Owner.monsterAnimation.AnimHitAir(); yield return null; while (true) { - bool reachEnd = m_Owner.monsterAnimation.playbackNormalizedTime == 1; - if (reachEnd) - { - //yield return new WaitForSeconds(1f); - ChangeState(EUnitState.Rise, new RiseParam()); - } + //bool reachEnd = m_Owner.monsterAnimation.playbackNormalizedTime == 1; + //if (reachEnd) + //{ + // //yield return new WaitForSeconds(1f); + // ChangeState(EUnitState.Rise, new RiseParam()); + //} yield return null; } } @@ -161,25 +161,25 @@ public class MonsterState : UnitState IEnumerator HitInAir(HitInAirParam param) { ((MonsterController)owner).FaceToFacePC(); - m_Owner.monsterAnimation.AnimHitInAir(); + //m_Owner.monsterAnimation.AnimHitInAir(); yield return null; float vy = -1f; float g = -15.8f; while (true) { - bool reachEnd = m_Owner.monsterAnimation.playbackNormalizedTime == 1; - if (reachEnd) - { - vy += g * Time.deltaTime; - Vector3 pos = owner.transform.position; - pos.y += vy * Time.deltaTime; - if(pos.y <= 0) - { - yield return new WaitForSeconds(0.5f); - ChangeState(EUnitState.Rise, new RiseParam()); - } - owner.transform.position = pos; - } + //bool reachEnd = m_Owner.monsterAnimation.playbackNormalizedTime == 1; + //if (reachEnd) + //{ + // vy += g * Time.deltaTime; + // Vector3 pos = owner.transform.position; + // pos.y += vy * Time.deltaTime; + // if(pos.y <= 0) + // { + // yield return new WaitForSeconds(0.5f); + // ChangeState(EUnitState.Rise, new RiseParam()); + // } + // owner.transform.position = pos; + //} yield return null; } } @@ -194,15 +194,15 @@ public class MonsterState : UnitState IEnumerator Rise(RiseParam param) { - m_Owner.monsterAnimation.AnimRise(); + //m_Owner.monsterAnimation.AnimRise(); yield return null; while (true) { - bool reachEnd = m_Owner.monsterAnimation.playbackNormalizedTime == 1; - if (reachEnd) - { - ChangeState(EUnitState.Idle, new IdleParam()); - } + //bool reachEnd = m_Owner.monsterAnimation.playbackNormalizedTime == 1; + //if (reachEnd) + //{ + // ChangeState(EUnitState.Idle, new IdleParam()); + //} yield return null; } } diff --git a/Erika/Assets/Scripts/Unit/Controller/MonsterController.cs b/Erika/Assets/Scripts/Unit/Controller/MonsterController.cs index f75933cc..ef3e5308 100644 --- a/Erika/Assets/Scripts/Unit/Controller/MonsterController.cs +++ b/Erika/Assets/Scripts/Unit/Controller/MonsterController.cs @@ -13,8 +13,8 @@ public class MonsterController : UnitController unitState = GetOrAddUnitComponent(); unitState.Initialize(); - unitAnimation = GetOrAddUnitComponent(); - unitAnimation.Initialize(); + //unitAnimation = GetOrAddUnitComponent(); + //unitAnimation.Initialize(); } public override void Update() diff --git a/Erika/Assets/Scripts/Unit/Controller/PCController.cs b/Erika/Assets/Scripts/Unit/Controller/PCController.cs index e634a4bb..94ba6e25 100644 --- a/Erika/Assets/Scripts/Unit/Controller/PCController.cs +++ b/Erika/Assets/Scripts/Unit/Controller/PCController.cs @@ -27,8 +27,8 @@ public class PCController : UnitController unitState = GetOrAddUnitComponent(); unitState.Initialize(); - unitAnimation = GetOrAddUnitComponent(); - unitAnimation.Initialize(); + //unitAnimation = GetOrAddUnitComponent(); + //unitAnimation.Initialize(); unitAfterImage = GetOrAddUnitComponent(); unitAfterImage.Initialize(); diff --git a/Erika/Assets/Scripts/Unit/Controller/UnitController.cs b/Erika/Assets/Scripts/Unit/Controller/UnitController.cs index d038831b..711b914b 100644 --- a/Erika/Assets/Scripts/Unit/Controller/UnitController.cs +++ b/Erika/Assets/Scripts/Unit/Controller/UnitController.cs @@ -33,10 +33,9 @@ public class UnitController : MonoBehaviour/*, Interactable*/ public PCState pcState { get { return unitState as PCState; } } public MonsterState monsterState { get { return unitState as MonsterState; } } - public UnitMotion unitAnimation; - public PCAnimation pcAnimation { get { return unitAnimation as PCAnimation; } } - public MonsterAnimation monsterAnimation { get { return unitAnimation as MonsterAnimation; } } + //public PCAnimation pcAnimation { get { return unitAnimation as PCAnimation; } } + //public MonsterAnimation monsterAnimation { get { return unitAnimation as MonsterAnimation; } } public UnitSkill unitSkill; diff --git a/Erika/Assets/Scripts/Unit/UnitMotionData.cs b/Erika/Assets/Scripts/Unit/UnitMotionData.cs index 851c0d3b..b8a45dd2 100644 --- a/Erika/Assets/Scripts/Unit/UnitMotionData.cs +++ b/Erika/Assets/Scripts/Unit/UnitMotionData.cs @@ -71,6 +71,28 @@ public class UnitMotionData : ScriptableObject #region 方法 + /// + /// 是否有某个动作 + /// + /// + /// + public bool HasMotionId(int id) + { + MotionData motion = GetMotionDataById(id); + return motion != null; + } + + /// + /// 是否有某个类型的动作 + /// + /// + /// + public bool HasMotionAnimationType(EAnimationType type) + { + MotionData motion = GetMotionDataByAnimationType(type); + return motion != null; + } + /// /// 用uid拿motion数据 /// -- cgit v1.1-26-g67d0