using UnityEngine; namespace Invector { [System.Serializable] public class OnDead : UnityEngine.Events.UnityEvent { } public interface vIHealthController : vIDamageReceiver { /// /// Event called when is zero or less /// OnDead onDead { get; } /// /// Current Health value /// float currentHealth { get; } /// /// Max Health value /// int MaxHealth { get; } /// /// Check if is zero or less /// bool isDead { get; set; } /// /// Encrease or Decrease respecting the /// /// value void AddHealth(int value); /// /// Change respecting the /// /// value void ChangeHealth(int value); /// /// Change the Max Health value /// /// value void ChangeMaxHealth(int value); /// /// Reset's current health to specific health value /// /// target health void ResetHealth(float health); /// /// Reset's current health to max health /// void ResetHealth(); } public static class vHealthControllerHelper { static vIHealthController GetHealthController(this GameObject gameObject) { return gameObject.GetComponent(); } /// /// Encrease or Decrease respecting the /// /// Target to GetComponent /// public static void AddHealth(this GameObject receiver, int health) { var healthController = receiver.GetHealthController(); if (healthController != null) { healthController.AddHealth(health); } } /// /// Change respecting the /// /// Target to GetComponent /// public static void ChangeHealth(this GameObject receiver, int health) { var healthController = receiver.GetHealthController(); if (healthController != null) { healthController.ChangeHealth(health); } } /// /// Change the Max Health value /// /// Target to GetComponent /// public static void ChangeMaxHealth(this GameObject receiver, int health) { var healthController = receiver.GetHealthController(); if (healthController != null) { healthController.ChangeMaxHealth(health); } } /// /// Check if GameObject Has a vIHealthController /// /// Target to GetComponent /// public static bool HasHealth(this GameObject gameObject) { return gameObject.GetHealthController() != null; } /// /// Check if GameObject is dead /// /// Target to GetComponent /// return true if GameObject does not has a vIHealthController or currentHealth is less or equals zero public static bool IsDead(this GameObject gameObject) { var health = gameObject.GetHealthController(); return health == null || health.isDead; } /// /// Reset's current health to specific health value /// /// Target to GetComponent /// target health public static void ResetHealth(this GameObject receiver, float health) { var healthController = receiver.GetHealthController(); if (healthController != null) { healthController.ResetHealth(health); } } /// /// Reset's current health to max health /// /// Target to GetComponent public static void ResetHealth(this GameObject receiver) { var healthController = receiver.GetHealthController(); if (healthController != null) { healthController.ResetHealth(); } } } }