113 lines
2.7 KiB
C#
113 lines
2.7 KiB
C#
using AdamSync;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class DeviceManager : MonoSingleton<DeviceManager>
|
|
{
|
|
/// <summary>
|
|
/// 所有设备
|
|
/// </summary>
|
|
public List<EquipmentCommon> devices = new List<EquipmentCommon>();
|
|
/// <summary>
|
|
/// 发送消息
|
|
/// </summary>
|
|
public Queue<string> send2roomStr = new Queue<string>();
|
|
|
|
private bool _isStartRehearsing = false;
|
|
// 属性绑定布尔值,并在值变化时触发事件
|
|
public bool isStartRehearsing
|
|
{
|
|
get { return _isStartRehearsing; }
|
|
set
|
|
{
|
|
if (_isStartRehearsing != value)
|
|
{
|
|
_isStartRehearsing = value;
|
|
OnActivationChanged?.Invoke(_isStartRehearsing);
|
|
}
|
|
}
|
|
}
|
|
// 布尔值变化时触发的事件
|
|
public event System.Action<bool> OnActivationChanged;
|
|
|
|
|
|
|
|
void Start()
|
|
{
|
|
SyncCreateRoom.send2roomRequset += GetSend2roomMsg;
|
|
|
|
// 订阅布尔值变化事件
|
|
OnActivationChanged += OnActivationChangedHandler;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 导条 暂停开始控制
|
|
/// </summary>
|
|
/// <param name="newValue"></param>
|
|
void OnActivationChangedHandler(bool newValue)
|
|
{
|
|
devices.ForEach(x => x.isStartRehearsing = newValue);
|
|
}
|
|
|
|
|
|
|
|
public bool isOnlyOne = true;
|
|
private void Update()
|
|
{
|
|
if (send2roomStr.Count > 0 && isOnlyOne)
|
|
{
|
|
isOnlyOne = false;
|
|
StartCoroutine(DequeueSend2roomStr());
|
|
}
|
|
}
|
|
|
|
IEnumerator DequeueSend2roomStr()
|
|
{
|
|
while (send2roomStr.Count > 0)
|
|
{
|
|
_ = SyncCreateRoom.SendMessageAsync(string.Format("send2room {0}", send2roomStr.Dequeue()));
|
|
yield return new WaitForSeconds(0.05f);
|
|
if (send2roomStr.Count == 0)
|
|
isOnlyOne = true;
|
|
}
|
|
}
|
|
|
|
public void AddDevice(EquipmentCommon d)
|
|
{
|
|
if (!devices.Contains(d))
|
|
{
|
|
devices.Add(d);
|
|
}
|
|
}
|
|
|
|
public void GetSend2roomMsg(string data)
|
|
{
|
|
data = data.Replace("send2room", "");
|
|
Debug.LogError("设备..:" + data);
|
|
string[] info = data.Split(',');
|
|
if (info.Length < 2) return;
|
|
|
|
EquipmentCommon equipmentCommon = devices.Find(x => x.deviceID == info[1]);
|
|
if (info[0] == "EditorDevice")
|
|
{
|
|
equipmentCommon.GetComponent<TerrestrialRadioInterferenceManger>().InterferingFrequency = info[2];
|
|
}
|
|
else
|
|
{
|
|
if (equipmentCommon)
|
|
{
|
|
equipmentCommon.ReceivingPositionAngle(info);
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public void OnDisalbe()
|
|
{
|
|
SyncCreateRoom.send2roomRequset -= GetSend2roomMsg;
|
|
}
|
|
}
|