LightGlueGameManager.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. using UnityEngine;
  2. using LightGlue.Unity.Game;
  3. using LightGlue.Unity.UI;
  4. namespace LightGlue.Unity.Game
  5. {
  6. public class LightGlueGameManager : MonoBehaviour
  7. {
  8. //[Header("LightGlue 系统预制体")]
  9. //[SerializeField]
  10. //private GameObject lightGlueSystemPrefab;
  11. //[Header("Roma 系统预制体(可选)")]
  12. //[Tooltip("RomaManager 预制,由 GameManager 在 Awake 时生成(跨场景持久化)。若未配置则不会创建。")]
  13. //[SerializeField]
  14. //private GameObject romaSystemPrefab;
  15. //[Header("LightGlueUI 系统预制体(可选)")]
  16. //[Tooltip("LightGlueUI 预制,由 LightGlueUI 在 Awake 时生成(跨场景持久化)。若未配置则不会创建。")]
  17. //[SerializeField]
  18. //private GameObject lightGlueUIPrefab;
  19. [Header("LightGlueUI 类型")]
  20. [Tooltip("Demo:显示 Demo/BLE 相关 UI;Plugin:隐藏 Demo UI,显示插件额外 UI。")]
  21. [SerializeField]
  22. private LightGlueUIManager.UIType lightGlueUIType = LightGlueUIManager.UIType.Demo;
  23. //[Header("BleUI(可选,仅 Demo 使用)")]
  24. //[Tooltip("是否在生成 LightGlueUI 后,自动在 BLEContainer 下挂载 BleUI 预制。")]
  25. //[SerializeField]
  26. //private bool enableBleUi = false;
  27. //[Tooltip("BleUI 预制体(建议放在 Assets/Demo/Prefabs/BleUI.prefab)。未配置则不会创建。")]
  28. //[SerializeField]
  29. //private GameObject bleUiPrefab;
  30. //[Tooltip("LightGlueUI 里用于挂载 BleUI 的容器节点名。")]
  31. //[SerializeField]
  32. //private string bleContainerName = "BLEContainer";
  33. private void Awake()
  34. {
  35. LightGlueUIManager.Create(lightGlueUIType);
  36. //// 确保全局 LightGlueManager / Bridge / Python 等只创建一次
  37. //if (LightGlueManager.Instance == null && lightGlueSystemPrefab != null)
  38. //{
  39. // Instantiate(lightGlueSystemPrefab);
  40. // Debug.Log("[GameManager] LightGlueSystem prefab instantiated.");
  41. //}
  42. //// 确保全局 RomaManager 只创建一次(跨场景)
  43. //if (LightGlue.Unity.Roma.RomaManager.Instance == null && romaSystemPrefab != null)
  44. //{
  45. // Instantiate(romaSystemPrefab);
  46. // Debug.Log("[GameManager] RomaSystem prefab instantiated.");
  47. //}
  48. //// LightGlueUI:只创建一次(避免切场景重复叠 UI)
  49. //if (LightGlueUIManager.Instance == null && lightGlueUIPrefab != null)
  50. //{
  51. // Instantiate(lightGlueUIPrefab);
  52. // Debug.Log("[GameManager] LightGlueUI prefab instantiated.");
  53. //}
  54. //// 可选:在 LightGlueUI 下挂载 BleUI(Demo 专用,插件用户可不配置)
  55. //ApplyLightGlueUIType();
  56. //TryAttachBleUi();
  57. }
  58. //private void TryAttachBleUi()
  59. //{
  60. // if (lightGlueUIType != LightGlueUIManager.UIType.Demo) return;
  61. // if (!enableBleUi) return;
  62. // if (bleUiPrefab == null) return;
  63. // var uiMgr = LightGlueUIManager.Instance != null ? LightGlueUIManager.Instance : FindObjectOfType<LightGlueUIManager>();
  64. // if (uiMgr == null || uiMgr.uiRoot == null) return;
  65. // Transform container = uiMgr.bleContainer != null ? uiMgr.bleContainer : FindChildByName(uiMgr.uiRoot.transform, bleContainerName);
  66. // if (container == null) return;
  67. // // 防重复:避免直接引用 BLEUI 类型(插件导出时可能不包含 BLEUI.cs)
  68. // // 这里按 BleUI 预制名判断是否已挂载过实例。
  69. // string bleUiName = bleUiPrefab.name;
  70. // if (HasChildNamed(container, bleUiName)) return;
  71. // var inst = Instantiate(bleUiPrefab, container);
  72. // inst.name = bleUiPrefab.name;
  73. // Debug.Log("[GameManager] BleUI prefab attached under BLEContainer.");
  74. //}
  75. //private void ApplyLightGlueUIType()
  76. //{
  77. // var uiMgr = LightGlueUIManager.Instance != null ? LightGlueUIManager.Instance : FindObjectOfType<LightGlueUIManager>();
  78. // if (uiMgr == null) return;
  79. // uiMgr.SetUIType(lightGlueUIType);
  80. //}
  81. //private static Transform FindChildByName(Transform root, string childName)
  82. //{
  83. // if (root == null || string.IsNullOrWhiteSpace(childName)) return null;
  84. // if (root.name == childName) return root;
  85. // for (int i = 0; i < root.childCount; i++)
  86. // {
  87. // Transform t = root.GetChild(i);
  88. // var found = FindChildByName(t, childName);
  89. // if (found != null) return found;
  90. // }
  91. // return null;
  92. //}
  93. //private static bool HasChildNamed(Transform root, string name)
  94. //{
  95. // if (root == null || string.IsNullOrWhiteSpace(name)) return false;
  96. // for (int i = 0; i < root.childCount; i++)
  97. // {
  98. // var t = root.GetChild(i);
  99. // if (t == null) continue;
  100. // if (t.name == name || t.name == $"{name}(Clone)") return true;
  101. // }
  102. // return false;
  103. //}
  104. // NOTE:
  105. // - 光标设置预制生成/面板显示隐藏 已迁移到 LightGlueUIManager
  106. // - EntGame(sceneToLoad) 场景跳转 已迁移到 LightGlueUIManager
  107. }
  108. }