| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- using UnityEngine;
- using LightGlue.Unity.Game;
- using LightGlue.Unity.UI;
- namespace LightGlue.Unity.Game
- {
- public class LightGlueGameManager : MonoBehaviour
- {
- //[Header("LightGlue 系统预制体")]
- //[SerializeField]
- //private GameObject lightGlueSystemPrefab;
- //[Header("Roma 系统预制体(可选)")]
- //[Tooltip("RomaManager 预制,由 GameManager 在 Awake 时生成(跨场景持久化)。若未配置则不会创建。")]
- //[SerializeField]
- //private GameObject romaSystemPrefab;
- //[Header("LightGlueUI 系统预制体(可选)")]
- //[Tooltip("LightGlueUI 预制,由 LightGlueUI 在 Awake 时生成(跨场景持久化)。若未配置则不会创建。")]
- //[SerializeField]
- //private GameObject lightGlueUIPrefab;
- [Header("LightGlueUI 类型")]
- [Tooltip("Demo:显示 Demo/BLE 相关 UI;Plugin:隐藏 Demo UI,显示插件额外 UI。")]
- [SerializeField]
- private LightGlueUIManager.UIType lightGlueUIType = LightGlueUIManager.UIType.Demo;
- //[Header("BleUI(可选,仅 Demo 使用)")]
- //[Tooltip("是否在生成 LightGlueUI 后,自动在 BLEContainer 下挂载 BleUI 预制。")]
- //[SerializeField]
- //private bool enableBleUi = false;
- //[Tooltip("BleUI 预制体(建议放在 Assets/Demo/Prefabs/BleUI.prefab)。未配置则不会创建。")]
- //[SerializeField]
- //private GameObject bleUiPrefab;
- //[Tooltip("LightGlueUI 里用于挂载 BleUI 的容器节点名。")]
- //[SerializeField]
- //private string bleContainerName = "BLEContainer";
- private void Awake()
- {
- LightGlueUIManager.Create(lightGlueUIType);
- //// 确保全局 LightGlueManager / Bridge / Python 等只创建一次
- //if (LightGlueManager.Instance == null && lightGlueSystemPrefab != null)
- //{
- // Instantiate(lightGlueSystemPrefab);
- // Debug.Log("[GameManager] LightGlueSystem prefab instantiated.");
- //}
- //// 确保全局 RomaManager 只创建一次(跨场景)
- //if (LightGlue.Unity.Roma.RomaManager.Instance == null && romaSystemPrefab != null)
- //{
- // Instantiate(romaSystemPrefab);
- // Debug.Log("[GameManager] RomaSystem prefab instantiated.");
- //}
- //// LightGlueUI:只创建一次(避免切场景重复叠 UI)
- //if (LightGlueUIManager.Instance == null && lightGlueUIPrefab != null)
- //{
- // Instantiate(lightGlueUIPrefab);
- // Debug.Log("[GameManager] LightGlueUI prefab instantiated.");
- //}
- //// 可选:在 LightGlueUI 下挂载 BleUI(Demo 专用,插件用户可不配置)
- //ApplyLightGlueUIType();
- //TryAttachBleUi();
- }
- //private void TryAttachBleUi()
- //{
- // if (lightGlueUIType != LightGlueUIManager.UIType.Demo) return;
- // if (!enableBleUi) return;
- // if (bleUiPrefab == null) return;
- // var uiMgr = LightGlueUIManager.Instance != null ? LightGlueUIManager.Instance : FindObjectOfType<LightGlueUIManager>();
- // if (uiMgr == null || uiMgr.uiRoot == null) return;
- // Transform container = uiMgr.bleContainer != null ? uiMgr.bleContainer : FindChildByName(uiMgr.uiRoot.transform, bleContainerName);
- // if (container == null) return;
- // // 防重复:避免直接引用 BLEUI 类型(插件导出时可能不包含 BLEUI.cs)
- // // 这里按 BleUI 预制名判断是否已挂载过实例。
- // string bleUiName = bleUiPrefab.name;
- // if (HasChildNamed(container, bleUiName)) return;
- // var inst = Instantiate(bleUiPrefab, container);
- // inst.name = bleUiPrefab.name;
- // Debug.Log("[GameManager] BleUI prefab attached under BLEContainer.");
- //}
- //private void ApplyLightGlueUIType()
- //{
- // var uiMgr = LightGlueUIManager.Instance != null ? LightGlueUIManager.Instance : FindObjectOfType<LightGlueUIManager>();
- // if (uiMgr == null) return;
- // uiMgr.SetUIType(lightGlueUIType);
- //}
- //private static Transform FindChildByName(Transform root, string childName)
- //{
- // if (root == null || string.IsNullOrWhiteSpace(childName)) return null;
- // if (root.name == childName) return root;
- // for (int i = 0; i < root.childCount; i++)
- // {
- // Transform t = root.GetChild(i);
- // var found = FindChildByName(t, childName);
- // if (found != null) return found;
- // }
- // return null;
- //}
- //private static bool HasChildNamed(Transform root, string name)
- //{
- // if (root == null || string.IsNullOrWhiteSpace(name)) return false;
- // for (int i = 0; i < root.childCount; i++)
- // {
- // var t = root.GetChild(i);
- // if (t == null) continue;
- // if (t.name == name || t.name == $"{name}(Clone)") return true;
- // }
- // return false;
- //}
- // NOTE:
- // - 光标设置预制生成/面板显示隐藏 已迁移到 LightGlueUIManager
- // - EntGame(sceneToLoad) 场景跳转 已迁移到 LightGlueUIManager
- }
- }
|