1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- 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]
- public class UiSystemModule : GameModuleBase
- {
- public override string name => "UI Module";
- [FoldoutGroup("@name"), 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";
- }
- 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<UiManager>();
- if(library != null) library.Load(uiObj.transform);
- return uiObj.transform;
- }
- public static UiSystemModule JSONToUiSystemModule(string data)
- {
- try
- {
- return JsonUtility.FromJson<UiSystemModule>(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");
- }
- }
- }
|