Browse Source

Removed Statistics namespace and bumped version to 0.2.0

James Peret 2 years ago
parent
commit
ac32f98833

+ 6 - 3
Readme.md

@@ -1,4 +1,4 @@
-# 📦 KairoEngine.Utilities v0.1.2
+# 📦 KairoEngine.Utilities v0.2.0
 
 Kairoengine utilities library.
 
@@ -9,7 +9,10 @@ Kairoengine utilities library.
 
 ### 📄Namespaces
 
-- `KairoEngine.Utilities`
-- `KairoEngine.Utilities.Statistics`
+- `KairoEngine.Utility`
 
+### 📄Changelog
 
+##### v0.2.0
+
+- Moved Statistics namespace to its own package

+ 2 - 4
Runtime/KairoEngine.Utility.asmdef

@@ -1,11 +1,9 @@
 {
     "name": "KairoEngine.Utility",
+    "rootNamespace": "",
     "references": [
-        "GUID:7e5ae6a38d1532248b4c890eca668b06",
         "GUID:6055be8ebefd69e48b49212b09b47b2f",
-        "GUID:560b04d1a97f54a4e82edc0cbbb69285",
-        "GUID:fb24642277b1db2449da7ac148ce939d",
-        "GUID:5f03fc37b95cb644599751ca563336b2"
+        "GUID:560b04d1a97f54a4e82edc0cbbb69285"
     ],
     "includePlatforms": [],
     "excludePlatforms": [],

+ 0 - 8
Runtime/Statistics.meta

@@ -1,8 +0,0 @@
-fileFormatVersion: 2
-guid: 7bd11ce3e4749b648bf12bf5c7c8487c
-folderAsset: yes
-DefaultImporter:
-  externalObjects: {}
-  userData: 
-  assetBundleName: 
-  assetBundleVariant: 

+ 0 - 51
Runtime/Statistics/StatisticChangeInteger.cs

@@ -1,51 +0,0 @@
-using System.Collections;
-using System.Collections.Generic;
-using UnityEngine;
-using Sirenix.OdinInspector;
-
-namespace KairoEngine.Utilities.Statistics
-{
-    public enum StatisticChangeIntegerTrigger
-    {
-        OnStart,
-        OnDisable,
-        OnDestroy
-    }
-
-    [HideMonoScript]
-    public class StatisticChangeInteger : MonoBehaviour
-    {
-        [HorizontalGroup()] public string statisticName = "";
-        [HorizontalGroup(80), ReadOnly, HideLabel] public string value;
-
-        public StatisticChangeIntegerTrigger trigger;
-        public int number;
-
-        void Start()
-        {
-            if(Statistics.instance == null) Debug.LogError("Statistics not loaded yet");
-            if(trigger == StatisticChangeIntegerTrigger.OnStart) ChangeInteger();
-        }
-
-        void OnDisable()
-        {
-            if(trigger == StatisticChangeIntegerTrigger.OnDisable) ChangeInteger();
-        }
-
-        void OnDestroy()
-        {
-            if(trigger == StatisticChangeIntegerTrigger.OnDestroy) ChangeInteger();
-        }
-
-        void Update()
-        {
-            value = Statistics.GetData(statisticName).GetInteger().ToString();
-        }
-
-        public void ChangeInteger()
-        {
-            Statistics.GetData(statisticName).AddInteger(number);
-        }
-    }
-}
-

+ 0 - 11
Runtime/Statistics/StatisticChangeInteger.cs.meta

@@ -1,11 +0,0 @@
-fileFormatVersion: 2
-guid: 71a9a6d00db694e40938597e57bd95cf
-MonoImporter:
-  externalObjects: {}
-  serializedVersion: 2
-  defaultReferences: []
-  executionOrder: 0
-  icon: {instanceID: 0}
-  userData: 
-  assetBundleName: 
-  assetBundleVariant: 

+ 0 - 75
Runtime/Statistics/StatisticData.cs

@@ -1,75 +0,0 @@
-using System.Collections;
-using System.Collections.Generic;
-using UnityEngine;
-using Sirenix.OdinInspector;
-using KairoEngine.Core;
-
-namespace KairoEngine.Utilities.Statistics
-{
-    public enum StatisticType
-    {
-        time,
-        integer,
-        text
-    }
-
-    [System.Serializable, HideMonoScript]
-    public class StatisticData
-    {
-        [HorizontalGroup(180), HideLabel] public string title;
-
-        [ShowIf("@category == StatisticType.time"), HorizontalGroup(), HideLabel, ShowInInspector] private float time;
-        [ShowIf("@category == StatisticType.integer"), HorizontalGroup(), HideLabel, ShowInInspector] private int integer;
-        [ShowIf("@category == StatisticType.text"), HorizontalGroup(), HideLabel, ShowInInspector] private string text;
-        [HorizontalGroup(80), HideLabel] public StatisticType category;
-        [HorizontalGroup(), HideLabel, Tooltip("Persistent Data?")] public bool persistent = false;
-
-        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;
-            TriggerEvent(time);
-        } 
-
-        public void SetInteger(int n) 
-        {
-            integer = n;
-            TriggerEvent(integer);
-        }
-
-        public void SetText(string t)
-        {
-            text = t;
-            TriggerEvent(text);
-        } 
-
-        public void Reset()
-        {
-            time = 0f;
-            integer = 0;
-            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);
-
-    }
-}

+ 0 - 11
Runtime/Statistics/StatisticData.cs.meta

@@ -1,11 +0,0 @@
-fileFormatVersion: 2
-guid: 919fc0a3cb4d10b4d8651a582a736d4e
-MonoImporter:
-  externalObjects: {}
-  serializedVersion: 2
-  defaultReferences: []
-  executionOrder: 0
-  icon: {instanceID: 0}
-  userData: 
-  assetBundleName: 
-  assetBundleVariant: 

+ 0 - 39
Runtime/Statistics/StatisticElapsedTime.cs

@@ -1,39 +0,0 @@
-using System.Collections;
-using System.Collections.Generic;
-using UnityEngine;
-using KairoEngine.Utilities;
-using Sirenix.OdinInspector;
-using KairoEngine.Core;
-
-namespace KairoEngine.Utilities.Statistics
-{
-    [HideMonoScript]
-    public class StatisticElapsedTime : MonoBehaviour
-    {
-        public string statisticName = "";
-        [ReadOnly] public string elapsedTime;
-
-        [HorizontalGroup()] public bool unscaledDeltaTime = true;
-        [HorizontalGroup()] public bool resetOnStart = true;
-
-        void Start()
-        {
-            if(resetOnStart) Statistics.GetData(statisticName).Reset();
-        }
-
-        void Update()
-        {
-            if(unscaledDeltaTime)
-            {
-                Statistics.GetData(statisticName).AddTime(Time.unscaledDeltaTime);
-            }
-            else
-            {
-                Statistics.GetData(statisticName).AddTime(Time.deltaTime);
-            }
-            float time = Statistics.GetData(statisticName).GetTime();
-            elapsedTime = KairoEngine.Core.Utilities.TimeToString(time);
-        }
-    }
-}
-

+ 0 - 11
Runtime/Statistics/StatisticElapsedTime.cs.meta

@@ -1,11 +0,0 @@
-fileFormatVersion: 2
-guid: 0f810b498e3e89445aa607425e0fdcac
-MonoImporter:
-  externalObjects: {}
-  serializedVersion: 2
-  defaultReferences: []
-  executionOrder: 0
-  icon: {instanceID: 0}
-  userData: 
-  assetBundleName: 
-  assetBundleVariant: 

+ 0 - 120
Runtime/Statistics/Statistics.cs

@@ -1,120 +0,0 @@
-using System.Collections;
-using System.Collections.Generic;
-using UnityEngine;
-using Sirenix.OdinInspector;
-
-namespace KairoEngine.Utilities.Statistics
-{
-    [HideMonoScript]
-    public class Statistics : SerializedMonoBehaviour
-    {
-        #region Singleton
-        private static Statistics statistics;
-        public static Statistics instance
-        {
-            get {
-                if(!statistics)
-                {
-                    statistics = FindObjectOfType (typeof(Statistics)) as Statistics;
-                    if(!statistics)
-                    {
-                        Debug.LogError("There need to one active Statistics script on the scene.");
-                        return null;
-                    }
-                }
-                return statistics;
-            }
-        }
-        #endregion
-
-        [InlineEditor(InlineEditorObjectFieldModes.Boxed)] public StatisticsLibrary db;
-
-        void Awake()
-        {
-            if(instance != null && instance != this) 
-            {
-                Destroy(this.gameObject);
-                return;
-            }
-        }
-
-        void Start()
-        {
-            if(db == null)
-            {
-                Debug.LogError("Statistics component is missing the StatisticsList.\nPlease configure the statistics module in the Game config file.");
-                return;
-            }
-            LoadStatistics();
-        }
-
-        void OnDestroy()
-        {
-            SaveStatistics();
-        }
-
-        public static StatisticData GetData(string title)
-        {
-            if(instance == null) return null;
-            if(instance.db == null) return null;
-            for (int i = 0; i < instance.db.data.Count; i++)
-            {
-                if(instance.db.data[i].title == title) return instance.db.data[i];
-            }
-            return null;
-        }
-
-        private void LoadStatistics()
-        {
-            if(instance == null) return;
-            if(instance.db == null) return;
-            for (int i = 0; i < instance.db.data.Count; i++)
-            {
-                StatisticData stat = instance.db.data[i];
-                if(stat.persistent == false) continue;
-                switch (stat.category)
-                {
-                    case StatisticType.time:
-                        float time = PlayerPrefs.GetFloat(stat.title, 0f);
-                        stat.SetTime(time);
-                        break;
-                    case StatisticType.integer:
-                        int integer = PlayerPrefs.GetInt(stat.title, 0);
-                        stat.SetInteger(integer);
-                        break;
-                    case StatisticType.text:
-                        string text = PlayerPrefs.GetString(stat.title, "");
-                        stat.SetText(text);
-                        break;
-                    default:
-                        break;
-                }
-            }
-        }
-
-        private void SaveStatistics()
-        {
-            if(instance == null) return;
-            if(instance.db == null) return;
-            for (int i = 0; i < instance.db.data.Count; i++)
-            {
-                StatisticData stat = instance.db.data[i];
-                if(stat.persistent == false) continue;
-                switch (stat.category)
-                {
-                    case StatisticType.time:
-                        PlayerPrefs.SetFloat(stat.title, stat.GetTime());
-                        break;
-                    case StatisticType.integer:
-                        PlayerPrefs.SetInt(stat.title, stat.GetInteger());
-                        break;
-                    case StatisticType.text:
-                        PlayerPrefs.SetString(stat.title, stat.GetText());
-                        break;
-                    default:
-                        break;
-                }
-            }
-        }
-    }
-}

+ 0 - 11
Runtime/Statistics/Statistics.cs.meta

@@ -1,11 +0,0 @@
-fileFormatVersion: 2
-guid: 8a8d253b00a34644980604012c30900d
-MonoImporter:
-  externalObjects: {}
-  serializedVersion: 2
-  defaultReferences: []
-  executionOrder: 0
-  icon: {instanceID: 0}
-  userData: 
-  assetBundleName: 
-  assetBundleVariant: 

+ 0 - 51
Runtime/Statistics/StatisticsConsoleCommands.cs

@@ -1,51 +0,0 @@
-using System.Collections;
-using System.Collections.Generic;
-using System.Text;
-using UnityEngine;
-using KairoEngine.Utilities;
-using QFSW.QC;
-using QFSW.QC.Utilities;
-using KairoEngine.Core;
-
-namespace KairoEngine.Utilities.Statistics
-{
-    public static class StatisticsConsoleCommands
-    {
-        private static readonly Pool<StringBuilder> _builderPool = new Pool<StringBuilder>();
-
-        [Command("statistics-list", "List of statistics names")]
-        private static string PrintStatistics()
-        {
-            QuantumConsole console = QuantumConsole.Instance;
-            string result = "";
-            StringBuilder buffer = _builderPool.GetObject();
-            Color color = Color.white;
-            buffer.Clear();
-            if(console != null)
-            {
-                QuantumTheme theme = console.GetTheme();
-                color = theme ? theme.SuccessColor : Color.white;
-            }
-            foreach (var stat in Statistics.instance.db.data)
-            {
-                result += stat.title;
-                switch (stat.category)
-                {
-                    case StatisticType.integer:
-                    result += " - " + ColorExtensions.ColorText(stat.GetInteger().ToString(), color);
-                    break;
-                    case StatisticType.time:
-                    result += " - " + ColorExtensions.ColorText(KairoEngine.Core.Utilities.TimeToString(stat.GetTime()), color);
-                    break;
-                    default:
-                    break;
-                }
-                buffer.AppendLine(result);
-                result = "";
-            }
-            result = buffer.ToString();
-            _builderPool.Release(buffer);
-            return result;
-        }
-    }
-}

+ 0 - 11
Runtime/Statistics/StatisticsConsoleCommands.cs.meta

@@ -1,11 +0,0 @@
-fileFormatVersion: 2
-guid: 00fb781460b49ed49bf1cd22d5794f94
-MonoImporter:
-  externalObjects: {}
-  serializedVersion: 2
-  defaultReferences: []
-  executionOrder: 0
-  icon: {instanceID: 0}
-  userData: 
-  assetBundleName: 
-  assetBundleVariant: 

+ 0 - 14
Runtime/Statistics/StatisticsLibrary.cs

@@ -1,14 +0,0 @@
-using System.Collections;
-using System.Collections.Generic;
-using UnityEngine;
-using Sirenix.OdinInspector;
-
-namespace KairoEngine.Utilities.Statistics
-{
-    [CreateAssetMenu(fileName = "StatisticsLibrary", menuName = "KairoEngine/Statistics/Library"), HideMonoScript]
-    public class StatisticsLibrary : ScriptableObject
-    {
-        [ListDrawerSettings(ShowPaging = false)]
-        public List<StatisticData> data = new List<StatisticData>();
-    }
-}

+ 0 - 11
Runtime/Statistics/StatisticsLibrary.cs.meta

@@ -1,11 +0,0 @@
-fileFormatVersion: 2
-guid: 48fb955243a877d4ea4cbe3debd8bcb1
-MonoImporter:
-  externalObjects: {}
-  serializedVersion: 2
-  defaultReferences: []
-  executionOrder: 0
-  icon: {instanceID: 0}
-  userData: 
-  assetBundleName: 
-  assetBundleVariant: 

+ 0 - 66
Runtime/Statistics/StatisticsModule.cs

@@ -1,66 +0,0 @@
-using System;
-using System.Collections;
-using System.Collections.Generic;
-using UnityEngine;
-using KairoEngine.Core;
-using KairoEngine.Core.ModuleSystem;
-using Sirenix.OdinInspector;
-
-namespace KairoEngine.Utilities.Statistics
-{
-    [Serializable, HideReferenceObjectPicker]
-    public class StatisticsModule : GameModuleBase
-    {
-        public override string name => "Statistics Module";
-        [NonSerialized, ShowInInspector, InlineEditor(InlineEditorObjectFieldModes.Boxed)] public StatisticsLibrary database;
-        public StatisticsModule(GameConfig config) : base(config)
-        {
-            this.gameConfig = config;
-            this.className = this.GetType().AssemblyQualifiedName;
-            this.typeName = "StatisticsModule";
-        }
-
-        public override void Load(Transform parent)
-        {
-            if(database == null)
-            {
-                Debug.LogError("Missing statistics database.\nPlease configure the statistics module in the Game config file.");
-                return;
-            }
-            var obj = new GameObject();
-            obj.transform.parent = parent;
-            obj.name = "Statistics";
-            var comp = obj.AddComponent<Statistics>();
-            comp.db = database;
-        }
-
-        public override void Reset()
-        {
-            
-        }
-
-        public override void Destroy() { }
-
-        public static StatisticsModule JSONToStatisticsModule(string data)
-        {
-            try
-            {
-                return JsonUtility.FromJson<StatisticsModule>(data);
-            }
-            catch (System.Exception e)
-            {
-                Debug.LogError($"Could not deserialize StatisticsModule: \n{e}");
-                return new StatisticsModule(null);
-            }
-        }
-
-        public override void OnBeforeSerialize(ObjectSerializer serializer) 
-        {
-            if(database != null) serializer.AddScriptableObject("Statistics_Database", database);
-        }
-        public override void OnBeforeDeserialize(ObjectSerializer serializer)
-        { 
-            database = (StatisticsLibrary)serializer.GetScriptableObject("Statistics_Database");
-        }
-    }
-}

+ 0 - 11
Runtime/Statistics/StatisticsModule.cs.meta

@@ -1,11 +0,0 @@
-fileFormatVersion: 2
-guid: a3fea9601b9d8e8419adff3354bb0180
-MonoImporter:
-  externalObjects: {}
-  serializedVersion: 2
-  defaultReferences: []
-  executionOrder: 0
-  icon: {instanceID: 0}
-  userData: 
-  assetBundleName: 
-  assetBundleVariant: 

+ 1 - 1
package.json

@@ -1,7 +1,7 @@
 {
     "name": "at.kairoscope.kairoengine.utilities",
     "displayName": "KairoEngine Utilities",
-    "version": "0.1.3",
+    "version": "0.2.0",
     "unity": "2020.3",
     "description": "Kairoengine utilities library. Contains the MeshUtils, StringUtils, Vector2Int extensions and the Statistics System.",
     "dependencies": {