UiSystemModule.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using KairoEngine.Core;
  6. using KairoEngine.Core.ModuleSystem;
  7. using Sirenix.OdinInspector;
  8. namespace KairoEngine.UI
  9. {
  10. [Serializable, HideReferenceObjectPicker]
  11. public class UiSystemModule : GameModuleBase
  12. {
  13. public override string name => "UI Module";
  14. public UiSystemModule(GameConfig config) : base(config)
  15. {
  16. this.gameConfig = config;
  17. this.className = this.GetType().AssemblyQualifiedName;
  18. this.typeName = "UiSystemModule";
  19. }
  20. public override void Load(Transform parent)
  21. {
  22. Transform uiParent = CreateUiManager(parent);
  23. Debug.Log("UI System has been loaded");
  24. }
  25. public override void Reset()
  26. {
  27. }
  28. public override void Destroy()
  29. {
  30. }
  31. private Transform CreateUiManager(Transform parent)
  32. {
  33. Transform UiTransform = parent.Find("UI");
  34. GameObject uiObj;
  35. if(UiTransform == null)
  36. {
  37. uiObj = GameObject.Instantiate(new GameObject(), new Vector3(), Quaternion.identity, parent);
  38. uiObj.name = "UI";
  39. }
  40. else uiObj = UiTransform.gameObject;
  41. uiObj.AddComponent<UiManager>();
  42. return uiObj.transform;
  43. }
  44. public static UiSystemModule JSONToUiSystemModule(string data)
  45. {
  46. try
  47. {
  48. return JsonUtility.FromJson<UiSystemModule>(data);
  49. }
  50. catch (System.Exception e)
  51. {
  52. Debug.LogError($"Could not deserialize UiSystemModule: \n{e}");
  53. return new UiSystemModule(null);
  54. }
  55. }
  56. public override void OnBeforeSerialize(ObjectSerializer serializer) { }
  57. public override void OnBeforeDeserialize(ObjectSerializer serializer) { }
  58. }
  59. }