using AdamThinkDevicesData; using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.UI; public class Spectrumdetection : MonoBehaviour { 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 camera; void Start() { equipmentCommon = GetComponent(); // 订阅布尔值变化事件 OnActivationChanged += OnActivationChangedHandler; _isStartRehearsing = GlobalFlag.isStartRehearsing; Microwave(); } private void Microwave() { frenbutton.onClick.AddListener(() => { Frequencyiamge.gameObject.SetActive(false); }); toggle1.onValueChanged.AddListener((ison) => { if (ison) { Frequency = "HUF"; camera.cullingMask = 1 << 16; } }); toggle2.onValueChanged.AddListener((ison) => { if (ison) { Frequency = "L"; camera.cullingMask = 1 << 17; } }); toggle3.onValueChanged.AddListener((ison) => { if (ison) { Frequency = "S"; camera.cullingMask = 1 << 18; } }); toggle4.onValueChanged.AddListener((ison) => { if (ison) { Frequency = "C"; camera.cullingMask = 1 << 19; } }); toggle5.onValueChanged.AddListener((ison) => { if (ison) { Frequency = "X"; camera.cullingMask = 1 << 20; } }); toggle6.onValueChanged.AddListener((ison) => { if (ison) { Frequency = "Ku"; camera.cullingMask = 1 << 21; } }); toggle7.onValueChanged.AddListener((ison) => { if (ison) { Frequency = "Ka"; camera.cullingMask = (1 << 22); } }); } /// /// 演习是否启动 /// 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; 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; } } } } void Update() { Search();//微波武器朝向无人机 Emittedray(); } /// /// 点击物体生成页面 /// /// private void Emittedray() { if (Input.GetMouseButtonDown(0) && UIBootstrap.Instance.GetRoleByIDPracticeId(GlobalFlag.practiceSeatId) != "0") { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (EventSystem.current.IsPointerOverGameObject()) { return; } if (Physics.Raycast(ray, out hit, 1000)) { if (hit.collider.GetComponent()) { EquipmentCommon equipmentCommon1 = hit.collider.GetComponent(); if (equipmentCommon.deviceID == equipmentCommon1.deviceID) { Frequencyiamge.transform.position = Camera.main.WorldToScreenPoint(hit.point); Frequencyiamge.gameObject.SetActive(true); } } } } } /// /// 搜索范围内的无人机 /// private void Search() { Collider[] colliders = Physics.OverlapSphere(transform.position, float.Parse(Detectionrange) * 100); 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 = colliders[i].GetComponent(); if (unmannedAerialVehicle != null) { Microwaveweapon microwaveweapon = Microwaveweapon.MicrowaveweaponList.Find(x => (x != null && x.ismicow == false)); if (microwaveweapon) { microwaveweapon.ismicow = true; microwaveweapon.miceopos = unmannedAerialVehicle.transform; microwaveweapon.Orientation(); } } } } } } private void OnMouseDown() { if (equipmentCommon.isPlayer) { SpectrumdetectionUI.SetActive(true); } //SpectrumdetectionUI.SetActive(true); } private void OnDestroy() { Destroy(Frequencyiamge.gameObject); OnActivationChanged -= OnActivationChangedHandler; } }