using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using KairoEngine.Core; using KairoEngine.Core.ModuleSystem; using Sirenix.OdinInspector; namespace KairoEngine.Achievements { [Serializable, HideReferenceObjectPicker] public class AchievementsModule : GameModuleBase { public override string name => "Achievements Module"; public bool CheckOnStart = true; public bool checkOnInterval = true; [ShowIf("@checkOnInterval"), SuffixLabel("ms")] public int checkInterval = 3000; [SuffixLabel("ms")] public int startDelay = 3000; public bool debug = false; [NonSerialized, ShowInInspector, InlineEditor(InlineEditorObjectFieldModes.Boxed)] public AchievementsLibrary library; public AchievementsModule(GameConfig config) : base(config) { this.gameConfig = config; this.className = this.GetType().AssemblyQualifiedName; this.typeName = "AchievementsModule"; } public override void Load(Transform parent) { if(library == null) { Debug.LogError("Missing Achievements Library.\nPlease configure the Achievements module in the Game config file."); return; } var obj = new GameObject(); obj.transform.parent = parent; obj.name = "Achievements"; var comp = obj.AddComponent(); comp.library = this.library; comp.CheckOnStart = this.CheckOnStart; comp.checkOnInterval = this.checkOnInterval; comp.checkInterval = this.checkInterval; comp.startDelay = this.startDelay; comp.debug = this.debug; } public override void Reset() { this.library = null; this.CheckOnStart = true; this.checkOnInterval = true; this.checkInterval = 3000; this.startDelay = 3000; this.debug = false; } public override void Destroy() { } public static AchievementsModule JSONToAchievementsModule(string data) { try { return JsonUtility.FromJson(data); } catch (System.Exception e) { Debug.LogError($"Could not deserialize AchievementsModule: \n{e}"); return new AchievementsModule(null); } } public override void OnBeforeSerialize(ObjectSerializer serializer) { if(library != null) serializer.AddScriptableObject("Achievements_Library", library); } public override void OnBeforeDeserialize(ObjectSerializer serializer) { library = (AchievementsLibrary)serializer.GetScriptableObject("Achievements_Library"); } } }