123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- 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<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");
- }
- }
- }
|