using System.Collections; using System.Collections.Generic; using UnityEngine; /// /// 地面无线电干扰控制 /// public class TerrestrialRadioInterferenceManger : MonoBehaviour { /// /// 是否正在预演 /// public bool isStartRehearsing = false; /// /// 测试用 /// public string msg; /// /// 测试接受数据 /// private Weaponitemone weaponitemones; #region 地面无线电干扰数据 /// /// 干扰频率 /// public string InterferingFrequency; /// /// 干扰模式 /// public string InterferenceMode; /// /// 发射功率 /// public string TransmittedPower; /// /// 干扰角度 /// public string InterferenceAngle; /// /// 干扰距离 /// public string InterferenceDistance; #endregion public float detectionRadius = 5f; // 检测范围半径 // Start is called before the first frame update void Start() { weaponitemones = Newtonsoft.Json.JsonConvert.DeserializeObject(msg); FillInTheData(weaponitemones);//测试写入 //InvokeRepeating("RadioDisturbance", 1, 5);//测试用 } // Update is called once per frame void Update() { } /// /// 数据写入 /// /// public void FillInTheData(Weaponitemone weaponitemone) { for (int i = 0; i < weaponitemone.data.Count; i++) { switch (weaponitemone.data[i].para_name) { case "干扰频率:": InterferingFrequency = weaponitemone.data[i].para_value; break; case "干扰模式:": InterferenceMode = weaponitemone.data[i].para_value; break; case "发射功率:": TransmittedPower = weaponitemone.data[i].para_value; break; case "干扰角度:": InterferenceAngle = weaponitemone.data[i].para_value; break; case "干扰距离:": InterferenceDistance = weaponitemone.data[i].para_value; break; default: break; } } } /// /// 开启无线电干扰 /// public void RadioDisturbance() { Collider[] colliders = Physics.OverlapSphere(transform.position, detectionRadius); // 检索范围内的所有碰撞体 foreach (Collider col in colliders) { if (col.transform.tag == "WRJ") { //Debug.Log("检测到无人机: " + col.name); UnmannedAerialVehicle unmannedAerialVehicle = col.GetComponent(); if (unmannedAerialVehicle) { Debug.Log(col.name+"数据链通信频点...:" + unmannedAerialVehicle.dataLinkCommunicationFrequency); if(unmannedAerialVehicle.dataLinkCommunicationFrequency== InterferingFrequency) { Debug.Log("干扰...:"+ col.name + "成功。"); unmannedAerialVehicle.BeAssaulted("无线电干扰"); } } } } } }