77 lines
1.9 KiB
C#
77 lines
1.9 KiB
C#
using HighlightPlus;
|
|
using QFramework;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using XMLTool;
|
|
|
|
public class DeviceController : MonoSingleton<DeviceController>
|
|
{
|
|
public Dictionary<string, DeviceData> deviceDict = new Dictionary<string, DeviceData>();
|
|
|
|
public class DeviceData
|
|
{
|
|
public DeviceItem item;
|
|
public Device device;
|
|
}
|
|
|
|
|
|
public override void OnSingletonInit()
|
|
{
|
|
base.OnSingletonInit();
|
|
TypeEventSystem.Global.Register<OnModuleStart>(OnStart).UnRegisterWhenGameObjectDestroyed(gameObject);
|
|
TypeEventSystem.Global.Register<OnModuleQuit>(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<DeviceItem>();
|
|
item.Init(device);
|
|
}
|
|
Debug.Log(device.Name, item);
|
|
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;
|
|
}
|
|
|
|
|
|
}
|