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; /// /// 频谱探测 /// public class Spectrumdetection : MonoBehaviour { public static List spectrumdetections=new List(); public EquipmentCommon equipmentCommon; #region 频谱探测的参数 /// /// 探测距离 /// public string Detectionrange; /// /// 批目标处理能力 /// public string Batchcapacity; /// /// 探测频率 /// public string frequency; /// /// 探测成功率 /// public string Detectionsuccessrate; /// /// 探测响应时间 /// public string Responsetime; /// /// 测向精度 /// public string Directionfindingaccuracy; /// /// 最小探测速度 /// public string Minimumdetectionvelocity; #endregion private bool _isStartRehearsing = false; /// /// 是否正在演练 /// public bool isStartRehearsing { get { return _isStartRehearsing; } set { if (_isStartRehearsing != value) { _isStartRehearsing = value; OnActivationChanged?.Invoke(_isStartRehearsing); } } } /// /// 布尔值变化时触发时间 /// public event System.Action OnActivationChanged; /// /// /// public GameObject SpectrumdetectionUI; /// /// 显示UI频段页面 /// public Image Frequencyiamge; /// /// 关闭按钮 /// public Button frenbutton; /// /// 选择最终的频段 /// public Toggle toggle1, toggle2, toggle3, toggle4, toggle5, toggle6, toggle7; /// /// 最终的波段 /// public string Frequency; /// /// 摄像机显示层数 /// public Camera Camera1; /// /// /// public RawImage rawImage; /// /// /// private bool onlyOne = true; /// /// 接收探测范围 /// public static float Radius; void Start() { Camera1.gameObject.SetActive(false); spectrumdetections.Add(this); equipmentCommon = GetComponent(); // 订阅布尔值变化事件 OnActivationChanged += OnActivationChangedHandler; _isStartRehearsing = GlobalFlag.isStartRehearsing; Microwave(); //DroneViewDisplay.Instance.CreateUI(equipmentCommon.deviceID, camera, rawImage); } void Update() { //if (onlyOne && equipmentCommon.deviceID.Length > 10) //{ // onlyOne = false; // DroneViewDisplay.Instance.CreateUI(equipmentCommon.deviceID, camera, rawImage); //} if (isStartRehearsing) { Camera1.gameObject.SetActive(true); Search();//微波武器朝向无人机 } } private void Microwave() { frenbutton.onClick.AddListener(() => { Frequencyiamge.gameObject.SetActive(false); }); toggle1.onValueChanged.AddListener((ison) => { if (ison) { Frequency = "UHF"; Camera1.cullingMask = 1 << 16; SweepFrequencyBandTo(); } }); toggle2.onValueChanged.AddListener((ison) => { if (ison) { Frequency = "L"; Camera1.cullingMask = 1 << 17; SweepFrequencyBandTo(); } }); toggle3.onValueChanged.AddListener((ison) => { if (ison) { Frequency = "S"; Camera1.cullingMask = 1 << 18; SweepFrequencyBandTo(); } }); toggle4.onValueChanged.AddListener((ison) => { if (ison) { Frequency = "C"; Camera1.cullingMask = 1 << 19; SweepFrequencyBandTo(); } }); toggle5.onValueChanged.AddListener((ison) => { if (ison) { Frequency = "X"; Camera1.cullingMask = 1 << 20; SweepFrequencyBandTo(); } }); toggle6.onValueChanged.AddListener((ison) => { if (ison) { Frequency = "Ku"; Camera1.cullingMask = 1 << 21; SweepFrequencyBandTo(); } }); toggle7.onValueChanged.AddListener((ison) => { if (ison) { Frequency = "Ka"; Camera1.cullingMask = (1 << 22); SweepFrequencyBandTo(); } }); } public void SweepFrequencyBandTo() { string nowData = GetSyncDataThree(); //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); } /// /// 设置扫描频段同步 /// /// protected string GetSyncDataThree() { UploadLog(); return string.Format("{0},{1},{2},{3}", "SweepFrequencyBand", "PPTC", equipmentCommon.deviceID, Frequency); } /// ///上传日志 /// /// public void UploadLog() { string currentTime = System.DateTime.Now.ToString(); List uploadLogMains = new List(); 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); })); } /// /// 演习是否启动 /// void OnActivationChangedHandler(bool bol) { if (bol) { Debug.Log("开始演练"); } else { Debug.Log("结束演练"); } } /// /// 读取设备参数 /// public void FillInTheData(List 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++) { switch (str[i]) { case "UHF": toggle1.gameObject.SetActive(true); break; case "L": toggle2.gameObject.SetActive(true); break; case "S": toggle3.gameObject.SetActive(true); break; case "C": toggle4.gameObject.SetActive(true); break; case "X": toggle5.gameObject.SetActive(true); break; case "Ku": toggle6.gameObject.SetActive(true); break; case "Ka": toggle7.gameObject.SetActive(true); break; default: break; } } } } public Collider[] colliders; public List attackColliders1 = new List(); /// /// 搜索范围内的无人机 /// 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()) { attackColliders1.Add(colliders[i]); unmannedAerialVehicle = colliders[i].GetComponent(); if (unmannedAerialVehicle != null&& unmannedAerialVehicle.unmannedAerialVehicleManage.dataLinkCommunicationFrequency== Frequency) { foreach(var terrestrialRadioInterferenceManger in TerrestrialRadioInterferenceManger.terrestrialRadioInterferenceMangers) { 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(); 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; } }