StatisticChangeInteger.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using Sirenix.OdinInspector;
  5. namespace KairoEngine.Utilities.Statistics
  6. {
  7. public enum StatisticChangeIntegerTrigger
  8. {
  9. OnStart,
  10. OnDisable,
  11. OnDestroy
  12. }
  13. [HideMonoScript]
  14. public class StatisticChangeInteger : MonoBehaviour
  15. {
  16. [HorizontalGroup()] public string statisticName = "";
  17. [HorizontalGroup(80), ReadOnly, HideLabel] public string value;
  18. public StatisticChangeIntegerTrigger trigger;
  19. public int number;
  20. void Start()
  21. {
  22. if(Statistics.instance == null) Debug.LogError("Statistics not loaded yet");
  23. if(trigger == StatisticChangeIntegerTrigger.OnStart) ChangeInteger();
  24. }
  25. void OnDisable()
  26. {
  27. if(trigger == StatisticChangeIntegerTrigger.OnDisable) ChangeInteger();
  28. }
  29. void OnDestroy()
  30. {
  31. if(trigger == StatisticChangeIntegerTrigger.OnDestroy) ChangeInteger();
  32. }
  33. void Update()
  34. {
  35. value = Statistics.GetData(statisticName).GetInteger().ToString();
  36. }
  37. public void ChangeInteger()
  38. {
  39. Statistics.GetData(statisticName).AddInteger(number);
  40. }
  41. }
  42. }