262 lines
7.9 KiB
C#
262 lines
7.9 KiB
C#
using AdamSync;
|
||
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using UnityEngine;
|
||
using System.Text;
|
||
|
||
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;
|
||
|
||
public void OnInit()
|
||
{
|
||
// 订阅布尔值变化事件
|
||
OnActivationChanged += OnActivationChangedHandler;
|
||
|
||
//接收实时传输数据
|
||
//SyncCreateRoom.send2roomRequset += GetSend2roomMsg;
|
||
LoadManage.Instance.reciveData += GetSend2roomMsg;
|
||
}
|
||
|
||
void Start()
|
||
{
|
||
|
||
|
||
}
|
||
|
||
/// <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());
|
||
//}
|
||
#if UNITY_EDITOR
|
||
if (Input.GetKeyDown(KeyCode.Space))
|
||
{
|
||
isStartRehearsing = !isStartRehearsing;
|
||
Debug.Log("编辑器测试...导条状态..:" + isStartRehearsing);
|
||
}
|
||
#endif
|
||
}
|
||
|
||
//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 RemoveDevice(GameObject obj)
|
||
{
|
||
if (devices.Contains(obj.GetComponent<EquipmentCommon>()))
|
||
devices.Remove(obj.GetComponent<EquipmentCommon>());
|
||
}
|
||
|
||
public int GetPlayerDevice()
|
||
{
|
||
List<GameObject> temp = new List<GameObject>();
|
||
for (int i = 0; i < devices.Count; i++)
|
||
{
|
||
if (devices[i] != null && devices[i].isPlayer)
|
||
{
|
||
temp.Add(devices[i].gameObject);
|
||
}
|
||
}
|
||
return temp.Count;
|
||
}
|
||
/// <summary>
|
||
/// 获取所以当前玩家的设备
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
public List<GameObject> GetPlayerDecive1()
|
||
{
|
||
List<GameObject> temp = new List<GameObject>();
|
||
for (int i = 0; i < devices.Count; i++)
|
||
{
|
||
if (devices[i] != null && devices[i].isPlayer)
|
||
{
|
||
temp.Add(devices[i].gameObject);
|
||
}
|
||
}
|
||
return temp;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取光学无人机和自杀式无人机
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
public List<UnmannedAerialVehicleManage> GetGXWRJAndZSWRJ()
|
||
{
|
||
List<UnmannedAerialVehicleManage> tempUAM = new List<UnmannedAerialVehicleManage>();
|
||
for (int i = 0; i < devices.Count; i++)
|
||
{
|
||
if (devices[i] != null && devices[i].gameObject.name.Contains("无人机"))
|
||
{
|
||
UnmannedAerialVehicleManage temp = devices[i].GetComponent<UnmannedAerialVehicleManage>();
|
||
if (temp != null)
|
||
{
|
||
if (temp.wrjModel == WRJModel.光学无人机 || temp.wrjModel == WRJModel.自杀式无人机)
|
||
tempUAM.Add(temp);
|
||
}
|
||
}
|
||
}
|
||
return tempUAM;
|
||
}
|
||
|
||
public List<UnmannedAerialVehicleManage> unmannedAerialVehicleManages;
|
||
public void SetCollider4WRJ(List<Collider> attackColliders, ref Collider currentTarget)
|
||
{
|
||
for (int i = 0; i < attackColliders.Count; i++)
|
||
{
|
||
if (attackColliders[i] == null)
|
||
attackColliders.RemoveAt(i);
|
||
}
|
||
if (attackColliders.Count > 0)
|
||
{
|
||
unmannedAerialVehicleManages = GetGXWRJAndZSWRJ();
|
||
for (int i = 0; i < unmannedAerialVehicleManages.Count; i++)
|
||
{
|
||
if (unmannedAerialVehicleManages[i].unmannedAerialVehicles[0] != null && unmannedAerialVehicleManages[i].unmannedAerialVehicles[0].gameObject.activeSelf)
|
||
{
|
||
if (unmannedAerialVehicleManages[i].unmannedAerialVehicles[0].attackTarget == null)
|
||
{
|
||
|
||
unmannedAerialVehicleManages[i].unmannedAerialVehicles[0].AttAck(attackColliders[0].transform);
|
||
}
|
||
}
|
||
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
|
||
|
||
/// <summary>
|
||
/// 处理数据
|
||
/// </summary>
|
||
/// <param name="data"></param>
|
||
/// <returns></returns>
|
||
public void GetSend2roomMsg(byte[] tt)
|
||
{
|
||
string data = Encoding.UTF8.GetString(tt).Replace("send2room", "");
|
||
string[] info = data.Split(',');
|
||
if (info.Length < 2) return;
|
||
|
||
if (info[0] == "KeyTarget")
|
||
{
|
||
Debug.Log("接收处理:KeyTarget...:" + data);
|
||
HighPriorityTarget highPriorityTarget = HighPriorityTarget.HighPriorityTargets.Find(x => x.Number == info[1]);
|
||
if (highPriorityTarget)
|
||
{
|
||
Vector3 Pos = new Vector3(float.Parse(info[3]), float.Parse(info[4]), float.Parse(info[5]));
|
||
highPriorityTarget.BeAssaulted(Pos, false, int.Parse(info[2]));
|
||
}
|
||
}
|
||
else if (info[0] == "BandSetting")
|
||
{
|
||
if (info[1] == "WRJ")
|
||
{
|
||
UnmannedAerialVehicleManage unmannedAerialVehicleManage = UnmannedAerialVehicleManage.unmannedAerialVehicleManages.Find(x => x.equipmentCommon.deviceID == info[2]);
|
||
if (unmannedAerialVehicleManage)
|
||
{
|
||
unmannedAerialVehicleManage.FrequencyGamepos(info[3]);
|
||
}
|
||
}
|
||
else if (info[1] == "ZYMB")
|
||
{
|
||
HighPriorityTarget highPriorityTarget = HighPriorityTarget.HighPriorityTargets.Find(x => x.Number == info[2]);
|
||
if (highPriorityTarget)
|
||
{
|
||
highPriorityTarget.FrequencyGamepos(info[3]);
|
||
}
|
||
}
|
||
}
|
||
else if (info[0] == "SweepFrequencyBand")
|
||
{
|
||
if (info[1] == "WRJ")
|
||
{
|
||
UnmannedAerialVehicleManage unmannedAerialVehicleManage = UnmannedAerialVehicleManage.unmannedAerialVehicleManages.Find(x => x.equipmentCommon.deviceID == info[2]);
|
||
if (unmannedAerialVehicleManage)
|
||
{
|
||
unmannedAerialVehicleManage.SurveillanceFrequency(info[3]);
|
||
}
|
||
}
|
||
else if (info[1] == "PPTC")
|
||
{
|
||
Spectrumdetection spectrumdetection = Spectrumdetection.spectrumdetections.Find(x => x.equipmentCommon.deviceID == info[2]);
|
||
if (spectrumdetection)
|
||
{
|
||
spectrumdetection.CameraFrequency(info[3]);
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
EquipmentCommon equipmentCommon = devices.Find(x => x.deviceID == info[1]);
|
||
if (equipmentCommon)
|
||
{
|
||
equipmentCommon.ReceivingPositionAngle(info);
|
||
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
|
||
public void OnDisalbe()
|
||
{
|
||
//SyncCreateRoom.send2roomRequset -= GetSend2roomMsg;
|
||
}
|
||
}
|