using System.Collections; using System.Collections.Generic; using UnityEngine; using AdamThinkDevicesData; using AdamSync; using System.Linq; using UnityEngine.UI; using System; /// /// 雷达控制 /// public class RadarManger : MonoBehaviour { public EquipmentCommon equipmentCommon; #region 启动暂停 private bool _isStartRehearsing = false; /// /// 是否正在预演 /// public bool isStartRehearsing { get { return _isStartRehearsing; } set { if (_isStartRehearsing != value) { _isStartRehearsing = value; OnActivationChanged?.Invoke(_isStartRehearsing); } } } /// /// 布尔值变化时触发的事件 /// public event System.Action OnActivationChanged; /// /// 协程对象 /// private Coroutine timerCoroutine; /// /// 定时器运行状态 /// private bool isTimerRunning = false; /// /// 间隔时间 /// public float interval = 5.0f; #endregion /// /// 雷达UI预制体 /// public GameObject RadarUiPrefab; /// /// 雷达UI /// public GameObject RadarUi; /// /// 雷达动画 /// public Animator aniRandar; /// /// 雷达UI动画播放 /// public Animator aniRandarUI; #region 雷达数据 /// /// 转台转速 /// public string TurntableSpeed; /// /// 探测距离 /// public string DetectionRange; /// /// 近盲区 /// public string NearBlindArea; /// /// 批量标处理能力 /// public string BatchStandardProcessingCapability; /// /// 探测成功率 /// public string DetectionSuccessRate; /// /// 最小探测速度 /// public string MinimumDetectionVelocity; /// /// 距离分辨率 /// public string RangeResolution; /// /// 方位分辨率 /// public string AzimuthResolution; /// /// 方位波束宽度 /// public string AzimuthBeamwidth; /// /// 俯仰波束宽度 /// public string PitchBeamwidth; #endregion /// /// 检测范围半径 /// public float detectionRadius = 5f; // /// /// 近盲区 /// public float nearBlindArea = 5f; // /// /// 批量标处理能力 /// public int NumberOfProbes = 0; /// /// 渲染小地图摄像机 /// public Camera minCamera; /// /// 激活面板预设体 /// public Image imageprs; /// /// /// public RawImage rawImage; /// /// /// private bool onlyOne = true; /// /// 接收无人机显示在地图上的参数大小 /// public float Mapsize; void Awake() { //失活摄像机 minCamera.gameObject.SetActive(false); } void Start() { equipmentCommon = GetComponent(); // 订阅布尔值变化事件 OnActivationChanged += OnActivationChangedHandler; //DroneViewDisplay.Instance.CreateUI(equipmentCommon.deviceID, minCamera, rawImage); } void Update() { //老师点了开始演习就激活摄像机 if (isStartRehearsing) { minCamera.gameObject.SetActive(true); } if (onlyOne && equipmentCommon.deviceID.Length > 10) { onlyOne = false; DroneViewDisplay.Instance.CreateUI(equipmentCommon.deviceID, minCamera, rawImage); } Deadzone();//雷达盲区 if (Mapsize >1) { Dotsize();//改变雷达地图上显示无人机大小 } } private void Dotsize() { GameObject[] wrjdtdx = GameObject.FindGameObjectsWithTag("WRJ"); for (int i = 0; i < wrjdtdx.Length; i++) { if (wrjdtdx[i].gameObject.tag=="WRJ"&& equipmentCommon.isPlayer) { UnmannedAerialVehicleManage unmannedAerialVehicleManage = wrjdtdx[i].GetComponent(); if (unmannedAerialVehicleManage&& unmannedAerialVehicleManage.gamemap) { unmannedAerialVehicleManage.gamemap.transform.localScale = new Vector3(Mapsize,1,Mapsize); Debug.Log("改变了无人机显示大小"); } } } } #region 启动暂停 /// /// 导条变化调用 /// /// void OnActivationChangedHandler(bool newValue) { if (newValue) { Debug.Log("开始检索"); StartTimer(); } else { Debug.Log("停止检索"); StopTimer(); } } IEnumerator Timer() { while (true) { //Debug.Log("Timer fired at: " + Time.time); yield return new WaitForSeconds(5); // 等待一段时间后继续执行 RetrievalUAV(); //Deadzone(); } } /// /// 开启 /// public void StartTimer() { if (equipmentCommon.isPlayer && timerCoroutine == null) { timerCoroutine = StartCoroutine(Timer()); isTimerRunning = true; } } /// s /// 停止 /// public void StopTimer() { if (equipmentCommon.isPlayer && timerCoroutine != null) { StopCoroutine(timerCoroutine); timerCoroutine = null; isTimerRunning = false; } } #endregion void CreateRadarUI() { imageprs.transform.localScale = Vector3.zero; aniRandarUI = imageprs.GetComponent(); RadarRotationSpeed(TurntableSpeed); } /// /// 数据写入 /// /// public void FillInTheData(List weaponitemone) { for (int i = 0; i < weaponitemone.Count; i++) { switch (weaponitemone[i].para_name) { case "转台转速:": TurntableSpeed = weaponitemone[i].para_value; //RadarRotationSpeed(TurntableSpeed); break; case "探测距离:": DetectionRange = weaponitemone[i].para_value; Showmap(float.Parse(DetectionRange)); detectionRadius = float.Parse(DetectionRange) * 1000; minCamera.orthographicSize = detectionRadius; break; case "近盲区:": NearBlindArea = weaponitemone[i].para_value; //Debug.LogError(NearBlindArea); nearBlindArea = float.Parse(NearBlindArea); break; case "批量标处理能力:": BatchStandardProcessingCapability = weaponitemone[i].para_value; NumberOfProbes = int.Parse(BatchStandardProcessingCapability); break; case "探测成功率:": DetectionSuccessRate = weaponitemone[i].para_value; break; case "最小探测速度:": MinimumDetectionVelocity = weaponitemone[i].para_value; break; case "距离分辨率:": RangeResolution = weaponitemone[i].para_value; break; case "方位分辨率:": AzimuthResolution = weaponitemone[i].para_value; break; case "方位波束宽度:": AzimuthBeamwidth = weaponitemone[i].para_value; break; case "俯仰波束宽度:": PitchBeamwidth = weaponitemone[i].para_value; break; default: break; } } } private void Showmap(float size) { switch (size) { case 1: Mapsize = 30; break; case 2: Mapsize = 60; break; case 3: Mapsize = 90; break; case 4: Mapsize = 120; break; case 5: Mapsize = 150; break; default: break; } } /// /// 雷达转动速度 /// public void RadarRotationSpeed(string speed) { float newSpeed = float.Parse(speed); if (newSpeed <= 0) return; if (aniRandar) { aniRandar.speed = (1 / newSpeed); // 改变动画的播放速度为新速度值 } if (aniRandarUI) { aniRandarUI.speed = (1 / newSpeed); // 改变动画的播放速度为新速度值 } } public List colliders = new List(); public List attackColliders1 = new List(); /// /// 检索 /// public void RetrievalUAV() { colliders = Physics.OverlapSphere(transform.position, detectionRadius).ToList(); // 检索范围内的所有碰撞体 var colliders2 = colliders.FindAll(x => x.tag == "WRJ"); if (colliders2.Count > 0) { for (int i = 0; i < colliders2.Count; i++) { UnmannedAerialVehicle unmannedAerialVehicle = colliders2[i].GetComponent(); if (unmannedAerialVehicle) { bool isnearBlindArea = Vector3.Distance(transform.position, unmannedAerialVehicle.transform.position) > nearBlindArea; if (!isnearBlindArea) continue; attackColliders1.Add(colliders[i]); LaserFireControlPlatformManger laserFireControlPlatformManger = LaserFireControlPlatformManger.laserFireControlPlatformMangers.Find(x => (x != null&& x.isLasing == false&& x.lasertime <= 0)); Microwaveweapon microwaveweapon = Microwaveweapon.MicrowaveweaponList.Find(x => x != null && x.ismicow == false); if (laserFireControlPlatformManger) { laserFireControlPlatformManger.lasertime = laserFireControlPlatformManger.storageIntervalTime+1.5f; laserFireControlPlatformManger.isLasing = true; laserFireControlPlatformManger.targetPoint = unmannedAerialVehicle.transform; laserFireControlPlatformManger.Lasing(); } else if (microwaveweapon) { microwaveweapon.ismicow = true; microwaveweapon.miceopos = unmannedAerialVehicle.transform; microwaveweapon.Orientation(); } } } } } /// /// 雷达盲区让目标消失在地图上 /// private void Deadzone() { if (float.Parse(NearBlindArea) > 0) { Collider[] colliders = Physics.OverlapSphere(transform.position, float.Parse(NearBlindArea)); for (int i = 0; i < colliders.Length; i++) { if (colliders[i].transform.gameObject.tag == "WRJ") { //Debug.Log("进来了" + Vector3.Distance(transform.position, colliders[i].transform.position)); UnmannedAerialVehicleManage unmannedAerialVehicle = colliders[i].GetComponent(); if (unmannedAerialVehicle) { unmannedAerialVehicle.gamemap.SetActive(false); } } } } } /// /// 检测鼠标点击的方法 /// private void OnMouseDown() { if (equipmentCommon.isPlayer && GlobalFlag.blueOrRed == 1) { GameManager.Instance.GetAllImportance(); imageprs.gameObject.SetActive(true); } } private void OnDestroy() { Destroy(RadarUi.gameObject); OnActivationChanged -= OnActivationChangedHandler; } }