using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using KairoEngine.Core; using KairoEngine.Core.ModuleSystem; using Sirenix.OdinInspector; namespace KairoEngine.UI { [Serializable, HideReferenceObjectPicker, Toggle("enableModule")] public class UiSystemModule : GameModuleBase { public override string name => "UI Module"; [InlineEditor(InlineEditorObjectFieldModes.Boxed), LabelText("UI Library"), NonSerialized, ShowInInspector] public UiSystemLibrary library; public UiSystemModule(GameConfig config) : base(config) { this.gameConfig = config; this.className = this.GetType().AssemblyQualifiedName; this.typeName = "UiSystemModule"; this.enableModule = true; } public override void Load(Transform parent) { Transform uiParent = CreateUiManager(parent); } public override void Reset() { library = null; } public override void Destroy() { } private Transform CreateUiManager(Transform parent) { Transform UiTransform = parent.Find("UI"); GameObject uiObj; if(UiTransform == null) { uiObj = new GameObject(); uiObj.transform.position = new Vector3(); uiObj.transform.rotation = Quaternion.identity; uiObj.transform.parent = parent; uiObj.name = "UI"; } else uiObj = UiTransform.gameObject; uiObj.AddComponent(); if(library != null) library.Load(uiObj.transform); return uiObj.transform; } public static UiSystemModule JSONToUiSystemModule(string data) { try { return JsonUtility.FromJson(data); } catch (System.Exception e) { Debug.LogError($"Could not deserialize UiSystemModule: \n{e}"); return new UiSystemModule(null); } } public override void OnBeforeSerialize(ObjectSerializer serializer) { if(library != null) serializer.AddScriptableObject("UiModule_UiSystemLibrary", library); } public override void OnBeforeDeserialize(ObjectSerializer serializer) { library = (UiSystemLibrary)serializer.GetScriptableObject("UiModule_UiSystemLibrary"); } } }