379 lines
12 KiB
C#
379 lines
12 KiB
C#
using AdamThinkDevicesData;
|
|
using Newtonsoft.Json;
|
|
using Newtonsoft.Json.Linq;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using static InterfaceManager;
|
|
/// <summary>
|
|
/// 频谱探测
|
|
/// </summary>
|
|
public class Spectrumdetection : MonoBehaviour
|
|
{
|
|
|
|
public static List<Spectrumdetection> spectrumdetections=new List<Spectrumdetection>();
|
|
|
|
public EquipmentCommon equipmentCommon;
|
|
#region 频谱探测的参数
|
|
/// <summary>
|
|
/// 探测距离
|
|
/// </summary>
|
|
public string Detectionrange;
|
|
/// <summary>
|
|
/// 批目标处理能力
|
|
/// </summary>
|
|
public string Batchcapacity;
|
|
/// <summary>
|
|
/// 探测频率
|
|
/// </summary>
|
|
public string frequency;
|
|
/// <summary>
|
|
/// 探测成功率
|
|
/// </summary>
|
|
public string Detectionsuccessrate;
|
|
/// <summary>
|
|
/// 探测响应时间
|
|
/// </summary>
|
|
public string Responsetime;
|
|
/// <summary>
|
|
/// 测向精度
|
|
/// </summary>
|
|
public string Directionfindingaccuracy;
|
|
/// <summary>
|
|
/// 最小探测速度
|
|
/// </summary>
|
|
public string Minimumdetectionvelocity;
|
|
#endregion
|
|
|
|
private bool _isStartRehearsing = false;
|
|
/// <summary>
|
|
/// 是否正在演练
|
|
/// </summary>
|
|
public bool isStartRehearsing
|
|
{
|
|
get { return _isStartRehearsing; }
|
|
set
|
|
{
|
|
if (_isStartRehearsing != value)
|
|
{
|
|
_isStartRehearsing = value;
|
|
OnActivationChanged?.Invoke(_isStartRehearsing);
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 布尔值变化时触发时间
|
|
/// </summary>
|
|
public event System.Action<bool> OnActivationChanged;
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public GameObject SpectrumdetectionUI;
|
|
/// <summary>
|
|
/// 显示UI频段页面
|
|
/// </summary>
|
|
public Image Frequencyiamge;
|
|
/// <summary>
|
|
/// 关闭按钮
|
|
/// </summary>
|
|
public Button frenbutton;
|
|
/// <summary>
|
|
/// 选择最终的频段
|
|
/// </summary>
|
|
//public Toggle toggle1, toggle2, toggle3, toggle4, toggle5, toggle6, toggle7;
|
|
/// <summary>
|
|
/// 频段设置
|
|
/// </summary>
|
|
public List<Toggle> toggles = new List<Toggle>();
|
|
/// <summary>
|
|
/// 最终的波段
|
|
/// </summary>
|
|
public string Frequency;
|
|
/// <summary>
|
|
/// 摄像机显示层数
|
|
/// </summary>
|
|
public Camera Camera1;
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public RawImage rawImage;
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
private bool onlyOne = true;
|
|
/// <summary>
|
|
/// 接收探测范围
|
|
/// </summary>
|
|
public static float Radius;
|
|
void Start()
|
|
{
|
|
Camera1.gameObject.SetActive(false);
|
|
spectrumdetections.Add(this);
|
|
|
|
equipmentCommon = GetComponent<EquipmentCommon>();
|
|
// 订阅布尔值变化事件
|
|
OnActivationChanged += OnActivationChangedHandler;
|
|
_isStartRehearsing = GlobalFlag.isStartRehearsing;
|
|
Microwave();
|
|
//DroneViewDisplay.Instance.CreateUI(equipmentCommon.deviceID, camera, rawImage);
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
if (isStartRehearsing)
|
|
{
|
|
Camera1.gameObject.SetActive(true);
|
|
Search();//微波武器朝向无人机
|
|
}
|
|
if (onlyOne && equipmentCommon.deviceID.Length > 10)
|
|
{
|
|
onlyOne = false;
|
|
DroneViewDisplay.Instance.CreateUI(equipmentCommon.deviceID, Camera1, rawImage);
|
|
}
|
|
}
|
|
private void Microwave()
|
|
{
|
|
frenbutton.onClick.AddListener(() =>
|
|
{
|
|
Frequencyiamge.gameObject.SetActive(false);
|
|
});
|
|
|
|
foreach (Toggle toggle in toggles)
|
|
{
|
|
toggle.onValueChanged.AddListener(delegate {
|
|
FrequencyBandsValueChanged(toggle);
|
|
});
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 频段设置方法
|
|
/// </summary>
|
|
/// <param name="change"></param>
|
|
void FrequencyBandsValueChanged(Toggle change)
|
|
{
|
|
if (change.isOn)
|
|
{
|
|
Frequency = change.transform.name;
|
|
int layerValue = LayerMask.NameToLayer(Frequency);
|
|
Camera1.cullingMask = (1 << layerValue);
|
|
string nowData = GetSyncDataThree();
|
|
MyNetMQClient.instance.Send(nowData);
|
|
equipmentCommon.SetDatabaseInfo("scan_rate", Frequency);
|
|
//DeviceManager.Instance.send2roomStr.Enqueue(nowData);
|
|
//MQTTManager.instance.SendData(MQTTManager.instance.SweepFrequencyBand, nowData);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public void CameraFrequency(string _frequency)
|
|
{
|
|
int layerValue = LayerMask.NameToLayer(_frequency);
|
|
Frequency = _frequency;
|
|
Camera1.cullingMask = (1 << layerValue);
|
|
}
|
|
/// <summary>
|
|
/// 设置扫描频段同步
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
protected string GetSyncDataThree()
|
|
{
|
|
UploadLog();
|
|
return string.Format("{0},{1},{2},{3}", "SweepFrequencyBand", "PPTC", equipmentCommon.deviceID, Frequency);
|
|
}
|
|
|
|
/// <summary>
|
|
///上传日志
|
|
/// </summary>
|
|
/// <param name="deviceID"></param>
|
|
public void UploadLog()
|
|
{
|
|
string currentTime = System.DateTime.Now.ToString();
|
|
List<UploadLogMain> uploadLogMains = new List<UploadLogMain>();
|
|
UploadLogMain uploadLogMain = new UploadLogMain();
|
|
uploadLogMain.PracticeId = GlobalFlag.practiceSubjectID;
|
|
uploadLogMain.ThinkId = GlobalFlag.currentThinkId;
|
|
string log = currentTime + " " + transform.name + "(" + equipmentCommon.deviceID + ")频段设置为" + Frequency;
|
|
uploadLogMain.log = log;
|
|
uploadLogMains.Add(uploadLogMain);
|
|
string uploadLogMainJson = JsonConvert.SerializeObject(uploadLogMains);
|
|
WWWForm wWWForm = new WWWForm();
|
|
wWWForm.AddField("data", uploadLogMainJson);
|
|
StartCoroutine(PostString(Url_Addpracticelog, wWWForm, data =>
|
|
{
|
|
//Debug.Log(data);
|
|
}));
|
|
}
|
|
/// <summary>
|
|
/// 演习是否启动
|
|
/// </summary>
|
|
void OnActivationChangedHandler(bool bol)
|
|
{
|
|
if (bol)
|
|
{
|
|
Debug.Log("开始演练");
|
|
}
|
|
else
|
|
{
|
|
Debug.Log("结束演练");
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 读取设备参数
|
|
/// </summary>
|
|
public void FillInTheData(List<List_paraItem> weaponitemone)
|
|
{
|
|
for (int i = 0; i < weaponitemone.Count; i++)
|
|
{
|
|
switch (weaponitemone[i].para_name)
|
|
{
|
|
case "探测距离:":
|
|
Detectionrange = weaponitemone[i].para_value;
|
|
Radius = float.Parse(Detectionrange);
|
|
Camera1.orthographicSize = Radius * 1000;
|
|
break;
|
|
case "批目标处理能力:":
|
|
Batchcapacity = weaponitemone[i].para_value;
|
|
break;
|
|
case "侦测频率:":
|
|
string[] str = weaponitemone[i].para_value.Split(',');
|
|
if (str.Length > 0)
|
|
{
|
|
for (int j = 0; j < str.Length; j++)
|
|
{
|
|
switch (str[j])
|
|
{
|
|
case "0":
|
|
frequency += "UHF" + ",";
|
|
break;
|
|
case "1":
|
|
frequency += "L" + ",";
|
|
break;
|
|
case "2":
|
|
frequency += "S" + ",";
|
|
break;
|
|
case "3":
|
|
frequency += "C" + ",";
|
|
break;
|
|
case "4":
|
|
frequency += "X" + ",";
|
|
break;
|
|
case "5":
|
|
frequency += "Ku" + ",";
|
|
break;
|
|
case "6":
|
|
frequency += "Ka" + ",";
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
break;
|
|
case "探测成功率:":
|
|
Detectionsuccessrate = weaponitemone[i].para_value;
|
|
break;
|
|
case "探测响应时间:":
|
|
Responsetime = weaponitemone[i].para_value;
|
|
break;
|
|
case "测向精度:":
|
|
Directionfindingaccuracy = weaponitemone[i].para_value;
|
|
break;
|
|
case "最小探测速度:":
|
|
Minimumdetectionvelocity = weaponitemone[i].para_value;
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
Microwavefrequency();
|
|
}
|
|
|
|
private void Microwavefrequency()
|
|
{
|
|
if (frequency.Length > 0)
|
|
{
|
|
string[] str = frequency.Split(',');
|
|
for (int i = 0; i < str.Length; i++)
|
|
{
|
|
var _tog = toggles.Find(x => x.transform.name == str[i]);
|
|
if (_tog)
|
|
_tog.gameObject.SetActive(true);
|
|
}
|
|
}
|
|
}
|
|
|
|
public Collider[] colliders;
|
|
|
|
public List<Collider> attackColliders1 = new List<Collider>();
|
|
/// <summary>
|
|
/// 搜索范围内的无人机
|
|
/// </summary>
|
|
private void Search()
|
|
{
|
|
attackColliders1.Clear();
|
|
colliders = Physics.OverlapSphere(transform.position, float.Parse(Detectionrange) * 1000);
|
|
for (int i = 0; i < colliders.Length; i++)
|
|
{
|
|
if (colliders[i].transform.gameObject.tag == "WRJ")
|
|
{
|
|
//Debug.LogError("进来了");
|
|
UnmannedAerialVehicle unmannedAerialVehicle = null;
|
|
if (colliders[i].GetComponent<UnmannedAerialVehicle>())
|
|
{
|
|
attackColliders1.Add(colliders[i]);
|
|
unmannedAerialVehicle = colliders[i].GetComponent<UnmannedAerialVehicle>();
|
|
if (unmannedAerialVehicle != null&& unmannedAerialVehicle.unmannedAerialVehicleManage.dataLinkCommunicationFrequency== Frequency)
|
|
{
|
|
foreach(var terrestrialRadioInterferenceManger in TerrestrialRadioInterferenceManger.terrestrialRadioInterferenceMangers)
|
|
{
|
|
if (terrestrialRadioInterferenceManger != null)
|
|
{
|
|
Vector3 lookPos = new Vector3(unmannedAerialVehicle.transform.position.x, terrestrialRadioInterferenceManger.transform.position.y, unmannedAerialVehicle.transform.position.z);
|
|
terrestrialRadioInterferenceManger.transform.LookAt(lookPos);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
private void OnMouseDown()
|
|
{
|
|
if (!GlobalFlag.isStartRehearsing && GlobalFlag.blueOrRed == 1)
|
|
{
|
|
GameManager.Instance.GetAllImportance();
|
|
EquipmentCommon equipmentCommon1 = GetComponent<EquipmentCommon>();
|
|
if (equipmentCommon.deviceID == equipmentCommon1.deviceID)
|
|
{
|
|
Frequencyiamge.transform.position = Camera.main.WorldToScreenPoint(transform.position);
|
|
Frequencyiamge.gameObject.SetActive(true);
|
|
}
|
|
}
|
|
if (equipmentCommon.isPlayer)
|
|
{
|
|
SpectrumdetectionUI.SetActive(true);
|
|
}
|
|
//SpectrumdetectionUI.SetActive(true);
|
|
}
|
|
private void OnDestroy()
|
|
{
|
|
for(int i = 0; i < spectrumdetections.Count; i++)
|
|
{
|
|
if (spectrumdetections[i] == null)
|
|
{
|
|
spectrumdetections.RemoveAt(i);
|
|
}
|
|
}
|
|
Destroy(Frequencyiamge.gameObject);
|
|
OnActivationChanged -= OnActivationChangedHandler;
|
|
}
|
|
}
|