StatisticData.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using Sirenix.OdinInspector;
  5. using KairoEngine.Core;
  6. namespace KairoEngine.Utilities.Statistics
  7. {
  8. public enum StatisticType
  9. {
  10. time,
  11. integer,
  12. text
  13. }
  14. [System.Serializable, HideMonoScript]
  15. public class StatisticData
  16. {
  17. [HorizontalGroup(180), HideLabel] public string title;
  18. [ShowIf("@category == StatisticType.time"), HorizontalGroup(), HideLabel, ShowInInspector] private float time;
  19. [ShowIf("@category == StatisticType.integer"), HorizontalGroup(), HideLabel, ShowInInspector] private int integer;
  20. [ShowIf("@category == StatisticType.text"), HorizontalGroup(), HideLabel, ShowInInspector] private string text;
  21. [HorizontalGroup(80), HideLabel] public StatisticType category;
  22. [HorizontalGroup(), HideLabel, Tooltip("Persistent Data?")] public bool persistent = false;
  23. public void AddTime(float t)
  24. {
  25. time += t;
  26. TriggerEvent(time);
  27. }
  28. public void AddInteger(int n)
  29. {
  30. integer += n;
  31. TriggerEvent(integer);
  32. }
  33. public float GetTime() => time;
  34. public int GetInteger() => integer;
  35. public string GetText() => text;
  36. public void SetTime(float t)
  37. {
  38. time = t;
  39. TriggerEvent(time);
  40. }
  41. public void SetInteger(int n)
  42. {
  43. integer = n;
  44. TriggerEvent(integer);
  45. }
  46. public void SetText(string t)
  47. {
  48. text = t;
  49. TriggerEvent(text);
  50. }
  51. public void Reset()
  52. {
  53. time = 0f;
  54. integer = 0;
  55. text = "";
  56. }
  57. private void TriggerEvent(float time) => GenericEvents.Trigger("StatisticDataChanged", title, time);
  58. private void TriggerEvent(int integer) => GenericEvents.Trigger("StatisticDataChanged", title, integer);
  59. private void TriggerEvent(string text) => GenericEvents.Trigger("StatisticDataChanged", title, text);
  60. }
  61. }