HealthReworkFuckMojMozg
This commit is contained in:
1 parent
98e4a055fe
commit
72070901ec
8 files changed
+65
-27
No files matched your search
@@ -1,4 +1,3 @@
|
||||
using System;
|
||||
using Code.Infrastructure.Configs;
|
||||
using UnityEngine;
|
||||
|
||||
@@ -49,5 +48,8 @@ namespace Code.Example.Platformer.Entity
|
||||
}
|
||||
|
||||
protected abstract void Move();
|
||||
|
||||
public virtual void OnGetDamage(){}
|
||||
public virtual void OnDeath(){}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using Unity.Collections;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Code.Example.Platformer.Entity
|
||||
{
|
||||
public class EntityGUID : MonoBehaviour
|
||||
{
|
||||
[SerializeField, ReadOnly] private string _id = GenerateId();
|
||||
|
||||
public string Id => _id;
|
||||
|
||||
[ContextMenu("Reset Id")]
|
||||
private void ResetId()
|
||||
{
|
||||
_id = GenerateId();
|
||||
}
|
||||
|
||||
private static string GenerateId()
|
||||
{
|
||||
return Guid.NewGuid().ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 597458061f454fbc9767838561ac16b6
|
||||
timeCreated: 1773761214
|
||||
@@ -1,3 +1,5 @@
|
||||
using Code.Infrastructure.EventBus;
|
||||
using Reflex.Attributes;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Code.Example.Platformer.Entity
|
||||
@@ -9,11 +11,16 @@ namespace Code.Example.Platformer.Entity
|
||||
public void SetMaxHealth(int maxHealth) => _maxHealth = maxHealth;
|
||||
public bool IsDead { get; private set; }
|
||||
|
||||
[Inject] private EventBus _eventBus;
|
||||
[SerializeField] private Entity entity;
|
||||
|
||||
public void GiveDamage(int damage)
|
||||
{
|
||||
_health -= damage;
|
||||
|
||||
if(_health <= 0) IsDead = true;
|
||||
|
||||
_eventBus.RaiseEvent<IEntityDamagedHandler>(x=> x.EntityDamaged(gameObject, damage, IsDead));
|
||||
}
|
||||
|
||||
public void Heal(int heal)
|
||||
@@ -21,6 +28,17 @@ namespace Code.Example.Platformer.Entity
|
||||
if (IsDead) return;
|
||||
if (_health + heal > _maxHealth) _health = _maxHealth;
|
||||
else _health += heal;
|
||||
|
||||
_eventBus.RaiseEvent<IEntityHealedHandler>(x=> x.EntityHealed(gameObject, heal));
|
||||
}
|
||||
}
|
||||
|
||||
public interface IEntityDamagedHandler : IGlobalSubscriber
|
||||
{
|
||||
void EntityDamaged(GameObject entity, int damageCount, bool isDied);
|
||||
}
|
||||
public interface IEntityHealedHandler : IGlobalSubscriber
|
||||
{
|
||||
void EntityHealed(GameObject entity, int healCount);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user