122 lines
3.5 KiB
C#
122 lines
3.5 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
/// <summary>
|
|
/// 地面无线电干扰控制
|
|
/// </summary>
|
|
public class TerrestrialRadioInterferenceManger : MonoBehaviour
|
|
{
|
|
/// <summary>
|
|
/// 是否正在预演
|
|
/// </summary>
|
|
public bool isStartRehearsing = false;
|
|
|
|
/// <summary>
|
|
/// 测试用
|
|
/// </summary>
|
|
public string msg;
|
|
/// <summary>
|
|
/// 测试接受数据
|
|
/// </summary>
|
|
private Weaponitemone weaponitemones;
|
|
|
|
#region 地面无线电干扰数据
|
|
/// <summary>
|
|
/// 干扰频率
|
|
/// </summary>
|
|
public string InterferingFrequency;
|
|
/// <summary>
|
|
/// 干扰模式
|
|
/// </summary>
|
|
public string InterferenceMode;
|
|
/// <summary>
|
|
/// 发射功率
|
|
/// </summary>
|
|
public string TransmittedPower;
|
|
/// <summary>
|
|
/// 干扰角度
|
|
/// </summary>
|
|
public string InterferenceAngle;
|
|
/// <summary>
|
|
/// 干扰距离
|
|
/// </summary>
|
|
public string InterferenceDistance;
|
|
|
|
#endregion
|
|
|
|
public float detectionRadius = 5f; // 检测范围半径
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
weaponitemones = Newtonsoft.Json.JsonConvert.DeserializeObject<Weaponitemone>(msg);
|
|
FillInTheData(weaponitemones);//测试写入
|
|
|
|
//InvokeRepeating("RadioDisturbance", 1, 5);//测试用
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 数据写入
|
|
/// </summary>
|
|
/// <param name="weaponitemone"></param>
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 开启无线电干扰
|
|
/// </summary>
|
|
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<UnmannedAerialVehicle>();
|
|
if (unmannedAerialVehicle)
|
|
{
|
|
Debug.Log(col.name+"数据链通信频点...:" + unmannedAerialVehicle.dataLinkCommunicationFrequency);
|
|
if(unmannedAerialVehicle.dataLinkCommunicationFrequency== InterferingFrequency)
|
|
{
|
|
Debug.Log("干扰...:"+ col.name + "成功。");
|
|
unmannedAerialVehicle.BeAssaulted("无线电干扰");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|