diff options
author | chai <chaifix@163.com> | 2021-09-01 08:30:42 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2021-09-01 08:30:42 +0800 |
commit | a5c191cf74238084d9bd9f805b4b6755f70d956d (patch) | |
tree | 06c0f5a85e6bda587205e5b2bea8e2d9fab4f373 /Assets/Scripts | |
parent | 340bb7224b4f100413541df3b937d90be028a8b1 (diff) |
*改变目录结构
Diffstat (limited to 'Assets/Scripts')
39 files changed, 1647 insertions, 1415 deletions
diff --git a/Assets/Scripts/Unit/Component.meta b/Assets/Scripts/Unit/Components.meta index 3d416e3a..3d416e3a 100644 --- a/Assets/Scripts/Unit/Component.meta +++ b/Assets/Scripts/Unit/Components.meta diff --git a/Assets/Scripts/Props.meta b/Assets/Scripts/Unit/Components/UnitAnimation.meta index bb96602e..580176c0 100644 --- a/Assets/Scripts/Props.meta +++ b/Assets/Scripts/Unit/Components/UnitAnimation.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: f299520ed9fcf4a45858ad4ef5a8d5d1 +guid: 21e3b4128e398d745a22f45d6268b4c7 folderAsset: yes DefaultImporter: externalObjects: {} diff --git a/Assets/Scripts/Unit/Components/UnitAnimation/DroneAnimation.cs b/Assets/Scripts/Unit/Components/UnitAnimation/DroneAnimation.cs new file mode 100644 index 00000000..29caab7b --- /dev/null +++ b/Assets/Scripts/Unit/Components/UnitAnimation/DroneAnimation.cs @@ -0,0 +1,18 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class DroneAnimation : MonoBehaviour +{ + // Start is called before the first frame update + void Start() + { + + } + + // Update is called once per frame + void Update() + { + + } +} diff --git a/Assets/Scripts/Unit/Components/UnitAnimation/DroneAnimation.cs.meta b/Assets/Scripts/Unit/Components/UnitAnimation/DroneAnimation.cs.meta new file mode 100644 index 00000000..219b76ff --- /dev/null +++ b/Assets/Scripts/Unit/Components/UnitAnimation/DroneAnimation.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 352eb281e97bf67499a8a85ab013f0f0 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Unit/Component/MonsterAnimation.cs b/Assets/Scripts/Unit/Components/UnitAnimation/MonsterAnimation.cs index 4db4b07f..26361098 100644 --- a/Assets/Scripts/Unit/Component/MonsterAnimation.cs +++ b/Assets/Scripts/Unit/Components/UnitAnimation/MonsterAnimation.cs @@ -1,110 +1,110 @@ -using System.Collections;
-using System.Collections.Generic;
-using UnityEngine;
-
-public class MonsterAnimation : UnitAnimation
-{
- public enum ELayer
- {
- Basic = 0,
-
- Count,
- }
-
- // 动作名,和animator里的state对应
- public enum EAnimState
- {
- // layer 0
- Idle = 0,
- Move,
- Jump,
- Hit,
- Attack,
- Rise,
- Stinger,
- Turn,
- Landing,
-
- AirAttack0,
- AirAttack1,
- AirAttack2,
- AirAttack3,
-
- Attack0,
- Attack1,
- Attack2,
- Attack3,
- }
-
- public override void Initialize()
- {
- base.Initialize();
-
- m_Animator = this.m_Owner.unitObj.GetComponent<Animator>();
-
- m_Animator.speed = 0;
-
- m_LayerInfo = new AnimatorLayerInfo[2];
- m_LayerInfo[0] = new AnimatorLayerInfo(this, m_Animator, (int)ELayer.Basic);
- //m_LayerInfo[1] = new AnimatorLayerInfo(this, m_Animator, ELayer.Attack);
-
- if (m_Animator == null)
- {
- LogHelper.LogError("没有挂Animator组件");
- }
-
- }
-
- public override void OnUpdate()
- {
- base.OnUpdate();
-
- UpdateLayer();
- UpdateAnimation();
- UpdateRootMotion();
- }
-
- void UpdateLayer()
- {
- m_LayerInfo[0].OnUpdate();
- return;
- for (int i = 0; i < m_LayerInfo.Length; ++i)
- {
- m_LayerInfo[i].OnUpdate();
- }
- }
-
- void UpdateAnimation()
- {
- m_Animator.speed = 1;
- m_Animator.Update(Time.deltaTime);
- m_Animator.speed = 0;
- }
-
- void UpdateRootMotion()
- {
- m_Owner.unitRootMotion.UpdateRootMotion();
- }
-
- public void AnimIdle()
- {
- m_Animator.CrossFade("Idle", 0.2f, 0);
- }
-
- public void AnimHitLight()
- {
- m_Animator.Play("HitLight", 0, 0);
- //m_Animator.CrossFade("HitLight", 0.05f, 0, 0, 0);
- }
- public void AnimHitAir()
- {
- m_Animator.Play("HitAir", 0, 0);
- //m_Animator.CrossFade("HitLight", 0.05f, 0, 0, 0);
- }
-
- public void AnimRise()
- {
- m_Animator.CrossFade("Rise", 0);
- }
-
-}
+using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class MonsterAnimation : UnitAnimation +{ + public enum ELayer + { + Basic = 0, + + Count, + } + + // 动作名,和animator里的state对应 + public enum EAnimState + { + // layer 0 + Idle = 0, + Move, + Jump, + Hit, + Attack, + Rise, + Stinger, + Turn, + Landing, + + AirAttack0, + AirAttack1, + AirAttack2, + AirAttack3, + + Attack0, + Attack1, + Attack2, + Attack3, + } + + public override void Initialize() + { + base.Initialize(); + + m_Animator = this.m_Owner.unitObj.GetComponent<Animator>(); + + m_Animator.speed = 0; + + m_LayerInfo = new AnimatorLayerInfo[2]; + m_LayerInfo[0] = new AnimatorLayerInfo(this, m_Animator, (int)ELayer.Basic); + //m_LayerInfo[1] = new AnimatorLayerInfo(this, m_Animator, ELayer.Attack); + + if (m_Animator == null) + { + LogHelper.LogError("没有挂Animator组件"); + } + + } + + public override void OnUpdate() + { + base.OnUpdate(); + + UpdateLayer(); + UpdateAnimation(); + UpdateRootMotion(); + } + + void UpdateLayer() + { + m_LayerInfo[0].OnUpdate(); + return; + for (int i = 0; i < m_LayerInfo.Length; ++i) + { + m_LayerInfo[i].OnUpdate(); + } + } + + void UpdateAnimation() + { + m_Animator.speed = 1; + m_Animator.Update(Time.deltaTime); + m_Animator.speed = 0; + } + + void UpdateRootMotion() + { + m_Owner.unitRootMotion.UpdateRootMotion(); + } + + public void AnimIdle() + { + m_Animator.CrossFade("Idle", 0.2f, 0); + } + + public void AnimHitLight() + { + m_Animator.Play("HitLight", 0, 0); + //m_Animator.CrossFade("HitLight", 0.05f, 0, 0, 0); + } + public void AnimHitAir() + { + m_Animator.Play("HitAir", 0, 0); + //m_Animator.CrossFade("HitLight", 0.05f, 0, 0, 0); + } + + public void AnimRise() + { + m_Animator.CrossFade("Rise", 0); + } + +} diff --git a/Assets/Scripts/Unit/Component/MonsterAnimation.cs.meta b/Assets/Scripts/Unit/Components/UnitAnimation/MonsterAnimation.cs.meta index 448e6a1a..448e6a1a 100644 --- a/Assets/Scripts/Unit/Component/MonsterAnimation.cs.meta +++ b/Assets/Scripts/Unit/Components/UnitAnimation/MonsterAnimation.cs.meta diff --git a/Assets/Scripts/Unit/Component/PCAnimation.cs b/Assets/Scripts/Unit/Components/UnitAnimation/PCAnimation.cs index 9c2a77ec..8a265f45 100644 --- a/Assets/Scripts/Unit/Component/PCAnimation.cs +++ b/Assets/Scripts/Unit/Components/UnitAnimation/PCAnimation.cs @@ -1,217 +1,217 @@ -#define ANIM_CROSS_FADE
-using System;
-using System.Collections;
-using System.Collections.Generic;
-using UnityEngine;
-
-public class PCAnimation : UnitAnimation
-{
- public enum ELayer
- {
- Basic = 0,
- Attack,
- SwordAttack,
- GunAttack,
- UpperBody,
- LowerBody,
- Count,
- }
-
-
- // 动作名,和animator里的state对应
- public enum EAnimState
- {
- // layer 0
- Idle = 0,
- Move,
- Jump,
- Hit,
- Attack,
- Rise,
- Stinger,
- Turn,
- Landing,
-
- AirAttack0,
- AirAttack1,
- AirAttack2,
- AirAttack3,
-
- Attack0,
- Attack1,
- Attack2,
- Attack3,
- }
-
-#if !ANIM_CROSS_FADE
- // 切换动画
- public enum ETrigger
- {
- ToIdle,
- ToMove,
- ToJump,
- ToAttack,
- ToAirAttack,
- ToLanding,
- }
-#endif
-
- private UnitActionData m_ActionData;
-
- public bool applyRootMotion { get; set; }// 动态设置root motion
- public bool applyRootCurve { get; set; } // 程序生成的root motion
-
- public override void Initialize()
- {
- base.Initialize();
-
- m_Animator = this.m_Owner.unitObj.GetComponent<Animator>();
-
- m_Animator.speed = 0;
-
- m_LayerInfo = new AnimatorLayerInfo[2];
- m_LayerInfo[0] = new AnimatorLayerInfo(this, m_Animator, (int)ELayer.Basic);
- //m_LayerInfo[1] = new AnimatorLayerInfo(this, m_Animator, ELayer.Attack);
-
- if (m_Animator == null)
- {
- LogHelper.LogError("没有挂Animator组件");
- }
-
- applyRootMotion = true;
- }
-
- public override void OnUpdate()
- {
- base.OnUpdate();
-
- UpdateLayer();
- UpdateAnimation();
-
- if (applyRootMotion)
- UpdateRootMotion();
- if (applyRootCurve)
- UpdateRootCurve();
- }
-
- void UpdateLayer()
- {
- m_LayerInfo[0].OnUpdate();
- return;
- for (int i = 0; i < m_LayerInfo.Length; ++i)
- {
- m_LayerInfo[i].OnUpdate();
- }
- }
-
- void UpdateAnimation()
- {
- m_Animator.speed = 1;
- m_Animator.Update(Time.deltaTime);
- m_Animator.speed = 0;
- }
-
- void UpdateRootMotion()
- {
- m_Owner.unitRootMotion.UpdateRootMotion();
- }
-
- void UpdateRootCurve()
- {
- }
-
- public void AnimIdle()
- {
-#if ANIM_CROSS_FADE
- m_Animator.CrossFade("Idle", 0.2f, 0);
-#else
- ResetAllTriggers();
- m_Animator.SetTrigger(ETrigger.ToIdle.ToString());
-#endif
- }
-
- public void AnimMove()
- {
-#if ANIM_CROSS_FADE
- m_Animator.CrossFade("Move", 0.01f, 0);
-#else
- ResetAllTriggers();
- m_Animator.SetTrigger(ETrigger.ToMove.ToString());
-#endif
- }
-
- public void AnimJump()
- {
-#if ANIM_CROSS_FADE
- m_Animator.CrossFade("Jump", 0.01f);
-#else
- ResetAllTriggers();
- SetTrigger(ETrigger.ToJump);
-#endif
- }
-
- public void AnimAirAttack(int id)
- {
- m_Owner.unitCollider.OnAnimationChange();
-#if ANIM_CROSS_FADE
- m_Animator.CrossFade("AirAttack" + id, 0.05f);
-#else
- ResetAllTriggers();
- SetTrigger(ETrigger.ToAirAttack);
-#endif
- }
-
- public void AnimAttack(int id)
- {
- m_Owner.unitCollider.OnAnimationChange();
- m_Animator.CrossFade("Attack" + id, 0.05f);
- }
-
- 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);
-#else
- ResetAllTriggers();
- SetTrigger(ETrigger.ToLanding);
-#endif
- }
-
- public void AnimLandingGround()
- {
-#if ANIM_CROSS_FADE
- m_Animator.CrossFade("LandingGround", 0.00f);
-#else
- ResetAllTriggers();
- SetTrigger(ETrigger.ToLanding);
-#endif
- }
-
-#if !ANIM_CROSS_FADE
- void ResetAllTriggers()
- {
- var values = Enum.GetValues(typeof(ETrigger));
- foreach (var e in values)
- {
- m_Animator.ResetTrigger(e.ToString());
- }
- }
-#endif
-
- private void Play(string animState, float fade = 0.1f, float offset = 0f, int layer = 0)
- {
- m_Animator.CrossFade(animState, fade, layer, offset);
- }
-}
+#define ANIM_CROSS_FADE +using System; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class PCAnimation : UnitAnimation +{ + public enum ELayer + { + Basic = 0, + Attack, + SwordAttack, + GunAttack, + UpperBody, + LowerBody, + Count, + } + + + // 动作名,和animator里的state对应 + public enum EAnimState + { + // layer 0 + Idle = 0, + Move, + Jump, + Hit, + Attack, + Rise, + Stinger, + Turn, + Landing, + + AirAttack0, + AirAttack1, + AirAttack2, + AirAttack3, + + Attack0, + Attack1, + Attack2, + Attack3, + } + +#if !ANIM_CROSS_FADE + // 切换动画 + public enum ETrigger + { + ToIdle, + ToMove, + ToJump, + ToAttack, + ToAirAttack, + ToLanding, + } +#endif + + private UnitActionData m_ActionData; + + public bool applyRootMotion { get; set; }// 动态设置root motion + public bool applyRootCurve { get; set; } // 程序生成的root motion + + public override void Initialize() + { + base.Initialize(); + + m_Animator = this.m_Owner.unitObj.GetComponent<Animator>(); + + m_Animator.speed = 0; + + m_LayerInfo = new AnimatorLayerInfo[2]; + m_LayerInfo[0] = new AnimatorLayerInfo(this, m_Animator, (int)ELayer.Basic); + //m_LayerInfo[1] = new AnimatorLayerInfo(this, m_Animator, ELayer.Attack); + + if (m_Animator == null) + { + LogHelper.LogError("没有挂Animator组件"); + } + + applyRootMotion = true; + } + + public override void OnUpdate() + { + base.OnUpdate(); + + UpdateLayer(); + UpdateAnimation(); + + if (applyRootMotion) + UpdateRootMotion(); + if (applyRootCurve) + UpdateRootCurve(); + } + + void UpdateLayer() + { + m_LayerInfo[0].OnUpdate(); + return; + for (int i = 0; i < m_LayerInfo.Length; ++i) + { + m_LayerInfo[i].OnUpdate(); + } + } + + void UpdateAnimation() + { + m_Animator.speed = 1; + m_Animator.Update(Time.deltaTime); + m_Animator.speed = 0; + } + + void UpdateRootMotion() + { + m_Owner.unitRootMotion.UpdateRootMotion(); + } + + void UpdateRootCurve() + { + } + + public void AnimIdle() + { +#if ANIM_CROSS_FADE + m_Animator.CrossFade("Idle", 0.2f, 0); +#else + ResetAllTriggers(); + m_Animator.SetTrigger(ETrigger.ToIdle.ToString()); +#endif + } + + public void AnimMove() + { +#if ANIM_CROSS_FADE + m_Animator.CrossFade("Move", 0.01f, 0); +#else + ResetAllTriggers(); + m_Animator.SetTrigger(ETrigger.ToMove.ToString()); +#endif + } + + public void AnimJump() + { +#if ANIM_CROSS_FADE + m_Animator.CrossFade("Jump", 0.01f); +#else + ResetAllTriggers(); + SetTrigger(ETrigger.ToJump); +#endif + } + + public void AnimAirAttack(int id) + { + m_Owner.unitCollider.OnAnimationChange(); +#if ANIM_CROSS_FADE + m_Animator.CrossFade("AirAttack" + id, 0.05f); +#else + ResetAllTriggers(); + SetTrigger(ETrigger.ToAirAttack); +#endif + } + + public void AnimAttack(int id) + { + m_Owner.unitCollider.OnAnimationChange(); + m_Animator.CrossFade("Attack" + id, 0.05f); + } + + 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); +#else + ResetAllTriggers(); + SetTrigger(ETrigger.ToLanding); +#endif + } + + public void AnimLandingGround() + { +#if ANIM_CROSS_FADE + m_Animator.CrossFade("LandingGround", 0.00f); +#else + ResetAllTriggers(); + SetTrigger(ETrigger.ToLanding); +#endif + } + +#if !ANIM_CROSS_FADE + void ResetAllTriggers() + { + var values = Enum.GetValues(typeof(ETrigger)); + foreach (var e in values) + { + m_Animator.ResetTrigger(e.ToString()); + } + } +#endif + + private void Play(string animState, float fade = 0.1f, float offset = 0f, int layer = 0) + { + m_Animator.CrossFade(animState, fade, layer, offset); + } +} diff --git a/Assets/Scripts/Unit/Component/PCAnimation.cs.meta b/Assets/Scripts/Unit/Components/UnitAnimation/PCAnimation.cs.meta index 6999e268..6999e268 100644 --- a/Assets/Scripts/Unit/Component/PCAnimation.cs.meta +++ b/Assets/Scripts/Unit/Components/UnitAnimation/PCAnimation.cs.meta diff --git a/Assets/Scripts/Unit/Components/UnitAnimation/RobotAnimation.cs b/Assets/Scripts/Unit/Components/UnitAnimation/RobotAnimation.cs new file mode 100644 index 00000000..a25f453e --- /dev/null +++ b/Assets/Scripts/Unit/Components/UnitAnimation/RobotAnimation.cs @@ -0,0 +1,18 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class RobotAnimation : MonoBehaviour +{ + // Start is called before the first frame update + void Start() + { + + } + + // Update is called once per frame + void Update() + { + + } +} diff --git a/Assets/Scripts/Unit/Components/UnitAnimation/RobotAnimation.cs.meta b/Assets/Scripts/Unit/Components/UnitAnimation/RobotAnimation.cs.meta new file mode 100644 index 00000000..f1cbe366 --- /dev/null +++ b/Assets/Scripts/Unit/Components/UnitAnimation/RobotAnimation.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 1f127e594317b84478999dccd109e5bf +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Unit/Component/UnitAnimation.cs b/Assets/Scripts/Unit/Components/UnitAnimation/UnitAnimation.cs index 3df9ef89..586bfbaa 100644 --- a/Assets/Scripts/Unit/Component/UnitAnimation.cs +++ b/Assets/Scripts/Unit/Components/UnitAnimation/UnitAnimation.cs @@ -1,249 +1,249 @@ -#define ANIM_CROSS_FADE
-using System;
-using System.Collections;
-using System.Collections.Generic;
-using UnityEngine;
-#if UNITY_EDITOR
-using UnityEditor;
-#endif
-
-// 单独一层动画
-public class AnimatorLayerInfo
-{
- public int layer;
-
- public int layerIndex { get { return (int)layer; } }
-
- public string name { get { return m_Animator.GetLayerName(layerIndex); } }
-
- private Animator m_Animator;
-
- // 当前动作的animation data,如果是blendtree选第一个动作
- private AnimationData m_AnimationData;
- public AnimationData animationData
- {
- get
- {
- if (clipInfo == null || clipInfo.Length == 0)
- return null;
- var clip = clipInfo[0]; //选第一个
- string folder = m_UnitAnimation.owner.folder;
- string name = clip.clip.name;
- if (m_AnimationData != null && m_AnimationData.animationName == name)
- return m_AnimationData;
- string path = folder + "AnimationData/" + name + ".asset" ; // 要注意这里使用名字区别的,因为最终每个角色的动画都会在一个目录下面
-#if UNITY_EDITOR
- m_AnimationData = AssetDatabase.LoadAssetAtPath<AnimationData>(path);
-#endif
- return m_AnimationData;
- }
- }
-
- // 当前动作所有animation data,包括blendtree使用的所有动画
- //private List<AnimationData> m_AnimationDatas;
- //public List<AnimationData> animationDatas
- //{
- // get
- // {
- // return null;
- // }
- //}
-
- // 当前在播放的动作
- // 如果处于transition中,动作不变,切换完成后才会到下一个动作
- public AnimatorStateInfo stateInfo
- {
- get
- {
- AnimatorStateInfo stateInfo = m_Animator.GetCurrentAnimatorStateInfo(layerIndex);
- AnimatorClipInfo[] clips = m_Animator.GetCurrentAnimatorClipInfo(layerIndex);
- if(clips == null || clips.Length == 0)
- {
- stateInfo = m_Animator.GetNextAnimatorStateInfo(layerIndex);
- }
- return stateInfo;
- }
- }
-
- private int preStateHash = -1;
-
- // 当前正在播放和融合的片段信息
- public AnimatorClipInfo[] clipInfo
- {
- get
- {
- AnimatorClipInfo[] clips = m_Animator.GetCurrentAnimatorClipInfo(layerIndex);
- if(clips.Length == 0)
- {
- // 如果transition设置了打断,会出现GetCurrentAnimatorClipinfo返回空数组的情况
- clips = m_Animator.GetNextAnimatorClipInfo(layerIndex);
- }
- return clips;
- }
- }
-
- public int stateHash
- {
- get
- {
- return stateInfo.shortNameHash;
- }
- }
-
- //public float playbackTimeInSeconds
- //{
- // get
- // {
- // return stateInfo.normalizedTime * stateInfo.length;// stateInfo.length会等于infinity,因为设置了animator.speed = 0
- // }
- //}
-
- // 并非准确的播放时间,只是逻辑时间,因为动画会加速减速
- public float playbackTimeInSeconds
- {
- get
- {
- return playbackNomralizedTime * clipInfo[0].clip.length;
- }
- }
-
- // 这个是真实世界的时间
- private float m_PlaybackRealTime;
- public float playbackRealTimeInSeconds
- {
- get
- {
- return m_PlaybackRealTime;
- }
- }
-
- // 播放进度百分比,[0-1],是逻辑上的,如果动画不是loop,那么播放完后normalizedTime是1
- public float playbackNomralizedTime
- {
- get
- {
- //return stateInfo.normalizedTime % 1f;
- if (!stateInfo.loop && stateInfo.normalizedTime > 1)
- return 1;
- return stateInfo.normalizedTime % 1f;
- }
- }
-
- public float playbackSpeed
- {
- get
- {
- return m_Animator.GetFloat("PlaybackSpeed" + layerIndex);
- }
- set
- {
- float v = Mathf.Clamp(value, 0, 10);
- m_Animator.SetFloat("PlaybackSpeed" + layerIndex, v);
- }
- }
-
- public float weight
- {
- get
- {
- return m_Animator.GetLayerWeight(layerIndex);
- }
- }
-
- public int nextStateHash
- {
- get
- {
- //if (!isInTransition)
- // return 0;
- AnimatorStateInfo nextState = m_Animator.GetNextAnimatorStateInfo(layerIndex);
- int hash = nextState.shortNameHash; // 如果不在过渡中,hash是0
- return hash;
- }
- }
-
- public bool isInTransition
- {
- get
- {
- return m_Animator.IsInTransition(layerIndex);
- }
- }
-
- public bool applySpeedCurve { get; set; }
-
- UnitAnimation m_UnitAnimation;
-
- Coroutine m_CalcPlaybackTimeCoroutine;
-
- TimelineEventProxy m_TimelineEventProxy;
-
- public AnimatorLayerInfo(UnitAnimation unitAnimation, Animator animator, int layer)
- {
- this.m_UnitAnimation = unitAnimation;
- this.m_Animator = animator;
- this.layer = layer;
- m_CalcPlaybackTimeCoroutine = unitAnimation.StartCoroutine(CalcPlaybackRealTimeCoroutine());
- m_TimelineEventProxy = new TimelineEventProxy(unitAnimation.owner.transform, unitAnimation.owner);
- applySpeedCurve = true;
- }
-
- IEnumerator CalcPlaybackRealTimeCoroutine()
- {
- while (true)
- {
- if(preStateHash != stateHash)
- {
- m_PlaybackRealTime = 0;
- }
- m_PlaybackRealTime += Time.deltaTime;
- preStateHash = stateHash;
- yield return null;
- }
- }
-
- public bool IsToggleOpen(EAnimationToogle toggle)
- {
- if (m_AnimationData == null)
- return false;
- return m_AnimationData.IsToggleOpen(toggle, playbackNomralizedTime);
- }
-
- public void OnUpdate()
- {
- // 执行事件
- m_TimelineEventProxy.ExecuteAnimationEvents(animationData, playbackTimeInSeconds * TimelineEventProxy.FPS);
-
- // 播放速度控制
- if (applySpeedCurve && animationData != null && animationData.speedCurve != null)
- {
- playbackSpeed = animationData.speedCurve.Evaluate(playbackNomralizedTime);
- }
-
- }
-
-}
-
-// 控制动画播放、执行动作timeline(包括执行事件和碰撞盒)
-// 每个layer同时只会有一个动画在播放,在执行transition时,current animation依然是
-// 这个动作,只有完全过渡完成后才会切到下一个动作
-// 当前是什么动作以ainmator的GetCurrentAnimatorStateInfo为准
-[DisallowMultipleComponent]
-public class UnitAnimation : UnitComponent
-{
- public AnimatorLayerInfo[] layers { get { return m_LayerInfo; } }
- protected AnimatorLayerInfo[] m_LayerInfo;
-
- public Animator animator { get { return m_Animator; } }
- protected Animator m_Animator;
-
-
- public bool isInTransition
- {
- get
- {
- return m_Animator.IsInTransition(0);
- }
- }
-
-}
+#define ANIM_CROSS_FADE +using System; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +#if UNITY_EDITOR +using UnityEditor; +#endif + +// 单独一层动画 +public class AnimatorLayerInfo +{ + public int layer; + + public int layerIndex { get { return (int)layer; } } + + public string name { get { return m_Animator.GetLayerName(layerIndex); } } + + private Animator m_Animator; + + // 当前动作的animation data,如果是blendtree选第一个动作 + private AnimationData m_AnimationData; + public AnimationData animationData + { + get + { + if (clipInfo == null || clipInfo.Length == 0) + return null; + var clip = clipInfo[0]; //选第一个 + string folder = m_UnitAnimation.owner.folder; + string name = clip.clip.name; + if (m_AnimationData != null && m_AnimationData.animationName == name) + return m_AnimationData; + string path = folder + "AnimationData/" + name + ".asset" ; // 要注意这里使用名字区别的,因为最终每个角色的动画都会在一个目录下面 +#if UNITY_EDITOR + m_AnimationData = AssetDatabase.LoadAssetAtPath<AnimationData>(path); +#endif + return m_AnimationData; + } + } + + // 当前动作所有animation data,包括blendtree使用的所有动画 + //private List<AnimationData> m_AnimationDatas; + //public List<AnimationData> animationDatas + //{ + // get + // { + // return null; + // } + //} + + // 当前在播放的动作 + // 如果处于transition中,动作不变,切换完成后才会到下一个动作 + public AnimatorStateInfo stateInfo + { + get + { + AnimatorStateInfo stateInfo = m_Animator.GetCurrentAnimatorStateInfo(layerIndex); + AnimatorClipInfo[] clips = m_Animator.GetCurrentAnimatorClipInfo(layerIndex); + if(clips == null || clips.Length == 0) + { + stateInfo = m_Animator.GetNextAnimatorStateInfo(layerIndex); + } + return stateInfo; + } + } + + private int preStateHash = -1; + + // 当前正在播放和融合的片段信息 + public AnimatorClipInfo[] clipInfo + { + get + { + AnimatorClipInfo[] clips = m_Animator.GetCurrentAnimatorClipInfo(layerIndex); + if(clips.Length == 0) + { + // 如果transition设置了打断,会出现GetCurrentAnimatorClipinfo返回空数组的情况 + clips = m_Animator.GetNextAnimatorClipInfo(layerIndex); + } + return clips; + } + } + + public int stateHash + { + get + { + return stateInfo.shortNameHash; + } + } + + //public float playbackTimeInSeconds + //{ + // get + // { + // return stateInfo.normalizedTime * stateInfo.length;// stateInfo.length会等于infinity,因为设置了animator.speed = 0 + // } + //} + + // 并非准确的播放时间,只是逻辑时间,因为动画会加速减速 + public float playbackTimeInSeconds + { + get + { + return playbackNormalizedTime * clipInfo[0].clip.length; + } + } + + // 这个是真实世界的时间 + private float m_PlaybackRealTime; + public float playbackRealTimeInSeconds + { + get + { + return m_PlaybackRealTime; + } + } + + // 播放进度百分比,[0-1],是逻辑上的,如果动画不是loop,那么播放完后normalizedTime是1 + public float playbackNormalizedTime + { + get + { + //return stateInfo.normalizedTime % 1f; + if (!stateInfo.loop && stateInfo.normalizedTime > 1) + return 1; + return stateInfo.normalizedTime % 1f; + } + } + + public float playbackSpeed + { + get + { + return m_Animator.GetFloat("PlaybackSpeed" + layerIndex); + } + set + { + float v = Mathf.Clamp(value, 0, 10); + m_Animator.SetFloat("PlaybackSpeed" + layerIndex, v); + } + } + + public float weight + { + get + { + return m_Animator.GetLayerWeight(layerIndex); + } + } + + public int nextStateHash + { + get + { + //if (!isInTransition) + // return 0; + AnimatorStateInfo nextState = m_Animator.GetNextAnimatorStateInfo(layerIndex); + int hash = nextState.shortNameHash; // 如果不在过渡中,hash是0 + return hash; + } + } + + public bool isInTransition + { + get + { + return m_Animator.IsInTransition(layerIndex); + } + } + + public bool applySpeedCurve { get; set; } + + UnitAnimation m_UnitAnimation; + + Coroutine m_CalcPlaybackTimeCoroutine; + + TimelineEventProxy m_TimelineEventProxy; + + public AnimatorLayerInfo(UnitAnimation unitAnimation, Animator animator, int layer) + { + this.m_UnitAnimation = unitAnimation; + this.m_Animator = animator; + this.layer = layer; + m_CalcPlaybackTimeCoroutine = unitAnimation.StartCoroutine(CalcPlaybackRealTimeCoroutine()); + m_TimelineEventProxy = new TimelineEventProxy(unitAnimation.owner.transform, unitAnimation.owner); + applySpeedCurve = true; + } + + IEnumerator CalcPlaybackRealTimeCoroutine() + { + while (true) + { + if(preStateHash != stateHash) + { + m_PlaybackRealTime = 0; + } + m_PlaybackRealTime += Time.deltaTime; + preStateHash = stateHash; + yield return null; + } + } + + public bool IsToggleOpen(EAnimationToogle toggle) + { + if (m_AnimationData == null) + return false; + return m_AnimationData.IsToggleOpen(toggle, playbackNormalizedTime); + } + + public void OnUpdate() + { + // 执行事件 + m_TimelineEventProxy.ExecuteAnimationEvents(animationData, playbackTimeInSeconds * TimelineEventProxy.FPS); + + // 播放速度控制 + if (applySpeedCurve && animationData != null && animationData.speedCurve != null) + { + playbackSpeed = animationData.speedCurve.Evaluate(playbackNormalizedTime); + } + + } + +} + +// 控制动画播放、执行动作timeline(包括执行事件和碰撞盒) +// 每个layer同时只会有一个动画在播放,在执行transition时,current animation依然是 +// 这个动作,只有完全过渡完成后才会切到下一个动作 +// 当前是什么动作以ainmator的GetCurrentAnimatorStateInfo为准 +[DisallowMultipleComponent] +public class UnitAnimation : UnitComponent +{ + public AnimatorLayerInfo[] layers { get { return m_LayerInfo; } } + protected AnimatorLayerInfo[] m_LayerInfo; + + public Animator animator { get { return m_Animator; } } + protected Animator m_Animator; + + + public bool isInTransition + { + get + { + return m_Animator.IsInTransition(0); + } + } + +} diff --git a/Assets/Scripts/Unit/Component/UnitAnimation.cs.meta b/Assets/Scripts/Unit/Components/UnitAnimation/UnitAnimation.cs.meta index 75ce33fe..75ce33fe 100644 --- a/Assets/Scripts/Unit/Component/UnitAnimation.cs.meta +++ b/Assets/Scripts/Unit/Components/UnitAnimation/UnitAnimation.cs.meta diff --git a/Assets/Scripts/Unit/Component/UnitCollider.cs b/Assets/Scripts/Unit/Components/UnitCollider.cs index ac9698a8..63e1ff7f 100644 --- a/Assets/Scripts/Unit/Component/UnitCollider.cs +++ b/Assets/Scripts/Unit/Components/UnitCollider.cs @@ -1,123 +1,123 @@ -using System.Collections;
-using System.Collections.Generic;
-using UnityEngine;
-
-// 角色当前的碰撞盒
-[DisallowMultipleComponent]
-public class UnitCollider : UnitComponent
-{
- public bool showGizmos;
-
- private Dictionary<int/*hitbox hash*/, List<int/*unitController hash*/>> m_HitMask = new Dictionary<int, List<int>>();
-
- public override void Awake()
- {
- base.Awake();
-
- ColliderRegistry.Instance.AddCollider(this);
- }
-
- public override void OnDestroy()
- {
- ColliderRegistry.Instance.RemoveCollider(this);
-
- base.OnDestroy();
- }
-
- public override void Initialize()
- {
- base.Initialize();
- showGizmos = true;
- }
-
- // 返回当前激活的对应类型的碰撞盒数据
- public ColliderInfo[] GetCurrentBoxesInfoByType(ColliderBox.EColliderType type, int layer = 0)
- {
- var layerInfo = m_Owner.unitAnimation.layers[0];
- AnimationData animData = layerInfo.animationData;
- AnimatorClipInfo[] clipInfos = layerInfo.clipInfo;
- //if(clipInfos == null || clipInfos.Length == 0)
- //{
- // return null;
- //}
- float playbackTime = layerInfo.playbackNomralizedTime * clipInfos[0].clip.length;
- //float playbackTime = layerInfo.playbackRealTimeInSeconds;
- ColliderInfo[] infos = animData.GetActiveCollidersInfo(type, playbackTime);
- return infos;
- }
-
- // 动作切换,重置collider mask
- public void OnAnimationChange()
- {
- m_HitMask.Clear();
- }
-
- public void RecordCollision(int colliderHash, int targetHash)
- {
- List<int> record;
- if (!m_HitMask.TryGetValue(colliderHash, out record))
- {
- record = new List<int>();
- m_HitMask.Add(colliderHash, record);
- }
- record.Add(targetHash);
- }
-
- public bool CanCollide(int colliderHash, int targetHash)
- {
- List<int> record;
- if(!m_HitMask.TryGetValue(colliderHash, out record))
- {
- return true;
- }
- return !record.Contains(targetHash);
- }
-
-#if UNITY_EDITOR
-
- // 绘制collider调试
- public void OnDrawGizmos()
- {
- if (!showGizmos)
- return;
-
- Vector3 unitPos = m_Owner.transform.position;
-
- OnDrawColliders(ColliderBox.EColliderType.HurtBox, Color.green);
- OnDrawColliders(ColliderBox.EColliderType.HitBox, Color.red);
- }
-
- void OnDrawColliders(ColliderBox.EColliderType type, Color color)
- {
- ColliderInfo[] boxes = GetCurrentBoxesInfoByType(type);
- if (boxes == null || boxes.Length == 0)
- return;
- Vector3 unitPos = m_Owner.transform.position;
- Quaternion right = Quaternion.Euler(0, 0, 0);
- Vector3 fac = new Vector3(1,1, m_Owner.transform.forward.normalized == Vector3.forward ? 1 : -1);
- Color oldC = Gizmos.color;
- Gizmos.color = color * 0.5f;
- for (int i = 0; i < boxes.Length; ++i)
- {
- var box = boxes[i];
- if (!box.isValid)
- continue;
- Vector3 localPos = box.position;
- Vector3 localSize = box.size;
- var pivot = box.pivot;
- Vector3 pos = Vector3.zero; // gizmo位置
- switch (pivot)
- {
- case ColliderBox.Pivot.MiddleBottom:
- localPos.y += localSize.y / 2;
- break;
- }
- pos = unitPos + Vector3.Scale(localPos, fac);
- Gizmos.DrawCube(pos, localSize);
- }
- Gizmos.color = oldC;
- }
-
-#endif
-
-}
+using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +// 角色当前的碰撞盒 +[DisallowMultipleComponent] +public class UnitCollider : UnitComponent +{ + public bool showGizmos; + + private Dictionary<int/*hitbox hash*/, List<int/*unitController hash*/>> m_HitMask = new Dictionary<int, List<int>>(); + + public override void Awake() + { + base.Awake(); + + ColliderRegistry.Instance.AddCollider(this); + } + + public override void OnDestroy() + { + ColliderRegistry.Instance.RemoveCollider(this); + + base.OnDestroy(); + } + + public override void Initialize() + { + base.Initialize(); + showGizmos = true; + } + + // 返回当前激活的对应类型的碰撞盒数据 + public ColliderInfo[] GetCurrentBoxesInfoByType(ColliderBox.EColliderType type, int layer = 0) + { + var layerInfo = m_Owner.unitAnimation.layers[0]; + AnimationData animData = layerInfo.animationData; + AnimatorClipInfo[] clipInfos = layerInfo.clipInfo; + //if(clipInfos == null || clipInfos.Length == 0) + //{ + // return null; + //} + float playbackTime = layerInfo.playbackNormalizedTime * clipInfos[0].clip.length; + //float playbackTime = layerInfo.playbackRealTimeInSeconds; + ColliderInfo[] infos = animData.GetActiveCollidersInfo(type, playbackTime); + return infos; + } + + // 动作切换,重置collider mask + public void OnAnimationChange() + { + m_HitMask.Clear(); + } + + public void RecordCollision(int colliderHash, int targetHash) + { + List<int> record; + if (!m_HitMask.TryGetValue(colliderHash, out record)) + { + record = new List<int>(); + m_HitMask.Add(colliderHash, record); + } + record.Add(targetHash); + } + + public bool CanCollide(int colliderHash, int targetHash) + { + List<int> record; + if(!m_HitMask.TryGetValue(colliderHash, out record)) + { + return true; + } + return !record.Contains(targetHash); + } + +#if UNITY_EDITOR + + // 绘制collider调试 + public void OnDrawGizmos() + { + if (!showGizmos) + return; + + Vector3 unitPos = m_Owner.transform.position; + + OnDrawColliders(ColliderBox.EColliderType.HurtBox, Color.green); + OnDrawColliders(ColliderBox.EColliderType.HitBox, Color.red); + } + + void OnDrawColliders(ColliderBox.EColliderType type, Color color) + { + ColliderInfo[] boxes = GetCurrentBoxesInfoByType(type); + if (boxes == null || boxes.Length == 0) + return; + Vector3 unitPos = m_Owner.transform.position; + Quaternion right = Quaternion.Euler(0, 0, 0); + Vector3 fac = new Vector3(1,1, m_Owner.transform.forward.normalized == Vector3.forward ? 1 : -1); + Color oldC = Gizmos.color; + Gizmos.color = color * 0.5f; + for (int i = 0; i < boxes.Length; ++i) + { + var box = boxes[i]; + if (!box.isValid) + continue; + Vector3 localPos = box.position; + Vector3 localSize = box.size; + var pivot = box.pivot; + Vector3 pos = Vector3.zero; // gizmo位置 + switch (pivot) + { + case ColliderBox.Pivot.MiddleBottom: + localPos.y += localSize.y / 2; + break; + } + pos = unitPos + Vector3.Scale(localPos, fac); + Gizmos.DrawCube(pos, localSize); + } + Gizmos.color = oldC; + } + +#endif + +} diff --git a/Assets/Scripts/Unit/Component/UnitCollider.cs.meta b/Assets/Scripts/Unit/Components/UnitCollider.cs.meta index fa98ddc9..fa98ddc9 100644 --- a/Assets/Scripts/Unit/Component/UnitCollider.cs.meta +++ b/Assets/Scripts/Unit/Components/UnitCollider.cs.meta diff --git a/Assets/Scripts/Unit/Component/UnitComponent.cs b/Assets/Scripts/Unit/Components/UnitComponent.cs index 1e4df1fc..a5034581 100644 --- a/Assets/Scripts/Unit/Component/UnitComponent.cs +++ b/Assets/Scripts/Unit/Components/UnitComponent.cs @@ -1,42 +1,42 @@ -using System.Collections;
-using System.Collections.Generic;
-using UnityEngine;
-
-public class UnitComponent : MonoBehaviour
-{
- public UnitController owner { get { return m_Owner; } }
-
- protected UnitController m_Owner;
-
- public bool IsAlive
- {
- get
- {
- return m_Owner != null;
- }
- }
-
- public virtual void Awake()
- {
- }
-
- public virtual void OnDestroy()
- {
- }
-
- public virtual void Initialize()
- {
- m_Owner = GetComponent<UnitController>();
- }
-
- public virtual void Release()
- {
- m_Owner = null;
- StopAllCoroutines();
- }
-
- public virtual void OnUpdate() { }
-
- private void Update() { }
-
-}
+using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class UnitComponent : MonoBehaviour +{ + public UnitController owner { get { return m_Owner; } } + + protected UnitController m_Owner; + + public bool IsAlive + { + get + { + return m_Owner != null; + } + } + + public virtual void Awake() + { + } + + public virtual void OnDestroy() + { + } + + public virtual void Initialize() + { + m_Owner = GetComponent<UnitController>(); + } + + public virtual void Release() + { + m_Owner = null; + StopAllCoroutines(); + } + + public virtual void OnUpdate() { } + + private void Update() { } + +} diff --git a/Assets/Scripts/Unit/Component/UnitComponent.cs.meta b/Assets/Scripts/Unit/Components/UnitComponent.cs.meta index 2641a06f..2641a06f 100644 --- a/Assets/Scripts/Unit/Component/UnitComponent.cs.meta +++ b/Assets/Scripts/Unit/Components/UnitComponent.cs.meta diff --git a/Assets/Scripts/Unit/Components/UnitMovement.cs b/Assets/Scripts/Unit/Components/UnitMovement.cs new file mode 100644 index 00000000..8c668c50 --- /dev/null +++ b/Assets/Scripts/Unit/Components/UnitMovement.cs @@ -0,0 +1,18 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class UnitMovement : MonoBehaviour +{ + // Start is called before the first frame update + void Start() + { + + } + + // Update is called once per frame + void Update() + { + + } +} diff --git a/Assets/Scripts/Unit/Components/UnitMovement.cs.meta b/Assets/Scripts/Unit/Components/UnitMovement.cs.meta new file mode 100644 index 00000000..6978a4bd --- /dev/null +++ b/Assets/Scripts/Unit/Components/UnitMovement.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 8a0ce2076d45ed44da0dfc96f277aa36 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Unit/Component/UnitRender.cs b/Assets/Scripts/Unit/Components/UnitRender.cs index 2ba53a7d..c8f6a125 100644 --- a/Assets/Scripts/Unit/Component/UnitRender.cs +++ b/Assets/Scripts/Unit/Components/UnitRender.cs @@ -1,12 +1,12 @@ -using System.Collections;
-using System.Collections.Generic;
-using UnityEngine;
-
-// 控制角色渲染
-[DisallowMultipleComponent]
-public class UnitRender : UnitComponent
-{
-
-
-
-}
+using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +// 控制角色渲染 +[DisallowMultipleComponent] +public class UnitRender : UnitComponent +{ + + + +} diff --git a/Assets/Scripts/Unit/Component/UnitRender.cs.meta b/Assets/Scripts/Unit/Components/UnitRender.cs.meta index 98aaba31..98aaba31 100644 --- a/Assets/Scripts/Unit/Component/UnitRender.cs.meta +++ b/Assets/Scripts/Unit/Components/UnitRender.cs.meta diff --git a/Assets/Scripts/Unit/Component/UnitSkill.cs b/Assets/Scripts/Unit/Components/UnitSkill.cs index 6a6a3a0e..3e1e480d 100644 --- a/Assets/Scripts/Unit/Component/UnitSkill.cs +++ b/Assets/Scripts/Unit/Components/UnitSkill.cs @@ -1,12 +1,12 @@ -using System.Collections;
-using System.Collections.Generic;
-using UnityEngine;
-
-// 技能逻辑
-[DisallowMultipleComponent]
-
-public class UnitSkill : UnitComponent
-{
-
-
-}
+using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +// 技能逻辑 +[DisallowMultipleComponent] + +public class UnitSkill : UnitComponent +{ + + +} diff --git a/Assets/Scripts/Unit/Component/UnitSkill.cs.meta b/Assets/Scripts/Unit/Components/UnitSkill.cs.meta index 882bb398..882bb398 100644 --- a/Assets/Scripts/Unit/Component/UnitSkill.cs.meta +++ b/Assets/Scripts/Unit/Components/UnitSkill.cs.meta diff --git a/Assets/Scripts/Scene.meta b/Assets/Scripts/Unit/Components/UnitState.meta index eb7a8716..7dca0bf1 100644 --- a/Assets/Scripts/Scene.meta +++ b/Assets/Scripts/Unit/Components/UnitState.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: eaee2d0f48cff9b40baf0686a8105600 +guid: b9414a0ec8c909c4ebb11b46a7f0819d folderAsset: yes DefaultImporter: externalObjects: {} diff --git a/Assets/Scripts/Unit/Components/UnitState/DroneState.cs b/Assets/Scripts/Unit/Components/UnitState/DroneState.cs new file mode 100644 index 00000000..28640664 --- /dev/null +++ b/Assets/Scripts/Unit/Components/UnitState/DroneState.cs @@ -0,0 +1,18 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class DroneState : MonoBehaviour +{ + // Start is called before the first frame update + void Start() + { + + } + + // Update is called once per frame + void Update() + { + + } +} diff --git a/Assets/Scripts/Unit/Components/UnitState/DroneState.cs.meta b/Assets/Scripts/Unit/Components/UnitState/DroneState.cs.meta new file mode 100644 index 00000000..ab3a2898 --- /dev/null +++ b/Assets/Scripts/Unit/Components/UnitState/DroneState.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: a6917bf61e4a31945846081533eb02f4 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Unit/Component/MonsterState.cs b/Assets/Scripts/Unit/Components/UnitState/MonsterState.cs index cd2ed8e5..a9ac0afb 100644 --- a/Assets/Scripts/Unit/Component/MonsterState.cs +++ b/Assets/Scripts/Unit/Components/UnitState/MonsterState.cs @@ -1,179 +1,179 @@ -using System;
-using System.Reflection;
-using System.Collections;
-using System.Collections.Generic;
-using UnityEngine;
-
-public class MonsterState : UnitState
-{
- public enum EUnitState
- {
- Nien,
-
- Idle,
-
- Move,
-
- HitLight,
- HitAir,
- HitGround,
- HitFall,
- KnockDown,
- Rise,
-
- Pull,
- Landing,
- }
-
- [SerializeField] private EUnitState m_State;
- public EUnitState CurrentState { get { return m_State; } }
-
- UnitAnimation unitAnimation { get { return m_Owner.unitAnimation; } }
-
- public override void Initialize()
- {
- base.Initialize();
- }
-
- public void ChangeState<T>(EUnitState nextState, T param = default, bool bForce = false)
- {
- if (!IsChange(nextState, bForce))
- return;
-
- LogHelper.Log("Monster UnitState: " + m_State.ToString() + " -> " + nextState.ToString());
-
- StopAllCoroutines();
-
- EUnitState prevState = m_State;
- string methodFunc = "On" + m_State.ToString() + "Exit";
- MethodInfo exitMethod = GetType().GetMethod(methodFunc, BindingFlags.Instance | BindingFlags.NonPublic, null, new Type[] { typeof(EUnitState) }, null);
- if (exitMethod != null)
- {
- exitMethod.Invoke(this, new object[] { nextState });
- }
- else
- {
- LogHelper.LogError("缺少 " + methodFunc);
- }
- m_State = nextState;
-
- StartCoroutine(m_State.ToString(), param);
- }
-
- bool IsChange(EUnitState newState, bool bForce)
- {
- if (newState != m_State || bForce)
- return true;
- return false;
- }
-
- IEnumerator Nein() { yield break; }
- void OnNienExit(EUnitState nextState) { }
-
- public struct IdleParam { }
-
- public struct LandingParam { }
-
- public struct HitLightParam { }
-
- public struct HitAirParam { }
-
- public struct RiseParam { }
-
- #region Idle
-
- IEnumerator Idle(IdleParam param)
- {
- //if (m_Owner.isInAir) // 浮空切换到landing
- //{
- // ChangeState(EUnitState.Landing, new LandingParam());
- //}
- //else // idle
- //{
- m_Owner.SetYPosition(0);
- m_Owner.monsterAnimation.AnimIdle();
- while (true)
- {
- yield return null;
- }
- //}
- }
-
- void OnIdleExit(EUnitState nextState)
- {
- }
- #endregion
-
- #region HitLight
-
- IEnumerator HitLight(HitLightParam param)
- {
- m_Owner.monsterAnimation.AnimHitLight();
- yield return null;
- while (true)
- {
- bool reachEnd = m_Owner.monsterAnimation.layers[0].playbackNomralizedTime == 1;
- if(reachEnd)
- {
- ChangeState(EUnitState.Idle, new IdleParam());
- }
- yield return null;
- }
- }
-
- void OnHitLightExit(EUnitState nextState)
- {
- }
-
- #endregion
-
- #region HitAir
-
- IEnumerator HitAir(HitAirParam param)
- {
- m_Owner.monsterAnimation.AnimHitAir();
- yield return null;
- while (true)
- {
- bool reachEnd = m_Owner.monsterAnimation.layers[0].playbackNomralizedTime == 1;
- if (reachEnd)
- {
- //yield return new WaitForSeconds(1f);
- ChangeState(EUnitState.Rise, new RiseParam());
- }
- yield return null;
- }
- }
-
- void OnHitAirExit(EUnitState nextState)
- {
- }
-
- #endregion
-
- #region Rise
-
- IEnumerator Rise(RiseParam param)
- {
- m_Owner.monsterAnimation.AnimRise();
- yield return null;
- while (true)
- {
- bool reachEnd = m_Owner.monsterAnimation.layers[0].playbackNomralizedTime == 1;
- if (reachEnd)
- {
- ChangeState(EUnitState.Idle, new IdleParam());
- }
- yield return null;
- }
- }
-
- void OnRiseExit(EUnitState nextState)
- {
- }
-
-
- #endregion
-
-
+using System; +using System.Reflection; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class MonsterState : UnitState +{ + public enum EUnitState + { + Nien, + + Idle, + + Move, + + HitLight, + HitAir, + HitGround, + HitFall, + KnockDown, + Rise, + + Pull, + Landing, + } + + [SerializeField] private EUnitState m_State; + public EUnitState CurrentState { get { return m_State; } } + + UnitAnimation unitAnimation { get { return m_Owner.unitAnimation; } } + + public override void Initialize() + { + base.Initialize(); + } + + public void ChangeState<T>(EUnitState nextState, T param = default, bool bForce = false) + { + if (!IsChange(nextState, bForce)) + return; + + LogHelper.Log("Monster UnitState: " + m_State.ToString() + " -> " + nextState.ToString()); + + StopAllCoroutines(); + + EUnitState prevState = m_State; + string methodFunc = "On" + m_State.ToString() + "Exit"; + MethodInfo exitMethod = GetType().GetMethod(methodFunc, BindingFlags.Instance | BindingFlags.NonPublic, null, new Type[] { typeof(EUnitState) }, null); + if (exitMethod != null) + { + exitMethod.Invoke(this, new object[] { nextState }); + } + else + { + LogHelper.LogError("缺少 " + methodFunc); + } + m_State = nextState; + + StartCoroutine(m_State.ToString(), param); + } + + bool IsChange(EUnitState newState, bool bForce) + { + if (newState != m_State || bForce) + return true; + return false; + } + + IEnumerator Nein() { yield break; } + void OnNienExit(EUnitState nextState) { } + + public struct IdleParam { } + + public struct LandingParam { } + + public struct HitLightParam { } + + public struct HitAirParam { } + + public struct RiseParam { } + + #region Idle + + IEnumerator Idle(IdleParam param) + { + //if (m_Owner.isInAir) // 浮空切换到landing + //{ + // ChangeState(EUnitState.Landing, new LandingParam()); + //} + //else // idle + //{ + m_Owner.SetYPosition(0); + m_Owner.monsterAnimation.AnimIdle(); + while (true) + { + yield return null; + } + //} + } + + void OnIdleExit(EUnitState nextState) + { + } + #endregion + + #region HitLight + + IEnumerator HitLight(HitLightParam param) + { + m_Owner.monsterAnimation.AnimHitLight(); + yield return null; + while (true) + { + bool reachEnd = m_Owner.monsterAnimation.layers[0].playbackNormalizedTime == 1; + if(reachEnd) + { + ChangeState(EUnitState.Idle, new IdleParam()); + } + yield return null; + } + } + + void OnHitLightExit(EUnitState nextState) + { + } + + #endregion + + #region HitAir + + IEnumerator HitAir(HitAirParam param) + { + m_Owner.monsterAnimation.AnimHitAir(); + yield return null; + while (true) + { + bool reachEnd = m_Owner.monsterAnimation.layers[0].playbackNormalizedTime == 1; + if (reachEnd) + { + //yield return new WaitForSeconds(1f); + ChangeState(EUnitState.Rise, new RiseParam()); + } + yield return null; + } + } + + void OnHitAirExit(EUnitState nextState) + { + } + + #endregion + + #region Rise + + IEnumerator Rise(RiseParam param) + { + m_Owner.monsterAnimation.AnimRise(); + yield return null; + while (true) + { + bool reachEnd = m_Owner.monsterAnimation.layers[0].playbackNormalizedTime == 1; + if (reachEnd) + { + ChangeState(EUnitState.Idle, new IdleParam()); + } + yield return null; + } + } + + void OnRiseExit(EUnitState nextState) + { + } + + + #endregion + + }
\ No newline at end of file diff --git a/Assets/Scripts/Unit/Component/MonsterState.cs.meta b/Assets/Scripts/Unit/Components/UnitState/MonsterState.cs.meta index 7d60499f..7d60499f 100644 --- a/Assets/Scripts/Unit/Component/MonsterState.cs.meta +++ b/Assets/Scripts/Unit/Components/UnitState/MonsterState.cs.meta diff --git a/Assets/Scripts/Unit/Component/PCState.cs b/Assets/Scripts/Unit/Components/UnitState/PCState.cs index a9252e26..f6eb7045 100644 --- a/Assets/Scripts/Unit/Component/PCState.cs +++ b/Assets/Scripts/Unit/Components/UnitState/PCState.cs @@ -1,460 +1,460 @@ -using System;
-using System.Reflection;
-using System.Collections;
-using System.Collections.Generic;
-using UnityEngine;
-
-// 角色状态机
-[DisallowMultipleComponent]
-public class PCState : UnitState
-{
- public enum EUnitState
- {
- Nien,
-
- Idle,
- Move,
- Spawn,
- Die,
- Dead,
- //
- Attack,
- AirAttack,
- AirDash,
- //
- HitAir,
- HitAirHit,
- Knockdown,
- //
- HitGuard,
- //
- Walk,
- //
- Rise,
- //
- Jump,
- // 转身
- Turn,
- Landing, // 从空中降落
- }
-
- [SerializeField] private EUnitState m_State;
- public EUnitState CurrentState { get { return m_State; } }
-
- public override void Initialize()
- {
- base.Initialize();
- }
-
- PCAnimation pcAnimation { get { return m_Owner.pcAnimation; } }
-
- #region state param
- public struct IdleParam { }
-
- public struct MoveParam
- {
- public bool isRight;
- public string key;
- }
-
- public struct SkillParam
- {
-
- }
-
- public struct AirDashParam
- {
-
- }
-
- public struct JumpParam
- { }
-
- public struct TurnParam
- {
- EUnitState nextState;
- }
-
- public struct LandingParam { }
-
- #endregion
- public void ChangeState<T>(EUnitState nextState, T param = default, bool bForce = false)
- {
- if (!IsChange(nextState, bForce))
- return;
-
- LogHelper.Log("UnitState: " + m_State.ToString() + " -> " + nextState.ToString());
-
- StopAllCoroutines();
-
- EUnitState prevState = m_State;
- string methodFunc = "On" + m_State.ToString() + "Exit";
- MethodInfo exitMethod = GetType().GetMethod(methodFunc, BindingFlags.Instance | BindingFlags.NonPublic, null, new Type[] { typeof(EUnitState) }, null);
- if (exitMethod != null)
- {
- exitMethod.Invoke(this, new object[] { nextState });
- }
- else
- {
- LogHelper.LogError("缺少 " + methodFunc);
- }
- m_State = nextState;
-
- StartCoroutine(m_State.ToString(), param);
- }
-
- bool IsChange(EUnitState newState, bool bForce)
- {
- if (newState != m_State || bForce)
- return true;
- return false;
- }
-
- 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)
- {
- //if (m_Owner.isInAir) // 浮空切换到landing
- //{
- // ChangeState(EUnitState.Landing, new LandingParam());
- //}
- //else // idle
- //{
- m_Owner.SetYPosition(0);
- m_Owner.pcAnimation.AnimIdle();
- while (true)
- {
- if (Input.GetKeyDown("j"))
- {
- ChangeState(EUnitState.Attack, new SkillParam());
- }
- if (Input.GetKeyDown("space"))
- {
- ChangeState(EUnitState.Jump, new JumpParam());
- }
- if (Input.GetKey("d"))
- {
- MoveParam move = new MoveParam();
- move.isRight = true;
- move.key = "d";
- ChangeState(EUnitState.Move, move);
- }
- if (Input.GetKey("a"))
- {
- MoveParam move = new MoveParam();
- move.isRight = false;
- move.key = "a";
- ChangeState(EUnitState.Move, move);
- }
- yield return null;
- }
- //}
- }
-
- void OnIdleExit(EUnitState nextState)
- {
- }
- #endregion
-
- #region Move
- IEnumerator Move(MoveParam param)
- {
- if (m_Owner.isTowardRight && !param.isRight
- || !m_Owner.isTowardRight && param.isRight)
- {
- //m_Owner.pcAnimation.Play(UnitAnimation.EAnimState.Turn);
- //yield return new WaitForActionReachEnd(m_Owner.pcAnimation);
- //if (param.isRight)
- // m_Owner.transform.rotation = Quaternion.Euler(0, 0, 0);
- //else
- // m_Owner.transform.rotation = Quaternion.Euler(0, 180, 0);
- m_Owner.transform.rotation = Quaternion.Euler(0, param.isRight ? 0 : 180, 0);
- }
- //if (Input.GetKey(param.key))
- m_Owner.pcAnimation.AnimMove();
- while (Input.GetKey(param.key))
- {
- yield return null;
- }
- ChangeState(EUnitState.Idle, new IdleParam());
- }
-
- void OnMoveExit(EUnitState nextState)
- {
- m_Owner.pcAnimation.animator.ResetTrigger("ToMove");
- }
-
- #endregion
-
- #region Attack
-
- IEnumerator Attack(SkillParam param)
- {
- const int total = 3;
- int id = 0;
- m_Owner.pcAnimation.AnimAttack(id);
- yield return null;
- while (true)
- {
- bool canCombo = m_Owner.pcAnimation.layers[0].IsToggleOpen(EAnimationToogle.Combo);
- if (canCombo)
- {
- if (Input.GetKeyDown("j"))
- {
- if (Input.GetKey("a"))
- {
- TurnAround(false);
- }
- if (Input.GetKey("d"))
- {
- TurnAround(true);
- }
- ++id;
- m_Owner.pcAnimation.AnimAttack(id);
- yield return null; // 等待animator更新
- yield return new WaitForTransitionDone(m_Owner.pcAnimation);
- }
- }
-
- bool reachEnd = m_Owner.pcAnimation.layers[0].playbackNomralizedTime == 1;
- if (reachEnd)
- {
- ChangeState(EUnitState.Idle, new IdleParam());
- }
-
- yield return null;
- }
- }
-
- void OnAttackExit(EUnitState next)
- {
- }
-
- #endregion
-
- #region AirAttack
-
- IEnumerator AirAttack(SkillParam param)
- {
- int id = 0;
- m_Owner.pcAnimation.AnimAirAttack(id);
- yield return null; // 等待animator更新
- while (true)
- {
- bool canCombo = m_Owner.pcAnimation.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.pcAnimation.AnimAirAttack(id);
- yield return null; // 等待animator更新
- yield return new WaitForTransitionDone(m_Owner.pcAnimation);
- }
- }
-
- bool reachEnd = m_Owner.pcAnimation.layers[0].playbackNomralizedTime == 1;
- if (reachEnd)
- {
- ChangeState(EUnitState.Landing, new LandingParam());
- }
-
- yield return null;
- }
- }
-
- void OnAirAttackExit(EUnitState next)
- {
-
- }
-
- #endregion
-
- #region AirDash
-
- IEnumerator AirDash(AirDashParam param)
- {
- m_Owner.pcAnimation.AnimAirDash();
- yield return null;
- while (true)
- {
- bool reachEnd = m_Owner.pcAnimation.layers[0].playbackNomralizedTime == 1;
- if (reachEnd)
- {
- ChangeState(EUnitState.Landing, new LandingParam());
- }
-
- bool canCombo = m_Owner.pcAnimation.layers[0].IsToggleOpen(EAnimationToogle.Combo);
- if (canCombo)
- {
- if (InputManager.Instance.TryCommand(0.5f, KeyCode.A, KeyCode.A))
- {
- TurnLeft();
- m_Owner.pcAnimation.AnimAirDash();
- }
- if (InputManager.Instance.TryCommand(0.5f, KeyCode.D, KeyCode.D))
- {
- TurnRight();
- m_Owner.pcAnimation.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
-
- IEnumerator Jump(JumpParam param)
- {
- pcAnimation.AnimJump();
- yield return null;
- yield return new WaitForTransitionDone(pcAnimation);
- while (true)
- {
- 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 (pcAnimation.layers[0].playbackNomralizedTime >= 1)
- ChangeState(EUnitState.Idle, new IdleParam());
- bool canAttack = m_Owner.pcAnimation.layers[0].IsToggleOpen(EAnimationToogle.Combo);
- if (Input.GetKeyDown("j") && canAttack)
- {
- ChangeState(EUnitState.AirAttack, new SkillParam());
- }
- yield return null;
- }
- }
-
- void OnJumpExit(EUnitState next)
- {
- }
-
- #endregion
-
- #region Landing
-
- IEnumerator Landing(LandingParam param)
- {
- m_Owner.pcAnimation.AnimLanding();
- yield return null;
- yield return new WaitForTransitionDone(m_Owner.pcAnimation);
- 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);
- 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.pcAnimation.AnimLandingGround();
- }
- if (pos.y <= 0)
- {
- pos.y = 0;
- m_Owner.transform.position = pos;
- ChangeState(EUnitState.Idle, new IdleParam());
- }
-
- 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());
- }
-
- yield return null;
- }
- }
-
- void OnLandingExit(EUnitState next)
- {
- }
-
- #endregion
-
-}
+using System; +using System.Reflection; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +// 角色状态机 +[DisallowMultipleComponent] +public class PCState : UnitState +{ + public enum EUnitState + { + Nien, + + Idle, + Move, + Spawn, + Die, + Dead, + // + Attack, + AirAttack, + AirDash, + // + HitAir, + HitAirHit, + Knockdown, + // + HitGuard, + // + Walk, + // + Rise, + // + Jump, + // 转身 + Turn, + Landing, // 从空中降落 + } + + [SerializeField] private EUnitState m_State; + public EUnitState CurrentState { get { return m_State; } } + + public override void Initialize() + { + base.Initialize(); + } + + PCAnimation pcAnimation { get { return m_Owner.pcAnimation; } } + + #region state param + public struct IdleParam { } + + public struct MoveParam + { + public bool isRight; + public string key; + } + + public struct SkillParam + { + + } + + public struct AirDashParam + { + + } + + public struct JumpParam + { } + + public struct TurnParam + { + EUnitState nextState; + } + + public struct LandingParam { } + + #endregion + public void ChangeState<T>(EUnitState nextState, T param = default, bool bForce = false) + { + if (!IsChange(nextState, bForce)) + return; + + LogHelper.Log("UnitState: " + m_State.ToString() + " -> " + nextState.ToString()); + + StopAllCoroutines(); + + EUnitState prevState = m_State; + string methodFunc = "On" + m_State.ToString() + "Exit"; + MethodInfo exitMethod = GetType().GetMethod(methodFunc, BindingFlags.Instance | BindingFlags.NonPublic, null, new Type[] { typeof(EUnitState) }, null); + if (exitMethod != null) + { + exitMethod.Invoke(this, new object[] { nextState }); + } + else + { + LogHelper.LogError("缺少 " + methodFunc); + } + m_State = nextState; + + StartCoroutine(m_State.ToString(), param); + } + + bool IsChange(EUnitState newState, bool bForce) + { + if (newState != m_State || bForce) + return true; + return false; + } + + 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) + { + //if (m_Owner.isInAir) // 浮空切换到landing + //{ + // ChangeState(EUnitState.Landing, new LandingParam()); + //} + //else // idle + //{ + m_Owner.SetYPosition(0); + m_Owner.pcAnimation.AnimIdle(); + while (true) + { + if (Input.GetKeyDown("j")) + { + ChangeState(EUnitState.Attack, new SkillParam()); + } + if (Input.GetKeyDown("space")) + { + ChangeState(EUnitState.Jump, new JumpParam()); + } + if (Input.GetKey("d")) + { + MoveParam move = new MoveParam(); + move.isRight = true; + move.key = "d"; + ChangeState(EUnitState.Move, move); + } + if (Input.GetKey("a")) + { + MoveParam move = new MoveParam(); + move.isRight = false; + move.key = "a"; + ChangeState(EUnitState.Move, move); + } + yield return null; + } + //} + } + + void OnIdleExit(EUnitState nextState) + { + } + #endregion + + #region Move + IEnumerator Move(MoveParam param) + { + if (m_Owner.isTowardRight && !param.isRight + || !m_Owner.isTowardRight && param.isRight) + { + //m_Owner.pcAnimation.Play(UnitAnimation.EAnimState.Turn); + //yield return new WaitForActionReachEnd(m_Owner.pcAnimation); + //if (param.isRight) + // m_Owner.transform.rotation = Quaternion.Euler(0, 0, 0); + //else + // m_Owner.transform.rotation = Quaternion.Euler(0, 180, 0); + m_Owner.transform.rotation = Quaternion.Euler(0, param.isRight ? 0 : 180, 0); + } + //if (Input.GetKey(param.key)) + m_Owner.pcAnimation.AnimMove(); + while (Input.GetKey(param.key)) + { + yield return null; + } + ChangeState(EUnitState.Idle, new IdleParam()); + } + + void OnMoveExit(EUnitState nextState) + { + m_Owner.pcAnimation.animator.ResetTrigger("ToMove"); + } + + #endregion + + #region Attack + + IEnumerator Attack(SkillParam param) + { + const int total = 3; + int id = 0; + m_Owner.pcAnimation.AnimAttack(id); + yield return null; + while (true) + { + bool canCombo = m_Owner.pcAnimation.layers[0].IsToggleOpen(EAnimationToogle.Combo); + if (canCombo) + { + if (Input.GetKeyDown("j")) + { + if (Input.GetKey("a")) + { + TurnAround(false); + } + if (Input.GetKey("d")) + { + TurnAround(true); + } + ++id; + m_Owner.pcAnimation.AnimAttack(id); + yield return null; // 等待animator更新 + yield return new WaitForTransitionDone(m_Owner.pcAnimation); + } + } + + bool reachEnd = m_Owner.pcAnimation.layers[0].playbackNormalizedTime == 1; + if (reachEnd) + { + ChangeState(EUnitState.Idle, new IdleParam()); + } + + yield return null; + } + } + + void OnAttackExit(EUnitState next) + { + } + + #endregion + + #region AirAttack + + IEnumerator AirAttack(SkillParam param) + { + int id = 0; + m_Owner.pcAnimation.AnimAirAttack(id); + yield return null; // 等待animator更新 + while (true) + { + bool canCombo = m_Owner.pcAnimation.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.pcAnimation.AnimAirAttack(id); + yield return null; // 等待animator更新 + yield return new WaitForTransitionDone(m_Owner.pcAnimation); + } + } + + bool reachEnd = m_Owner.pcAnimation.layers[0].playbackNormalizedTime == 1; + if (reachEnd) + { + ChangeState(EUnitState.Landing, new LandingParam()); + } + + yield return null; + } + } + + void OnAirAttackExit(EUnitState next) + { + + } + + #endregion + + #region AirDash + + IEnumerator AirDash(AirDashParam param) + { + m_Owner.pcAnimation.AnimAirDash(); + yield return null; + while (true) + { + bool reachEnd = m_Owner.pcAnimation.layers[0].playbackNormalizedTime == 1; + if (reachEnd) + { + ChangeState(EUnitState.Landing, new LandingParam()); + } + + bool canCombo = m_Owner.pcAnimation.layers[0].IsToggleOpen(EAnimationToogle.Combo); + if (canCombo) + { + if (InputManager.Instance.TryCommand(0.5f, KeyCode.A, KeyCode.A)) + { + TurnLeft(); + m_Owner.pcAnimation.AnimAirDash(); + } + if (InputManager.Instance.TryCommand(0.5f, KeyCode.D, KeyCode.D)) + { + TurnRight(); + m_Owner.pcAnimation.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 + + IEnumerator Jump(JumpParam param) + { + pcAnimation.AnimJump(); + yield return null; + yield return new WaitForTransitionDone(pcAnimation); + while (true) + { + 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 (pcAnimation.layers[0].playbackNormalizedTime >= 1) + ChangeState(EUnitState.Idle, new IdleParam()); + bool canAttack = m_Owner.pcAnimation.layers[0].IsToggleOpen(EAnimationToogle.Combo); + if (Input.GetKeyDown("j") && canAttack) + { + ChangeState(EUnitState.AirAttack, new SkillParam()); + } + yield return null; + } + } + + void OnJumpExit(EUnitState next) + { + } + + #endregion + + #region Landing + + IEnumerator Landing(LandingParam param) + { + m_Owner.pcAnimation.AnimLanding(); + yield return null; + yield return new WaitForTransitionDone(m_Owner.pcAnimation); + 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); + 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.pcAnimation.AnimLandingGround(); + } + if (pos.y <= 0) + { + pos.y = 0; + m_Owner.transform.position = pos; + ChangeState(EUnitState.Idle, new IdleParam()); + } + + 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()); + } + + yield return null; + } + } + + void OnLandingExit(EUnitState next) + { + } + + #endregion + +}
\ No newline at end of file diff --git a/Assets/Scripts/Unit/Component/PCState.cs.meta b/Assets/Scripts/Unit/Components/UnitState/PCState.cs.meta index 548a0a91..548a0a91 100644 --- a/Assets/Scripts/Unit/Component/PCState.cs.meta +++ b/Assets/Scripts/Unit/Components/UnitState/PCState.cs.meta diff --git a/Assets/Scripts/Unit/Components/UnitState/PropState.cs b/Assets/Scripts/Unit/Components/UnitState/PropState.cs new file mode 100644 index 00000000..86b95e38 --- /dev/null +++ b/Assets/Scripts/Unit/Components/UnitState/PropState.cs @@ -0,0 +1,18 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class PropState : MonoBehaviour +{ + // Start is called before the first frame update + void Start() + { + + } + + // Update is called once per frame + void Update() + { + + } +} diff --git a/Assets/Scripts/Unit/Components/UnitState/PropState.cs.meta b/Assets/Scripts/Unit/Components/UnitState/PropState.cs.meta new file mode 100644 index 00000000..db5dd78f --- /dev/null +++ b/Assets/Scripts/Unit/Components/UnitState/PropState.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 96148351ded87a247bbdf39d56eb592e +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Unit/Components/UnitState/RobotState.cs b/Assets/Scripts/Unit/Components/UnitState/RobotState.cs new file mode 100644 index 00000000..68a11135 --- /dev/null +++ b/Assets/Scripts/Unit/Components/UnitState/RobotState.cs @@ -0,0 +1,18 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class RobotState : MonoBehaviour +{ + // Start is called before the first frame update + void Start() + { + + } + + // Update is called once per frame + void Update() + { + + } +} diff --git a/Assets/Scripts/Unit/Components/UnitState/RobotState.cs.meta b/Assets/Scripts/Unit/Components/UnitState/RobotState.cs.meta new file mode 100644 index 00000000..ef3ef469 --- /dev/null +++ b/Assets/Scripts/Unit/Components/UnitState/RobotState.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 12346a9b76519ab4098b11da90589040 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Unit/Component/UnitState.cs b/Assets/Scripts/Unit/Components/UnitState/UnitState.cs index 2825f606..4896e255 100644 --- a/Assets/Scripts/Unit/Component/UnitState.cs +++ b/Assets/Scripts/Unit/Components/UnitState/UnitState.cs @@ -1,12 +1,12 @@ -using System;
-using System.Reflection;
-using System.Collections;
-using System.Collections.Generic;
-using UnityEngine;
-
-// 角色状态机
-[DisallowMultipleComponent]
-public class UnitState : UnitComponent
-{
-
+using System; +using System.Reflection; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +// 角色状态机 +[DisallowMultipleComponent] +public class UnitState : UnitComponent +{ + }
\ No newline at end of file diff --git a/Assets/Scripts/Unit/Component/UnitState.cs.meta b/Assets/Scripts/Unit/Components/UnitState/UnitState.cs.meta index 781994dc..781994dc 100644 --- a/Assets/Scripts/Unit/Component/UnitState.cs.meta +++ b/Assets/Scripts/Unit/Components/UnitState/UnitState.cs.meta diff --git a/Assets/Scripts/Unit/Controller/PropController.cs b/Assets/Scripts/Unit/Controller/PropController.cs new file mode 100644 index 00000000..6449d49e --- /dev/null +++ b/Assets/Scripts/Unit/Controller/PropController.cs @@ -0,0 +1,18 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class PropController : MonoBehaviour +{ + // Start is called before the first frame update + void Start() + { + + } + + // Update is called once per frame + void Update() + { + + } +} diff --git a/Assets/Scripts/Unit/Controller/PropController.cs.meta b/Assets/Scripts/Unit/Controller/PropController.cs.meta new file mode 100644 index 00000000..e5212ee7 --- /dev/null +++ b/Assets/Scripts/Unit/Controller/PropController.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 67cc84cac8614a646a7e981178ec9939 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Unit/Controller/RobotController.cs b/Assets/Scripts/Unit/Controller/RobotController.cs new file mode 100644 index 00000000..7a10c968 --- /dev/null +++ b/Assets/Scripts/Unit/Controller/RobotController.cs @@ -0,0 +1,18 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class RobotController : MonoBehaviour +{ + // Start is called before the first frame update + void Start() + { + + } + + // Update is called once per frame + void Update() + { + + } +} diff --git a/Assets/Scripts/Unit/Controller/RobotController.cs.meta b/Assets/Scripts/Unit/Controller/RobotController.cs.meta new file mode 100644 index 00000000..d40dd55d --- /dev/null +++ b/Assets/Scripts/Unit/Controller/RobotController.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 4f594c33f502a71408a6d16e21274ca2 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: |