diff options
author | chai <chaifix@163.com> | 2022-03-10 14:07:40 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2022-03-10 14:07:40 +0800 |
commit | 22891bf59032ba88262824255a706d652031384b (patch) | |
tree | 7595439ba9966c9402d37e37cee5e8cf098757d5 /Assets/Scripts/Managers/HitManager.cs | |
parent | 8b04ea73e540067f83870b61d89db4868fea5e8a (diff) |
* move folder
Diffstat (limited to 'Assets/Scripts/Managers/HitManager.cs')
-rw-r--r-- | Assets/Scripts/Managers/HitManager.cs | 134 |
1 files changed, 0 insertions, 134 deletions
diff --git a/Assets/Scripts/Managers/HitManager.cs b/Assets/Scripts/Managers/HitManager.cs deleted file mode 100644 index d16a462c..00000000 --- a/Assets/Scripts/Managers/HitManager.cs +++ /dev/null @@ -1,134 +0,0 @@ -using System.Collections;
-using System.Collections.Generic;
-using UnityEngine;
-
-public struct HitInfo
-{
- public HitDefination hitDef;
- public Hitbox hitbox;
- public Hurtbox hurtbox;
- public Vector3 contact;
- public Vector3 size;
-}
-
-public struct HurtInfo
-{
- public HitDefination hitDef;
- public Hitbox hitbox;
- public Hurtbox hurtbox;
- public Vector3 contact;
- public Vector3 size;
-}
-
-public class HitManager : Singleton<HitManager>
-{
- private List<Hitbox> m_HitBoxes = new List<Hitbox>();
- private List<Hurtbox> m_HurtBoxes = new List<Hurtbox>();
-
- public void AddHitBox(Hitbox hitbox)
- {
- m_HitBoxes.Add(hitbox);
- }
-
- public void AddHurtBox(Hurtbox hurtbox)
- {
- m_HurtBoxes.Add(hurtbox);
- }
-
- public void RemoveHitBox(Hitbox hitbox)
- {
- m_HitBoxes.Remove(hitbox);
- }
-
- public void RemoveHurtBox(Hurtbox hurtbox)
- {
- m_HurtBoxes.Remove(hurtbox);
- }
-
- /// <summary>
- /// 根据碰撞结果产生击中信息
- /// </summary>
- public void OnPhysicsUpdate()
- {
- for(int i = 0;i < m_HitBoxes.Count; ++i)
- {
- Hitbox hitbox = m_HitBoxes[i];
- if (hitbox == null)
- return;
- for (int j = 0; j < PhysicsWorld.Instance.Collisions.Count; ++j)
- {
- PhysicsCollisionInfo info = PhysicsWorld.Instance.Collisions[j];
- PhysicsPrimitive collider;
- if(info.prim1 == hitbox.Collider)
- {
- collider = info.prim2;
- }
- else if(info.prim2 == hitbox.Collider)
- {
- collider = info.prim1;
- }
- else
- {
- continue;
- }
-
- Hurtbox hurtbox = GetHurtboxByCollider(collider);
- if(hurtbox == null)
- {
- Debug.LogError("没有找到hurtbox");
- continue;
- }
-
- HitDefination hitDef = null;
-
- if (hitbox.Host is Avatar)
- {
- Avatar attacker = hitbox.Host as Avatar;
- Hit hit = attacker.GetHit();
- if(hit == null)
- continue;
- if (hit.HasRecord(hurtbox.Host))
- continue;
- hit.AddRecord(hurtbox.Host);
- hitDef = hit.defination;
- }
-
- // 发送击中消息
- HitInfo hitInfo = new HitInfo ();
- hitInfo.hitbox = hitbox;
- hitInfo.hurtbox = hurtbox;
- hitInfo.contact = info.contact;
- hitInfo.size = info.size;
- hitInfo.hitDef = hitDef;
-
- hitbox.Host.OnHit(hitInfo);
-
- // 发送受击消息
- HurtInfo hurtInfo = new HurtInfo();
- hurtInfo.hitbox = hitbox;
- hurtInfo.hurtbox = hurtbox;
- hurtInfo.contact = info.contact;
- hurtInfo.size = info.size;
- hurtInfo.hitDef = hitDef;
-
- hurtbox.Host.OnHurt(hurtInfo);
-
- // 场景处理特效等
- BattleManager.Instance.OnHitOccur();
- }
- }
- }
-
- Hurtbox GetHurtboxByCollider(PhysicsPrimitive collider)
- {
- foreach(var hurtbox in m_HurtBoxes)
- {
- if(hurtbox.Collider == collider)
- {
- return hurtbox;
- }
- }
- return null;
- }
-
-}
|