Ver código fonte

Added events on statistic value changed

James Peret 2 anos atrás
pai
commit
135614bb33

+ 34 - 6
Runtime/Statistics/StatisticData.cs

@@ -2,6 +2,7 @@
 using System.Collections.Generic;
 using UnityEngine;
 using Sirenix.OdinInspector;
+using KairoEngine.Core;
 
 namespace KairoEngine.Utilities.Statistics
 {
@@ -23,18 +24,39 @@ namespace KairoEngine.Utilities.Statistics
         [HorizontalGroup(80), HideLabel] public StatisticType category;
         [HorizontalGroup(), HideLabel, Tooltip("Persistent Data?")] public bool persistent = false;
 
-        public void AddTime(float t) => time += t;
-        public void AddInteger(int n) => integer += n;
+        public void AddTime(float t)
+        {
+            time += t;
+            TriggerEvent(time);
+        } 
+
+        public void AddInteger(int n)
+        {
+            integer += n;
+            TriggerEvent(integer);
+        } 
 
         public float GetTime() => time;
         public int GetInteger() => integer;
         public string GetText() => text;
 
-        public void SetTime(float t) => time = t;
-        public void SetInteger(int n) => integer = n;
-        public void SetText(string t) => text = t;
+        public void SetTime(float t) 
+        {
+            time = t;
+            TriggerEvent(time);
+        } 
 
-        
+        public void SetInteger(int n) 
+        {
+            integer = n;
+            TriggerEvent(integer);
+        }
+
+        public void SetText(string t)
+        {
+            text = t;
+            TriggerEvent(text);
+        } 
 
         public void Reset()
         {
@@ -43,5 +65,11 @@ namespace KairoEngine.Utilities.Statistics
             text = "";
         }
 
+        private void TriggerEvent(float time) => GenericEvents.Trigger("StatisticDataChanged", title, time);
+
+        private void TriggerEvent(int integer) => GenericEvents.Trigger("StatisticDataChanged", title, integer);
+
+        private void TriggerEvent(string text) => GenericEvents.Trigger("StatisticDataChanged", title, text);
+
     }
 }

+ 1 - 1
Runtime/Statistics/Statistics.cs

@@ -27,7 +27,7 @@ namespace KairoEngine.Utilities.Statistics
         }
         #endregion
 
-        [InlineEditor(InlineEditorObjectFieldModes.Boxed)] public StatisticsList db;
+        [InlineEditor(InlineEditorObjectFieldModes.Boxed)] public StatisticsLibrary db;
 
         void Awake()
         {

+ 2 - 2
Runtime/Statistics/StatisticsList.cs → Runtime/Statistics/StatisticsLibrary.cs

@@ -5,8 +5,8 @@ using Sirenix.OdinInspector;
 
 namespace KairoEngine.Utilities.Statistics
 {
-    [CreateAssetMenu(fileName = "StatisticsList", menuName = "KairoEngine/StatisticsList"), HideMonoScript]
-    public class StatisticsList : ScriptableObject
+    [CreateAssetMenu(fileName = "StatisticsLibrary", menuName = "KairoEngine/Statistics/Library"), HideMonoScript]
+    public class StatisticsLibrary : ScriptableObject
     {
         [ListDrawerSettings(ShowPaging = false)]
         public List<StatisticData> data = new List<StatisticData>();

+ 0 - 0
Runtime/Statistics/StatisticsList.cs.meta → Runtime/Statistics/StatisticsLibrary.cs.meta


+ 2 - 2
Runtime/Statistics/StatisticsModule.cs

@@ -12,7 +12,7 @@ namespace KairoEngine.Utilities.Statistics
     public class StatisticsModule : GameModuleBase
     {
         public override string name => "Statistics Module";
-        [FoldoutGroup("@name"), NonSerialized, ShowInInspector, InlineEditor(InlineEditorObjectFieldModes.Boxed)] public StatisticsList database;
+        [FoldoutGroup("@name"), NonSerialized, ShowInInspector, InlineEditor(InlineEditorObjectFieldModes.Boxed)] public StatisticsLibrary database;
         public StatisticsModule(GameConfig config) : base(config)
         {
             this.gameConfig = config;
@@ -60,7 +60,7 @@ namespace KairoEngine.Utilities.Statistics
         }
         public override void OnBeforeDeserialize(ObjectSerializer serializer)
         { 
-            database = (StatisticsList)serializer.GetScriptableObject("Statistics_Database");
+            database = (StatisticsLibrary)serializer.GetScriptableObject("Statistics_Database");
         }
     }
 }