diff options
Diffstat (limited to 'Assets/Scripts/Unit')
-rw-r--r-- | Assets/Scripts/Unit/Component/UnitCollider.cs | 31 | ||||
-rw-r--r-- | Assets/Scripts/Unit/Component/UnitComponent.cs | 10 | ||||
-rw-r--r-- | Assets/Scripts/Unit/Controller/UnitController.cs | 23 |
3 files changed, 63 insertions, 1 deletions
diff --git a/Assets/Scripts/Unit/Component/UnitCollider.cs b/Assets/Scripts/Unit/Component/UnitCollider.cs index 2630cb91..57585ba2 100644 --- a/Assets/Scripts/Unit/Component/UnitCollider.cs +++ b/Assets/Scripts/Unit/Component/UnitCollider.cs @@ -2,12 +2,43 @@ using System.Collections.Generic;
using UnityEngine;
+public class ColliderRegistry : Singleton<ColliderRegistry>
+{
+ public List<UnitCollider> colliders = new List<UnitCollider>();
+
+ public void AddCollider(UnitCollider collider)
+ {
+ if (!colliders.Contains(collider))
+ colliders.Add(collider);
+ }
+
+ public void RemoveCollider(UnitCollider collider)
+ {
+ if (colliders.Contains(collider))
+ colliders.Remove(collider);
+ }
+}
+
// 角色当前的碰撞盒
[DisallowMultipleComponent]
public class UnitCollider : UnitComponent
{
public bool showGizmos;
+ 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();
diff --git a/Assets/Scripts/Unit/Component/UnitComponent.cs b/Assets/Scripts/Unit/Component/UnitComponent.cs index 6c8dc916..1e4df1fc 100644 --- a/Assets/Scripts/Unit/Component/UnitComponent.cs +++ b/Assets/Scripts/Unit/Component/UnitComponent.cs @@ -4,6 +4,8 @@ using UnityEngine; public class UnitComponent : MonoBehaviour
{
+ public UnitController owner { get { return m_Owner; } }
+
protected UnitController m_Owner;
public bool IsAlive
@@ -14,6 +16,14 @@ public class UnitComponent : MonoBehaviour }
}
+ public virtual void Awake()
+ {
+ }
+
+ public virtual void OnDestroy()
+ {
+ }
+
public virtual void Initialize()
{
m_Owner = GetComponent<UnitController>();
diff --git a/Assets/Scripts/Unit/Controller/UnitController.cs b/Assets/Scripts/Unit/Controller/UnitController.cs index b1e708bb..4169ca6a 100644 --- a/Assets/Scripts/Unit/Controller/UnitController.cs +++ b/Assets/Scripts/Unit/Controller/UnitController.cs @@ -2,7 +2,14 @@ using System.Collections.Generic;
using UnityEngine;
-public class UnitController : MonoBehaviour
+public interface Interactable
+{
+ void OnHit();
+ void OnHurt();
+ void OnGrab();
+}
+
+public class UnitController : MonoBehaviour, Interactable
{
// 角色共有的组件
@@ -88,4 +95,18 @@ public class UnitController : MonoBehaviour unitRootMotion.OnUpdate();
}
+ public void OnHit()
+ {
+ throw new System.NotImplementedException();
+ }
+
+ public void OnHurt()
+ {
+ throw new System.NotImplementedException();
+ }
+
+ public void OnGrab()
+ {
+ throw new System.NotImplementedException();
+ }
}
|