BITKit/Src/Unity/Scripts/Entity/Components/Hitbox/EntityHitbox.cs

58 lines
1.4 KiB
C#
Raw Normal View History

2023-06-05 19:57:17 +08:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using BITKit;
namespace BITKit.Entities
{
2024-03-31 23:31:00 +08:00
public class EntityHitbox : MonoBehaviour,IDamagable
2023-06-05 19:57:17 +08:00
{
2024-04-06 16:33:32 +08:00
public string Tag => tag is null ? base.tag : tag.Value;
2024-03-31 23:31:00 +08:00
public IHealth Health
{
get
{
EnsureConfigure();
return _health;
}
}
public IUnityEntity UnityEntity
{
get
{
EnsureConfigure();
return _unityEntity;
}
}
public Rigidbody Rigidbody
{
get=>m_rigidbody;
set=>m_rigidbody=value;
}
2023-07-17 10:23:47 +08:00
public void GiveDamage(DamageMessage message)
{
2024-03-31 23:31:00 +08:00
if (_unityEntity is not null)
UnityEntity.Invoke(message);
2023-07-17 10:23:47 +08:00
}
2024-03-31 23:31:00 +08:00
2023-10-24 23:38:22 +08:00
[SerializeField]private Rigidbody m_rigidbody;
2024-04-06 16:33:32 +08:00
[SerializeReference, SubclassSelector] private new IReference tag;
2024-03-31 23:31:00 +08:00
[Inject(true)]
private IHealth _health;
private IUnityEntity _unityEntity;
private bool _initialized;
private void EnsureConfigure()
{
if (_initialized) return;
_unityEntity = GetComponentInParent<IUnityEntity>(true);
_unityEntity?.Inject(this);
_initialized = true;
}
2023-06-05 19:57:17 +08:00
}
}