iFactory.Cutting.Unity/Assets/BITKit/Unity/Scripts/Entity/Components/Hitbox/EntityHitbox.cs

58 lines
1.4 KiB
C#
Raw Normal View History

2024-01-23 02:56:26 +08:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using BITKit;
namespace BITKit.Entities
{
2024-04-16 04:15:06 +08:00
public class EntityHitbox : MonoBehaviour,IDamagable
2024-01-23 02:56:26 +08:00
{
2024-04-16 04:15:06 +08:00
public string Tag => tag is null ? base.tag : tag.Value;
public IHealth Health
{
get
{
EnsureConfigure();
return _health;
}
}
public IUnityEntity UnityEntity
{
get
{
EnsureConfigure();
return _unityEntity;
}
}
public Rigidbody Rigidbody
{
get=>m_rigidbody;
set=>m_rigidbody=value;
}
2024-01-23 02:56:26 +08:00
public void GiveDamage(DamageMessage message)
{
2024-04-16 04:15:06 +08:00
if (_unityEntity is not null)
UnityEntity.Invoke(message);
2024-01-23 02:56:26 +08:00
}
2024-04-16 04:15:06 +08:00
2024-01-23 02:56:26 +08:00
[SerializeField]private Rigidbody m_rigidbody;
2024-04-16 04:15:06 +08:00
[SerializeReference, SubclassSelector] private new IReference tag;
2024-01-23 02:56:26 +08:00
2024-04-16 04:15:06 +08:00
[Inject(true)]
2024-01-23 02:56:26 +08:00
private IHealth _health;
2024-04-16 04:15:06 +08:00
private IUnityEntity _unityEntity;
private bool _initialized;
private void EnsureConfigure()
{
if (_initialized) return;
_unityEntity = GetComponentInParent<IUnityEntity>(true);
_unityEntity?.Inject(this);
_initialized = true;
}
2024-01-23 02:56:26 +08:00
}
}