using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using KairoEngine.Core; using KairoEngine.Core.ModuleSystem; using Sirenix.OdinInspector; namespace KairoEngine.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(); comp.db = database; } public override void Reset() { } public override void Destroy() { } public static StatisticsModule JSONToStatisticsModule(string data) { try { return JsonUtility.FromJson(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"); } } }