add kcp
This commit is contained in:
@@ -37,8 +37,18 @@ namespace BITKit.Entities
|
||||
|
||||
public interface IHealth
|
||||
{
|
||||
/// <summary>
|
||||
/// 当设置HP时的回调
|
||||
/// </summary>
|
||||
public event Action<int> OnSetHealthPoint;
|
||||
/// <summary>
|
||||
/// 当设置生存状态时的回调
|
||||
/// </summary>
|
||||
public event Action<bool> OnSetAlive;
|
||||
/// <summary>
|
||||
/// 当受到伤害时的回调
|
||||
/// </summary>
|
||||
public event Func<DamageMessage,int,int> OnDamage;
|
||||
int HealthPoint { get; set; }
|
||||
int MaxHealthPoint { get; set; }
|
||||
bool IsAlive { get; }
|
||||
@@ -50,14 +60,13 @@ namespace BITKit.Entities
|
||||
[SerializeField] private int healthPoint = 100;
|
||||
[SerializeField] private int maxHealthPoint = 100;
|
||||
|
||||
[Header(Constant.Header.Events)]
|
||||
[SerializeField] private UnityEvent<bool> onSetAlive = new();
|
||||
|
||||
[Header(Constant.Header.Providers)] [SerializeField, SerializeReference, SubclassSelector]
|
||||
[Obsolete]
|
||||
private IHealthCallback[] additiveCallback;
|
||||
|
||||
public event Action<int> OnSetHealthPoint;
|
||||
public event Action<bool> OnSetAlive;
|
||||
public event Func<DamageMessage,int, int> OnDamage;
|
||||
|
||||
public int HealthPoint
|
||||
{
|
||||
@@ -72,7 +81,7 @@ namespace BITKit.Entities
|
||||
public bool IsAlive { get; private set; }
|
||||
public override void OnAwake()
|
||||
{
|
||||
entity.AddListener<DamageMessage>(OnDamage);
|
||||
entity.AddListener<DamageMessage>(OnGetDamage);
|
||||
}
|
||||
|
||||
public override void OnStart()
|
||||
@@ -95,11 +104,6 @@ namespace BITKit.Entities
|
||||
x.OnSetHP(newHP);
|
||||
}
|
||||
|
||||
foreach (var x in additiveCallback)
|
||||
{
|
||||
x.OnSetHP(newHP);
|
||||
}
|
||||
|
||||
OnSetHealthPoint?.Invoke(newHP);
|
||||
}
|
||||
|
||||
@@ -110,12 +114,11 @@ namespace BITKit.Entities
|
||||
{
|
||||
x.OnSetAlive(alive);
|
||||
}
|
||||
foreach (var x in additiveCallback)
|
||||
{
|
||||
x.OnSetAlive(alive);
|
||||
}
|
||||
// foreach (var x in additiveCallback)
|
||||
// {
|
||||
// x.OnSetAlive(alive);
|
||||
// }
|
||||
OnSetAlive?.Invoke(alive);
|
||||
onSetAlive.Invoke(alive);
|
||||
}
|
||||
|
||||
private void AddHP(int hp)
|
||||
@@ -123,10 +126,15 @@ namespace BITKit.Entities
|
||||
OnHealthPointChangedInternal(healthPoint, healthPoint += hp);
|
||||
}
|
||||
|
||||
private void OnDamage(DamageMessage damageMessage)
|
||||
private void OnGetDamage(DamageMessage damageMessage)
|
||||
{
|
||||
if (damageMessage.target == entity)
|
||||
AddHP(-damageMessage.damage);
|
||||
if (damageMessage.target != entity) return;
|
||||
var damage = damageMessage.damage;
|
||||
foreach (var x in OnDamage.CastAsFunc())
|
||||
{
|
||||
damage = x.Invoke(damageMessage,damage);
|
||||
}
|
||||
AddHP(-damage);
|
||||
}
|
||||
#if UNITY_EDITOR
|
||||
[BIT]
|
||||
|
Reference in New Issue
Block a user