From 22891bf59032ba88262824255a706d652031384b Mon Sep 17 00:00:00 2001 From: chai Date: Thu, 10 Mar 2022 14:07:40 +0800 Subject: * move folder --- Assets/Scripts/Managers/HitManager.cs | 134 ---------------------------------- 1 file changed, 134 deletions(-) delete mode 100644 Assets/Scripts/Managers/HitManager.cs (limited to 'Assets/Scripts/Managers/HitManager.cs') 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 -{ - private List m_HitBoxes = new List(); - private List m_HurtBoxes = new List(); - - 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); - } - - /// - /// 根据碰撞结果产生击中信息 - /// - 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; - } - -} -- cgit v1.1-26-g67d0