using HighlightPlus; using QFramework; using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using XMLTool; public class DeviceController : MonoSingleton { public Dictionary deviceDict = new Dictionary(); public class DeviceData { public DeviceItem item; public Device device; } public override void OnSingletonInit() { base.OnSingletonInit(); TypeEventSystem.Global.Register(OnStart).UnRegisterWhenGameObjectDestroyed(gameObject); TypeEventSystem.Global.Register(OnQuit).UnRegisterWhenGameObjectDestroyed(gameObject); } private void OnQuit(OnModuleQuit quit) { deviceDict.Clear(); deviceDict.Clear(); } private void OnStart(OnModuleStart start) { foreach (var device in Global.Instance.curModule.Devices) { GameObject obj = null; DeviceItem item = null; if (string.IsNullOrEmpty(device.Path) == false) { obj = Utility.FindObj(device.Path); item = obj.GetOrAddComponent(); item.Init(device); } deviceDict.Add(device.Name, new DeviceData() { device = device, item = item }); } } public Device GetDevice(string name) { if (deviceDict.ContainsKey(name)) { return deviceDict[name]?.device; } return null; } public GameObject GetDeviceObj(string name) { return GetDeviceItem(name)?.gameObject; } public DeviceItem GetDeviceItem(string name) { if (deviceDict.ContainsKey(name)) { return deviceDict[name]?.item; } return null; } }