From 01f06fb513dab303abeb02d7e1007e397874bcc0 Mon Sep 17 00:00:00 2001 From: chai Date: Mon, 16 Nov 2020 21:08:39 +0800 Subject: *misc --- Assets/Scripts/Avatar/Avatar.cs | 2 + Assets/Scripts/Avatar/Avatar_Hurt.cs | 9 +++ Assets/Scripts/Avatar/HitDefination.cs | 13 +++- Assets/Scripts/Avatar/StateController.cs | 106 ++++++++++++++++++++++++++ Assets/Scripts/Avatar/StateController.cs.meta | 11 +++ Assets/Scripts/Avatar/StateSystem.cs | 106 -------------------------- Assets/Scripts/Avatar/StateSystem.cs.meta | 11 --- 7 files changed, 139 insertions(+), 119 deletions(-) create mode 100644 Assets/Scripts/Avatar/StateController.cs create mode 100644 Assets/Scripts/Avatar/StateController.cs.meta delete mode 100644 Assets/Scripts/Avatar/StateSystem.cs delete mode 100644 Assets/Scripts/Avatar/StateSystem.cs.meta (limited to 'Assets/Scripts/Avatar') diff --git a/Assets/Scripts/Avatar/Avatar.cs b/Assets/Scripts/Avatar/Avatar.cs index 0ee7555f..8787b942 100644 --- a/Assets/Scripts/Avatar/Avatar.cs +++ b/Assets/Scripts/Avatar/Avatar.cs @@ -16,6 +16,8 @@ public partial class Avatar : MonoBehaviour, IInteractable public Hitbox[] m_Hitbox; public Hurtbox[] m_Hurtbox; + public Transform m_Hips; + protected StateController m_StateController = new StateController(); // 预定义的state,角色必须定义的 diff --git a/Assets/Scripts/Avatar/Avatar_Hurt.cs b/Assets/Scripts/Avatar/Avatar_Hurt.cs index eebc9a78..c6b840b9 100644 --- a/Assets/Scripts/Avatar/Avatar_Hurt.cs +++ b/Assets/Scripts/Avatar/Avatar_Hurt.cs @@ -24,6 +24,15 @@ public partial class Avatar : MonoBehaviour, IInteractable break; } + // spark + if(hit.sparkName != string.Empty) + { + if(hit.sparkHostType == HitSparkHost.Center) + { + SparksManager.Instance.PlaySpark(hit.sparkName, m_Hips); + } + } + } } diff --git a/Assets/Scripts/Avatar/HitDefination.cs b/Assets/Scripts/Avatar/HitDefination.cs index db07a677..d5d68b23 100644 --- a/Assets/Scripts/Avatar/HitDefination.cs +++ b/Assets/Scripts/Avatar/HitDefination.cs @@ -14,6 +14,14 @@ public enum HitType Air, // 击飞 } +public enum HitSparkHost +{ + Center, // 受击者质心 + Hitpoint, // 重叠盒子中心 + Fixed, // 固定挂点sparkHost + WorldPosition, // 世界空间位置sparkRotation +} + /// /// 一个hit的定义,如果一个attack有多个hit,需要定义多个HitDef /// @@ -27,8 +35,9 @@ public class HitDefination // 特效 public string sparkName = string.Empty; // 特效 - public Transform sparkHost = null; // 特效挂点 - public Vector3 sparkPosition; // 特效位置(sparkHost为空时生效) + public HitSparkHost sparkHostType = HitSparkHost.Center; + public Transform sparkHost = null; // 特效挂点 + public Vector3 sparkPosition; // 特效位置 public Quaternion sparkRotation; // 特效旋转 public Vector3 sparkScale = Vector3.one; // 特效缩放 diff --git a/Assets/Scripts/Avatar/StateController.cs b/Assets/Scripts/Avatar/StateController.cs new file mode 100644 index 00000000..12ba6fe4 --- /dev/null +++ b/Assets/Scripts/Avatar/StateController.cs @@ -0,0 +1,106 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +/// +/// 每个角色拥有一个state system +/// +public class StateController +{ + /// + /// 当前执行的state + /// + private StateBase m_Currrent; + + public StateBase Current + { + get + { + return m_Currrent; + } + } + + private List m_States = new List(); + + private UberState m_UberState; + + public StateController() + { + } + + public void ForceStart(StateBase state) + { + if (state == null) + return; + + if (m_Currrent != null) + m_Currrent.OnExit(); + + m_Currrent = state; + m_Currrent.OnEnter(); + } + + public void SetUberState(UberState state) + { + m_UberState = state; + } + + public void AddState(StateBase state) + { + m_States.Add(state); + } + + public void OnUpdate() + { + if(m_Currrent != null) + { + m_Currrent.OnUpdate(); + } + if(m_UberState != null) + { + m_UberState.OnUpdate(); + } + } + + public void OnPhysicsUpdate() + { + if(m_Currrent != null) + { + m_Currrent.OnPhysicsUpdate(); + } + if(m_UberState != null) + { + m_UberState.OnPhysicsUpdate(); + } + } + + public void OnHit(HitInfo info) + { + if (m_Currrent != null) + m_Currrent.OnHit(info); + } + + public void OnHurt(HurtInfo info) + { + if (m_Currrent != null) + m_Currrent.OnHurt(info); + } + + public void SwitchToState(StateBase targetState) + { + if (m_Currrent != null) + m_Currrent.OnExit(); + m_Currrent = targetState; + m_Currrent.OnEnter(); + } + + // 获得当前击打如果有的话 + public Hit GetHit() + { + if (Current == null || !(Current is AttackState)) + return null; + AttackState state = Current as AttackState; + return state.GetHit(); + } + +} \ No newline at end of file diff --git a/Assets/Scripts/Avatar/StateController.cs.meta b/Assets/Scripts/Avatar/StateController.cs.meta new file mode 100644 index 00000000..8974eb37 --- /dev/null +++ b/Assets/Scripts/Avatar/StateController.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 4dec6f0208c6e564980e1380ad151233 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Avatar/StateSystem.cs b/Assets/Scripts/Avatar/StateSystem.cs deleted file mode 100644 index 12ba6fe4..00000000 --- a/Assets/Scripts/Avatar/StateSystem.cs +++ /dev/null @@ -1,106 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; - -/// -/// 每个角色拥有一个state system -/// -public class StateController -{ - /// - /// 当前执行的state - /// - private StateBase m_Currrent; - - public StateBase Current - { - get - { - return m_Currrent; - } - } - - private List m_States = new List(); - - private UberState m_UberState; - - public StateController() - { - } - - public void ForceStart(StateBase state) - { - if (state == null) - return; - - if (m_Currrent != null) - m_Currrent.OnExit(); - - m_Currrent = state; - m_Currrent.OnEnter(); - } - - public void SetUberState(UberState state) - { - m_UberState = state; - } - - public void AddState(StateBase state) - { - m_States.Add(state); - } - - public void OnUpdate() - { - if(m_Currrent != null) - { - m_Currrent.OnUpdate(); - } - if(m_UberState != null) - { - m_UberState.OnUpdate(); - } - } - - public void OnPhysicsUpdate() - { - if(m_Currrent != null) - { - m_Currrent.OnPhysicsUpdate(); - } - if(m_UberState != null) - { - m_UberState.OnPhysicsUpdate(); - } - } - - public void OnHit(HitInfo info) - { - if (m_Currrent != null) - m_Currrent.OnHit(info); - } - - public void OnHurt(HurtInfo info) - { - if (m_Currrent != null) - m_Currrent.OnHurt(info); - } - - public void SwitchToState(StateBase targetState) - { - if (m_Currrent != null) - m_Currrent.OnExit(); - m_Currrent = targetState; - m_Currrent.OnEnter(); - } - - // 获得当前击打如果有的话 - public Hit GetHit() - { - if (Current == null || !(Current is AttackState)) - return null; - AttackState state = Current as AttackState; - return state.GetHit(); - } - -} \ No newline at end of file diff --git a/Assets/Scripts/Avatar/StateSystem.cs.meta b/Assets/Scripts/Avatar/StateSystem.cs.meta deleted file mode 100644 index 52e8267c..00000000 --- a/Assets/Scripts/Avatar/StateSystem.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 2cf426be55a8b8b48a1b794fa6938e94 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: -- cgit v1.1-26-g67d0