diff options
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, + + /// <summary> + /// 技能 + /// </summary> + 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; /// <summary> /// 在Animator controller里的state名,在override controller时会进行替换 +/// 这个设计的目的是为了动作的按需加载 /// </summary> 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); } + /// <summary> + /// 是否有某个类型的动作,用于gameplay逻辑 + /// </summary> + /// <param name="type"></param> + /// <returns></returns> + public bool HasAnimationType(EAnimationType type) + { + return m_MotionData.HasMotionAnimationType(type); + } + + /// <summary> + /// 是否有某个id的动作 + /// </summary> + /// <param name="uid"></param> + /// <returns></returns> + public bool HasMotionId(int uid) + { + return m_MotionData.HasMotionId(uid); + } + #region 播放动作,对外屏蔽Animator + /// <summary> + /// 过渡到某个类型的动作 + /// </summary> + /// <param name="animType"></param> + /// <param name="normalizedTransitionDuration"></param> + /// <param name="normalizedTimeOffset"></param> + /// <param name="normalizedTransitionTime"></param> + 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); + } + /// <summary> /// CrossFade过渡到目标动作 /// </summary> @@ -231,11 +267,19 @@ public class UnitMotion : UnitComponent } } - /// <summary> - /// 直接播放目标动作 - /// </summary> - /// <param name="motionId"></param> - public void PlayMotion(int motionId) + public void Play(EAnimationType animType) + { + if (!m_MotionData.HasMotionAnimationType(animType)) + return; + MotionData motion = m_MotionData.GetMotionDataByAnimationType(animType); + PlayMotion(motion); + } + + /// <summary> + /// 直接播放目标动作 + /// </summary> + /// <param name="motionId"></param> + 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<T>(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<MonsterState>();
unitState.Initialize();
- unitAnimation = GetOrAddUnitComponent<MonsterAnimation>();
- unitAnimation.Initialize();
+ //unitAnimation = GetOrAddUnitComponent<MonsterAnimation>();
+ //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<PCState>();
unitState.Initialize();
- unitAnimation = GetOrAddUnitComponent<PCAnimation>();
- unitAnimation.Initialize();
+ //unitAnimation = GetOrAddUnitComponent<PCAnimation>();
+ //unitAnimation.Initialize();
unitAfterImage = GetOrAddUnitComponent<UnitAfterImage>();
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 @@ -72,6 +72,28 @@ public class UnitMotionData : ScriptableObject #region 方法 /// <summary> + /// 是否有某个动作 + /// </summary> + /// <param name="id"></param> + /// <returns></returns> + public bool HasMotionId(int id) + { + MotionData motion = GetMotionDataById(id); + return motion != null; + } + + /// <summary> + /// 是否有某个类型的动作 + /// </summary> + /// <param name="type"></param> + /// <returns></returns> + public bool HasMotionAnimationType(EAnimationType type) + { + MotionData motion = GetMotionDataByAnimationType(type); + return motion != null; + } + + /// <summary> /// 用uid拿motion数据 /// </summary> /// <param name="id"></param> |