FloatingValuesController.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using Sirenix.OdinInspector;
  5. using KairoEngine.Core;
  6. namespace KairoEngine.CharacterSystem
  7. {
  8. public class FloatingValuesController : MonoBehaviour
  9. {
  10. public GameObject floatingValueUiPrefab;
  11. public Transform canvasParent;
  12. void OnEnable()
  13. {
  14. DamageEvents.OnDamage += OnDamage;
  15. DamageEvents.OnHeal += OnHeal;
  16. FloatingMessageEvents.OnMessage += OnMessage;
  17. }
  18. void OnDisable()
  19. {
  20. DamageEvents.OnDamage -= OnDamage;
  21. DamageEvents.OnHeal -= OnHeal;
  22. FloatingMessageEvents.OnMessage -= OnMessage;
  23. }
  24. private void OnDamage(DamageData damageData)
  25. {
  26. GameObject obj = Instantiate(floatingValueUiPrefab, canvasParent);
  27. obj.GetComponent<FloatingValueUi>().Setup(damageData.damageController.transform.position, "-" + damageData.damage.ToString());
  28. }
  29. private void OnHeal(DamageController damageController, int heal)
  30. {
  31. GameObject obj = Instantiate(floatingValueUiPrefab, canvasParent);
  32. obj.GetComponent<FloatingValueUi>().Setup(damageController.transform.position, "+" + heal.ToString());
  33. }
  34. private void OnMessage(string message, Vector3 pos, float offset, float time, float fontSize)
  35. {
  36. GameObject obj = Instantiate(floatingValueUiPrefab, canvasParent);
  37. obj.GetComponent<FloatingValueUi>().Setup(pos, message, 1.2f);
  38. }
  39. }
  40. }