diff options
Diffstat (limited to 'Erika/Assets/Scripts/Unit/Components/UnitPhysicsBoxCollection.cs')
-rw-r--r-- | Erika/Assets/Scripts/Unit/Components/UnitPhysicsBoxCollection.cs | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/Erika/Assets/Scripts/Unit/Components/UnitPhysicsBoxCollection.cs b/Erika/Assets/Scripts/Unit/Components/UnitPhysicsBoxCollection.cs new file mode 100644 index 00000000..ef4676a4 --- /dev/null +++ b/Erika/Assets/Scripts/Unit/Components/UnitPhysicsBoxCollection.cs @@ -0,0 +1,85 @@ +using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+
+public class UnitPhysicsBoxCollection : UnitComponent
+{
+ // 列表里不一定按顺序存储
+
+ [SerializeField] private List<UnitHurtBox> m_HurtBoxes;
+ [SerializeField] private List<UnitGuardBox> m_GuardBoxes;
+ [SerializeField] private List<UnitTriggerBox> m_TriggerBoxes;
+
+ private IEnumerable AllPhysicsBoxes()
+ {
+ yield return m_HurtBoxes;
+ yield return m_GuardBoxes;
+ yield return m_TriggerBoxes;
+ }
+
+ private IEnumerable GetBoxListByType(EPhysicsBoxType type)
+ {
+ switch (type)
+ {
+ case EPhysicsBoxType.None:
+ return null;
+ case EPhysicsBoxType.HurtBox:
+ return m_HurtBoxes;
+ case EPhysicsBoxType.GuardBox:
+ return m_GuardBoxes;
+ case EPhysicsBoxType.TriggerBox:
+ return m_TriggerBoxes;
+ default:
+ break;
+ }
+ return null;
+ }
+
+ public UnitPhysicsBox GetBoxByUName(string uName)
+ {
+ foreach(var it in AllPhysicsBoxes())
+ {
+ var box = it as UnitPhysicsBox;
+ if (box == null)
+ continue;
+
+ if (box.uName == uName)
+ return box;
+ }
+ return null;
+ }
+
+ /// <summary>
+ /// 根据类型+ID返回对应的physics box
+ /// </summary>
+ /// <param name="type"></param>
+ /// <param name="id"></param>
+ /// <returns></returns>
+ public UnitPhysicsBox GetBoxByTypeAndID(EPhysicsBoxType type, int id)
+ {
+ IEnumerable list = GetBoxListByType(type);
+ if (list == null)
+ return null;
+
+ foreach(var it in list)
+ {
+ var box = it as UnitPhysicsBox;
+ if (box == null)
+ continue;
+ if (box.ID == id)
+ return box;
+ }
+
+ return null;
+ }
+
+ #region 碰撞回调
+
+ public void OnCollisionHappends(EPhysicsBoxType type, int id)
+ {
+
+ }
+
+ #endregion
+
+}
\ No newline at end of file |