73 lines
2.1 KiB
C#
73 lines
2.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using Code.OfficeGame.BattleMode.Timeline;
|
|
using UnityEngine;
|
|
|
|
namespace Code.OfficeGame.BattleMode.HitBoxes
|
|
{
|
|
// TODO Добавить меотды отключения,чтобы не получать урон во время стаггера
|
|
public class EntityHitBoxes : MonoBehaviour
|
|
{
|
|
[SerializeField] private Dictionary<HitBoxPartType, BoxCollider> bodyParts;
|
|
private LayerMask _hitBoxLayerMask;
|
|
|
|
private readonly Collider[] _hitResults = new Collider[8];
|
|
|
|
private void Awake()
|
|
{
|
|
foreach (var part in bodyParts.Values)
|
|
{
|
|
part.enabled = false;
|
|
}
|
|
_hitBoxLayerMask = LayerMask.GetMask("HitBox");
|
|
}
|
|
|
|
public void CheckHitsForCurrentFrame(Action<Collider> onNewTargetHit, HitBoxPartType hitBoxPartType)
|
|
{
|
|
BoxCollider box = bodyParts[hitBoxPartType];
|
|
Transform boxTransform = box.transform;
|
|
|
|
HitboxDrawer.DrawBox(box, Color.red, BattleTimeline.TickDelta);
|
|
|
|
Vector3 worldCenter = boxTransform.TransformPoint(box.center);
|
|
Vector3 worldHalfExtents = Vector3.Scale(box.size * 0.5f, boxTransform.lossyScale);
|
|
|
|
int hitsCount = Physics.OverlapBoxNonAlloc(
|
|
worldCenter,
|
|
worldHalfExtents,
|
|
_hitResults,
|
|
boxTransform.rotation,
|
|
_hitBoxLayerMask,
|
|
QueryTriggerInteraction.Collide);
|
|
|
|
for (int i = 0; i < hitsCount; i++)
|
|
{
|
|
Collider hitCol = _hitResults[i];
|
|
|
|
Debug.Log($"Попадание по {hitCol.name}");
|
|
|
|
if (hitCol.transform.root == transform.root) continue;
|
|
|
|
onNewTargetHit?.Invoke(hitCol);
|
|
}
|
|
}
|
|
}
|
|
|
|
public enum HitBoxPartType
|
|
{
|
|
Head,
|
|
Chest,
|
|
LArm,
|
|
LElbow,
|
|
LWrist,
|
|
LLeg,
|
|
LKnee,
|
|
LAnkle,
|
|
RArm,
|
|
RElbow,
|
|
RWrist,
|
|
RLeg,
|
|
RKnee,
|
|
RAnkle
|
|
}
|
|
} |