1235 lines
40 KiB
C#
1235 lines
40 KiB
C#
using DG.Tweening;
|
||
using System;
|
||
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using UnityEngine;
|
||
using AdamThinkDevicesData;
|
||
using System.Linq;
|
||
using static InterfaceManager;
|
||
using Newtonsoft.Json;
|
||
using PData;
|
||
using UnityEngine.UI;
|
||
|
||
public enum WRJModel
|
||
{
|
||
无人机,
|
||
光学无人机,
|
||
电子侦察无人机,
|
||
自杀式无人机
|
||
}
|
||
/// <summary>
|
||
/// 单个无人机蜂群控制
|
||
/// </summary>
|
||
public class UnmannedAerialVehicleManage : MonoBehaviour
|
||
{
|
||
public WRJModel wrjModel = WRJModel.无人机;
|
||
/// <summary>
|
||
/// 无人机状态
|
||
/// </summary>
|
||
public Pattern pattern = Pattern.待机;
|
||
|
||
public static List<UnmannedAerialVehicleManage> unmannedAerialVehicleManages = new List<UnmannedAerialVehicleManage>();
|
||
#region 启动暂停
|
||
private bool _isStartRehearsing = false;
|
||
/// <summary>
|
||
/// 是否正在预演
|
||
/// </summary>
|
||
public bool isStartRehearsing
|
||
{
|
||
get { return _isStartRehearsing; }
|
||
set
|
||
{
|
||
if (_isStartRehearsing != value)
|
||
{
|
||
_isStartRehearsing = value;
|
||
OnActivationChanged?.Invoke(_isStartRehearsing);
|
||
}
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// 布尔值变化时触发的事件
|
||
/// </summary>
|
||
public event System.Action<bool> OnActivationChanged;
|
||
|
||
/// <summary>
|
||
/// 间隔时间
|
||
/// </summary>
|
||
public float interval = 5.0f;
|
||
#endregion
|
||
|
||
public EquipmentCommon equipmentCommon;
|
||
|
||
|
||
/// <summary>
|
||
/// 打组ID
|
||
/// </summary>
|
||
public int groupId = -1;
|
||
|
||
public bool isGroup = false;
|
||
|
||
/// <summary>
|
||
/// 无人机预制体
|
||
/// </summary>
|
||
public GameObject UAVPrefab;
|
||
/// <summary>
|
||
/// 编队无人机数量
|
||
/// </summary>
|
||
public int totalObjects = 30; // 总共的物体数量
|
||
/// <summary>
|
||
/// 所有子物体无人机
|
||
/// </summary>
|
||
public List<UnmannedAerialVehicle> unmannedAerialVehicles = new List<UnmannedAerialVehicle>();
|
||
/// <summary>
|
||
/// 频段设置
|
||
/// </summary>
|
||
public List<Toggle> togFrequencyBands = new List<Toggle>();
|
||
/// <summary>
|
||
/// 探测频段设置
|
||
/// </summary>
|
||
public List<Toggle> togSurveillanceFrequencyBands = new List<Toggle>();
|
||
/// <summary>
|
||
/// 线预制体
|
||
/// </summary>
|
||
public GameObject LinePrefab;
|
||
/// <summary>
|
||
/// 航线
|
||
/// </summary>
|
||
public GameObject airRoute;
|
||
/// <summary>
|
||
/// 已有路径
|
||
/// </summary>
|
||
public Queue<Vector3> positions = new Queue<Vector3>();
|
||
public Vector3 endPosition = new Vector3();
|
||
/// <summary>
|
||
/// 飞行速度
|
||
/// </summary>
|
||
public float FireSpeed = 20.0f;
|
||
|
||
/// <summary>
|
||
/// 检测范围半径
|
||
/// </summary>
|
||
public float detectionRadius = 500; //
|
||
/// <summary>
|
||
/// 是否正在攻击目标
|
||
/// </summary>
|
||
public bool isEngagedTarget = false;
|
||
|
||
/// <summary>
|
||
/// 光学无人机
|
||
/// </summary>
|
||
public Camera gxWRJCamera;
|
||
/// <summary>
|
||
/// 电子侦察无人机
|
||
/// </summary>
|
||
public Camera dzWRJCamera;
|
||
|
||
#region 无人机数据
|
||
/// <summary>
|
||
/// 续航时间
|
||
/// </summary>
|
||
public string batteryLife;
|
||
/// <summary>
|
||
/// 抗风等级
|
||
/// </summary>
|
||
public string classificationWindResistance;
|
||
/// <summary>
|
||
/// 最大飞行速度
|
||
/// </summary>
|
||
public string maximumFlyingSpeed;
|
||
/// <summary>
|
||
/// RCS
|
||
/// </summary>
|
||
public string RCS;
|
||
/// <summary>
|
||
/// 卫星定位频点
|
||
/// </summary>
|
||
public string satellitePositioningFrequency;
|
||
/// <summary>
|
||
/// 数据链通信频点
|
||
/// </summary>
|
||
public string dataLinkCommunicationFrequency;
|
||
/// <summary>
|
||
/// 电子侦察能力
|
||
/// </summary>
|
||
public string electronicReconnaissanceCapability;
|
||
/// <summary>
|
||
/// 光学侦察能力
|
||
/// </summary>
|
||
public string opticalReconnaissanceCapability;
|
||
|
||
#endregion
|
||
/// <summary>
|
||
/// 频段设置面板
|
||
/// </summary>
|
||
public GameObject FrequencyBand;
|
||
/// <summary>
|
||
/// 侦察频段设置面板
|
||
/// </summary>
|
||
public GameObject SurveillanceFrequencyBand;
|
||
|
||
/// <summary>
|
||
/// 显示频谱地图上的位置
|
||
/// </summary>
|
||
public GameObject gamePos;
|
||
/// <summary>
|
||
/// 显示在雷达上的位置
|
||
/// </summary>
|
||
public GameObject gamemap;
|
||
/// <summary>
|
||
/// 频谱显示无人机大小
|
||
/// </summary>
|
||
public float reveal;
|
||
/// <summary>
|
||
/// 地面层数
|
||
/// </summary>
|
||
public LayerMask Ground;
|
||
/// <summary>
|
||
/// 改变频谱探测地图上显示点的大小
|
||
/// </summary>
|
||
public bool boisp = true;
|
||
void Start()
|
||
{
|
||
gamePos.gameObject.SetActive(false);
|
||
MatrixFormation(30, 1);
|
||
for (int i = 0; i < unmannedAerialVehicles.Count; i++)
|
||
{
|
||
unmannedAerialVehicles[i].serialNumber = (i + 1).ToString();
|
||
}
|
||
unmannedAerialVehicleManages.Add(this);
|
||
equipmentCommon = GetComponent<EquipmentCommon>();
|
||
//Formation(1);//默认阵型
|
||
// 订阅布尔值变化事件
|
||
OnActivationChanged += OnActivationChangedHandler;
|
||
|
||
//频段设置
|
||
foreach (Toggle toggle in togFrequencyBands)
|
||
{
|
||
toggle.onValueChanged.AddListener(delegate { FrequencyBandsValueChanged(toggle); });
|
||
}
|
||
//探测频段设置
|
||
foreach (Toggle toggle in togSurveillanceFrequencyBands)
|
||
{
|
||
toggle.onValueChanged.AddListener(delegate { SurveillanceFrequencyBandsValueChanged(toggle); });
|
||
}
|
||
|
||
}
|
||
|
||
private void Mapdisplay()
|
||
{
|
||
if (reveal > 1)
|
||
{
|
||
gamePos.transform.localScale = new Vector3(reveal, 1, reveal);
|
||
boisp = false;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 设置组得标志
|
||
/// </summary>
|
||
public void SetGroupTips(int index)
|
||
{
|
||
UnmannedAerialVehicle uav = unmannedAerialVehicles[0];
|
||
if (uav != null)
|
||
{
|
||
uav.tips.text = uav.tips.text + "\n" + "组" + index.ToString();
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// 设置标志和单个信息
|
||
/// </summary>
|
||
public void SetGroupTipsAndDatabaseInfo(int index)
|
||
{
|
||
SetGroupTips(index);
|
||
equipmentCommon.SetDatabaseInfo("bdxx", index.ToString());
|
||
}
|
||
|
||
|
||
|
||
|
||
/// <summary>
|
||
/// 频段设置
|
||
/// </summary>
|
||
/// <param name="change"></param>
|
||
void FrequencyBandsValueChanged(Toggle change)
|
||
{
|
||
if (change.isOn)
|
||
{
|
||
dataLinkCommunicationFrequency = change.transform.name;
|
||
int layerValue = LayerMask.NameToLayer(dataLinkCommunicationFrequency);
|
||
gamePos.layer = layerValue;
|
||
string nowData = GetSyncDataTwo();
|
||
MyNetMQClient.instance.Send(nowData);
|
||
equipmentCommon.SetDatabaseInfo("my_rate", dataLinkCommunicationFrequency);
|
||
//DeviceManager.Instance.send2roomStr.Enqueue(nowData);
|
||
//MQTTManager.instance.SendData(MQTTManager.instance.BandSetting, nowData);
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// 接受同步消息
|
||
/// </summary>
|
||
/// <param name="_frequency"></param>
|
||
public void FrequencyGamepos(string _frequency)
|
||
{
|
||
int layerValue = LayerMask.NameToLayer(_frequency);
|
||
dataLinkCommunicationFrequency = _frequency;
|
||
gamePos.layer = layerValue;
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 探测频段设置
|
||
/// </summary>
|
||
/// <param name="change"></param>
|
||
void SurveillanceFrequencyBandsValueChanged(Toggle change)
|
||
{
|
||
if (change.isOn)
|
||
{
|
||
electronicReconnaissanceCapability = change.transform.name;
|
||
int layerValue = LayerMask.NameToLayer(electronicReconnaissanceCapability);
|
||
dzWRJCamera.cullingMask = 1 << layerValue;
|
||
string nowData = GetSyncDataThree();
|
||
MyNetMQClient.instance.Send(nowData);
|
||
equipmentCommon.SetDatabaseInfo("scan_rate", electronicReconnaissanceCapability);
|
||
//DeviceManager.Instance.send2roomStr.Enqueue(nowData);
|
||
//MQTTManager.instance.SendData(MQTTManager.instance.SweepFrequencyBand, nowData);
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// 接受同步消息
|
||
/// </summary>
|
||
/// <param name="_frequency"></param>
|
||
public void SurveillanceFrequency(string _frequency)
|
||
{
|
||
int layerValue = LayerMask.NameToLayer(_frequency);
|
||
electronicReconnaissanceCapability = _frequency;
|
||
dzWRJCamera.cullingMask = 1 << layerValue;
|
||
}
|
||
|
||
[ContextMenu("Test")]
|
||
public void Test()
|
||
{
|
||
MatrixFormation(30, 1);//根据想定数据去设置无人机数量
|
||
}
|
||
|
||
// Update is called once per frame
|
||
void Update()
|
||
{
|
||
if (isStartRehearsing)
|
||
{
|
||
gamePos.gameObject.SetActive(true);
|
||
}
|
||
if (isStartRehearsing && equipmentCommon.isPlayer)
|
||
{
|
||
switch (pattern)
|
||
{
|
||
case Pattern.待机:
|
||
break;
|
||
case Pattern.警戒:
|
||
SelectiveAttackDrone();
|
||
break;
|
||
case Pattern.攻击:
|
||
SelectiveAttackDrone();
|
||
if (airRoute)
|
||
{
|
||
StartMoveObjectAlongPath();
|
||
}
|
||
break;
|
||
}
|
||
}
|
||
var _unmannedAerialVehicle = unmannedAerialVehicles.FindAll(x => x != null && x.gameObject.activeSelf);
|
||
if (_unmannedAerialVehicle.Count == 0)
|
||
{
|
||
string nowData = string.Format("{0},{1}", "SetToBeDestroyed", equipmentCommon.deviceID);
|
||
MyNetMQClient.instance.Send(nowData);
|
||
//DeviceManager.Instance.send2roomStr.Enqueue(nowData);
|
||
//MQTTManager.instance.SendData(MQTTManager.instance.SetToBeDestroyed, nowData);
|
||
UploadLog(equipmentCommon.deviceID);
|
||
WWWForm headers = new WWWForm();
|
||
headers.AddField("id", equipmentCommon.deviceID);
|
||
StartCoroutine(PostString(Url_Deletepracticedevicedetail, headers, data =>
|
||
{
|
||
equipmentCommon.onDeviceDelete?.Invoke(equipmentCommon.deviceID);
|
||
//Debug.Log(data);
|
||
DroneViewDisplay.Instance.DistroyUI(equipmentCommon.deviceID);
|
||
Destroy(gameObject);
|
||
}));
|
||
}
|
||
|
||
if (Spectrumdetection.Radius > 0 && boisp)
|
||
{
|
||
//if (gxWRJCamera && dzWRJCamera)
|
||
//{
|
||
// //gxWRJCamera.orthographicSize = Spectrumdetection.Radius * 1000;
|
||
|
||
switch (Spectrumdetection.Radius)
|
||
{
|
||
case 1:
|
||
reveal = 30;
|
||
Mapdisplay();
|
||
break;
|
||
case 2:
|
||
reveal = 60;
|
||
Mapdisplay();
|
||
break;
|
||
case 3:
|
||
reveal = 90;
|
||
Mapdisplay();
|
||
break;
|
||
case 4:
|
||
reveal = 120;
|
||
Mapdisplay();
|
||
break;
|
||
case 5:
|
||
reveal = 150;
|
||
Mapdisplay();
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
//}
|
||
}
|
||
//Judgingdistance();
|
||
}
|
||
|
||
//private void Judgingdistance()
|
||
//{
|
||
// RaycastHit hit;
|
||
// //Debug.LogError("调用了");
|
||
// if (Physics.Raycast(transform.position, Vector3.down, out hit))
|
||
// {
|
||
// Debug.Log(hit.distance);
|
||
// if (hit.distance <= 1f)
|
||
// {
|
||
// if (gamemap && gamePos)
|
||
// {
|
||
// gamePos.gameObject.SetActive(false);
|
||
// gamemap.gameObject.SetActive(false);
|
||
// }
|
||
// }
|
||
// else
|
||
// {
|
||
// if (gamemap && gamePos)
|
||
// {
|
||
// gamePos.gameObject.SetActive(true);
|
||
// gamemap.gameObject.SetActive(true);
|
||
// }
|
||
// }
|
||
|
||
// }
|
||
//}
|
||
|
||
/// <summary>
|
||
///上传日志
|
||
/// </summary>
|
||
/// <param name="deviceID"></param>
|
||
public void UploadLog(string deviceID)
|
||
{
|
||
string currentTime = System.DateTime.Now.ToString();
|
||
List<UploadLogMain> uploadLogMains = new List<UploadLogMain>();
|
||
UploadLogMain uploadLogMain = new UploadLogMain();
|
||
uploadLogMain.PracticeId = GlobalFlag.practiceSubjectID;
|
||
uploadLogMain.ThinkId = GlobalFlag.currentThinkId;
|
||
string log = currentTime + " " + equipmentCommon.equipmentType + "(" + deviceID + ")" + "被销毁了 ";
|
||
uploadLogMain.log = log;
|
||
uploadLogMains.Add(uploadLogMain);
|
||
string uploadLogMainJson = JsonConvert.SerializeObject(uploadLogMains);
|
||
WWWForm wWWForm = new WWWForm();
|
||
wWWForm.AddField("data", uploadLogMainJson);
|
||
//Debug.Log(uploadLogMainJson);
|
||
StartCoroutine(PostString(Url_Addpracticelog, wWWForm, data =>
|
||
{
|
||
Debug.Log(data);
|
||
}));
|
||
}
|
||
|
||
/// <summary>
|
||
/// 模式切换
|
||
/// </summary>
|
||
public void modeSwitch(int patternCut)
|
||
{
|
||
switch (patternCut)
|
||
{
|
||
case 0://待机
|
||
pattern = Pattern.待机;
|
||
break;
|
||
case 1:
|
||
pattern = Pattern.警戒;
|
||
break;
|
||
case 2:
|
||
pattern = Pattern.攻击;
|
||
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
|
||
}
|
||
|
||
public Action<List<Collider>> WRJAttach;
|
||
public void SwitchWRJModel()
|
||
{
|
||
gxWRJCamera.gameObject.SetActive(false);
|
||
switch (wrjModel)
|
||
{
|
||
case WRJModel.光学无人机:
|
||
gxWRJCamera.gameObject.SetActive(true);
|
||
break;
|
||
case WRJModel.电子侦察无人机:
|
||
WRJAttach += SetCollider4WRJ;
|
||
break;
|
||
case WRJModel.自杀式无人机:
|
||
break;
|
||
}
|
||
}
|
||
|
||
public List<Collider> attackColliders1 = new List<Collider>();
|
||
|
||
|
||
/// <summary>
|
||
/// 攻击打击
|
||
/// </summary>
|
||
private void SelectiveAttackDrone()
|
||
{
|
||
//if (isEngagedTarget) return;
|
||
//if (wrjModel == WRJModel.电子侦察无人机 || wrjModel == WRJModel.光学无人机)
|
||
|
||
if (wrjModel == WRJModel.电子侦察无人机)
|
||
{
|
||
List<Collider> allColliders = Physics.OverlapSphere(transform.position, Spectrumdetection.Radius * 1000).ToList(); // 检索范围内的所有碰撞体
|
||
for (int i = 0; i < allColliders.Count; i++)
|
||
{
|
||
if (allColliders[i].gameObject.tag == "AttackTarget"
|
||
&& !allColliders[i].isTrigger
|
||
&& !attackColliders1.Contains(allColliders[i])
|
||
&& allColliders[i].transform.GetComponent<HighPriorityTarget>()
|
||
&& allColliders[i].transform.GetComponent<HighPriorityTarget>().frequency == electronicReconnaissanceCapability)
|
||
{
|
||
attackColliders1.Add(allColliders[i]);
|
||
}
|
||
|
||
}
|
||
}
|
||
else if (wrjModel == WRJModel.光学无人机)
|
||
{
|
||
List<Collider> allColliders = Physics.OverlapSphere(transform.position, Spectrumdetection.Radius * 1000).ToList(); // 检索范围内的所有碰撞体
|
||
for (int i = 0; i < allColliders.Count; i++)
|
||
{
|
||
if (allColliders[i].gameObject.tag == "AttackTarget" && !allColliders[i].isTrigger && !attackColliders1.Contains(allColliders[i]))
|
||
{
|
||
Vector3 pos = gxWRJCamera.WorldToViewportPoint(allColliders[i].transform.position);
|
||
bool ispcamera = (pos.x > 0 && pos.x < 1 && pos.y > 0 && pos.y < 1 && pos.z > 0);
|
||
if (ispcamera)
|
||
{
|
||
attackColliders1.Add(allColliders[i]);
|
||
}
|
||
}
|
||
}
|
||
|
||
}
|
||
|
||
if (wrjModel == WRJModel.电子侦察无人机)
|
||
{
|
||
WRJAttach.Invoke(attackColliders1);
|
||
}
|
||
if (wrjModel == WRJModel.光学无人机)
|
||
{
|
||
for (int i = 0; i < attackColliders1.Count; i++)
|
||
{
|
||
if (attackColliders1[i] == null)
|
||
attackColliders1.RemoveAt(i);
|
||
}
|
||
if (attackColliders1.Count > 0)
|
||
{
|
||
var highPriorityTargets = attackColliders1.FindAll(x => x.transform.GetComponent<HighPriorityTarget>());
|
||
if (highPriorityTargets.Count > 0)
|
||
{
|
||
unmannedAerialVehicles[0].AttAck(highPriorityTargets[0].transform);
|
||
}
|
||
else
|
||
{
|
||
unmannedAerialVehicles[0].AttAck(attackColliders1[0].transform);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
public Collider currentCollider;
|
||
public void SetCollider4WRJ(List<Collider> attackColliders)
|
||
{
|
||
DeviceManager.Instance.SetCollider4WRJ(attackColliders, ref currentCollider);
|
||
if (currentCollider != null)
|
||
SendMsg(currentCollider.transform);
|
||
}
|
||
|
||
public void SendMsg(Transform attackTarget)
|
||
{
|
||
string nowData = GetSyncData(attackTarget);
|
||
//MQTTManager.instance.SendData(MQTTManager.instance.SingleDronePosition, nowData);
|
||
MyNetMQClient.instance.Send(nowData);
|
||
//DeviceManager.Instance.send2roomStr.Enqueue(nowData);
|
||
}
|
||
/// <summary>
|
||
/// 无人机攻击目标传递
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
protected string GetSyncData(Transform attackTarget)
|
||
{
|
||
return string.Format("{0},{1},{2},{3},{4}", "SingleDronePosition", equipmentCommon.deviceID,
|
||
attackTarget.position.x, attackTarget.position.y, attackTarget.position.z);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 设置频段同步
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
protected string GetSyncDataTwo()
|
||
{
|
||
UploadLog("频段设置为:", dataLinkCommunicationFrequency);
|
||
return string.Format("{0},{1},{2},{3}", "BandSetting", "WRJ", equipmentCommon.deviceID, dataLinkCommunicationFrequency);
|
||
}
|
||
/// <summary>
|
||
///上传日志
|
||
/// </summary>
|
||
/// <param name="deviceID"></param>
|
||
public void UploadLog(string str1, string str2)
|
||
{
|
||
string currentTime = System.DateTime.Now.ToString();
|
||
List<UploadLogMain> uploadLogMains = new List<UploadLogMain>();
|
||
UploadLogMain uploadLogMain = new UploadLogMain();
|
||
uploadLogMain.PracticeId = GlobalFlag.practiceSubjectID;
|
||
uploadLogMain.ThinkId = GlobalFlag.currentThinkId;
|
||
string log = currentTime + " " + transform.name + "(" + equipmentCommon.deviceID + ")" + str1 + str2;
|
||
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);
|
||
}));
|
||
}
|
||
/// <summary>
|
||
/// 设置扫描频段同步
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
protected string GetSyncDataThree()
|
||
{
|
||
UploadLog("扫描频段设置为:", electronicReconnaissanceCapability);
|
||
return string.Format("{0},{1},{2},{3}", "SweepFrequencyBand", "WRJ", equipmentCommon.deviceID, electronicReconnaissanceCapability);
|
||
}
|
||
#region 启动暂停
|
||
/// <summary>
|
||
/// 导条变化调用
|
||
/// </summary>
|
||
/// <param name="newValue"></param>
|
||
void OnActivationChangedHandler(bool newValue)
|
||
{
|
||
if (newValue)
|
||
{
|
||
|
||
}
|
||
else
|
||
{
|
||
|
||
}
|
||
}
|
||
|
||
|
||
|
||
#endregion
|
||
|
||
#region 数据写入
|
||
/// <summary>
|
||
/// 数据写入
|
||
/// </summary>
|
||
/// <param name="weaponitemone"></param>
|
||
public void FillInTheData(List<List_paraItem> weaponitemone, string _deviceId)
|
||
{
|
||
SenceInfo currentSceneInfo = new SenceInfo();
|
||
currentSceneInfo = UIBootstrap.Instance.currentSceneInfo.data;
|
||
for (int i = 0; i < weaponitemone.Count; i++)
|
||
{
|
||
switch (weaponitemone[i].para_name)
|
||
{
|
||
case "续航时间:":
|
||
batteryLife = weaponitemone[i].para_value;
|
||
break;
|
||
case "抗风等级:":
|
||
classificationWindResistance = weaponitemone[i].para_value;
|
||
break;
|
||
case "最大飞行速度:":
|
||
maximumFlyingSpeed = weaponitemone[i].para_value;
|
||
|
||
break;
|
||
case "RCS:":
|
||
RCS = weaponitemone[i].para_value;
|
||
break;
|
||
case "卫星定位频点:":
|
||
//satellitePositioningFrequency = weaponitemone[i].para_value;
|
||
switch (weaponitemone[i].para_value)
|
||
{
|
||
case "0":
|
||
satellitePositioningFrequency = "1227.60MHz";
|
||
break;
|
||
case "1":
|
||
satellitePositioningFrequency = "1381.05MHz";
|
||
break;
|
||
case "2":
|
||
satellitePositioningFrequency = "1575.42MHz";
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
break;
|
||
case "数据链通信频点:":
|
||
string date1 = GetFrequencyBand(weaponitemone[i].para_value);
|
||
|
||
string[] dates1 = date1.Split(',');
|
||
if (dates1.Length > 0)
|
||
{
|
||
for (int k = 0; k < togFrequencyBands.Count; k++)
|
||
{
|
||
|
||
togFrequencyBands[k].gameObject.SetActive(date1.Contains(togFrequencyBands[k].transform.name));
|
||
}
|
||
dataLinkCommunicationFrequency = dates1[0];
|
||
int layerValue = LayerMask.NameToLayer(dataLinkCommunicationFrequency);
|
||
gamePos.layer = layerValue;
|
||
foreach (Toggle toggle in togFrequencyBands)
|
||
{
|
||
if (toggle.transform.name == dataLinkCommunicationFrequency)
|
||
toggle.isOn = true;
|
||
}
|
||
}
|
||
break;
|
||
case "电子侦察能力:":
|
||
string date2 = GetFrequencyBand(weaponitemone[i].para_value);
|
||
string[] dates2 = date2.Split(',');
|
||
if (dates2.Length > 0)
|
||
{
|
||
for (int k = 0; k < togSurveillanceFrequencyBands.Count; k++)
|
||
{
|
||
|
||
togSurveillanceFrequencyBands[k].gameObject.SetActive(date2.Contains(togSurveillanceFrequencyBands[k].transform.name));
|
||
}
|
||
electronicReconnaissanceCapability = dates2[0];
|
||
int layerValue = LayerMask.NameToLayer(electronicReconnaissanceCapability);
|
||
dzWRJCamera.cullingMask = 1 << layerValue;
|
||
//探测频段设置
|
||
foreach (Toggle toggle in togSurveillanceFrequencyBands)
|
||
{
|
||
if (toggle.transform.name == electronicReconnaissanceCapability)
|
||
toggle.isOn = true;
|
||
}
|
||
}
|
||
|
||
break;
|
||
case "光学侦察能力:":
|
||
//opticalReconnaissanceCapability = weaponitemone[i].para_value;
|
||
switch (weaponitemone[i].para_value)
|
||
{
|
||
case "0":
|
||
opticalReconnaissanceCapability = "有";
|
||
break;
|
||
case "1":
|
||
opticalReconnaissanceCapability = "无";
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
|
||
if (string.IsNullOrEmpty(currentSceneInfo.EnvWindSpeed))
|
||
{
|
||
///根据风得速度改变无人机得速度
|
||
FireSpeed = float.Parse(maximumFlyingSpeed) / float.Parse(currentSceneInfo.EnvWindSpeed);
|
||
/////如果风速大于6级,无人机停止飞行
|
||
if (float.Parse(currentSceneInfo.EnvWindSpeed) * 10 > 6)
|
||
{
|
||
FireSpeed = 0;
|
||
}
|
||
}
|
||
CheckRSC();
|
||
if (i == (weaponitemone.Count - 1))
|
||
{
|
||
StartCoroutine(WeaponitemoneDataAddition());
|
||
}
|
||
SwitchWRJModel();
|
||
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取频段
|
||
/// </summary>
|
||
/// <param name="para_value"></param>
|
||
/// <returns></returns>
|
||
string GetFrequencyBand(string para_value)
|
||
{
|
||
string _data = "";
|
||
string[] str = para_value.Split(',');
|
||
if (str.Length > 0)
|
||
{
|
||
|
||
for (int j = 0; j < str.Length; j++)
|
||
{
|
||
switch (str[j])
|
||
{
|
||
case "0":
|
||
_data += "UHF" + ",";
|
||
break;
|
||
case "1":
|
||
_data += "L" + ",";
|
||
break;
|
||
case "2":
|
||
_data += "S" + ",";
|
||
break;
|
||
case "3":
|
||
_data += "C" + ",";
|
||
break;
|
||
case "4":
|
||
_data += "X" + ",";
|
||
break;
|
||
case "5":
|
||
_data += "Ku" + ",";
|
||
break;
|
||
case "6":
|
||
_data += "Ka" + ",";
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
}
|
||
|
||
}
|
||
return _data;
|
||
}
|
||
/// <summary>
|
||
/// 设置tips颜色
|
||
/// </summary>
|
||
public void SetTipsColor()
|
||
{
|
||
if (equipmentCommon.isPlayer)
|
||
unmannedAerialVehicles[0].tips.color = Color.green;
|
||
else
|
||
unmannedAerialVehicles[0].tips.color = Color.red;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 雷达检测无人机身上得RSC
|
||
/// </summary>
|
||
public void CheckRSC()
|
||
{
|
||
if (string.IsNullOrEmpty(RCS))
|
||
{
|
||
float rcs = float.Parse(RCS);
|
||
if (rcs <= 0.5 && rcs >= 0.1)
|
||
{
|
||
StartCoroutine(ShowRadarTips(0.8f, 2));
|
||
}
|
||
else if (rcs >= 0.5f && rcs <= 1)
|
||
{
|
||
StartCoroutine(ShowRadarTips(0.4f, 1));
|
||
}
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// 多少时间在对方雷达界面上显示红色标记
|
||
/// </summary>
|
||
/// <param name="minTime"></param>
|
||
/// <param name="maxTime"></param>
|
||
/// <returns></returns>
|
||
private IEnumerator ShowRadarTips(float minTime, float maxTime)
|
||
{
|
||
GameObject tips = transform.Find("Minimapwrj").gameObject;
|
||
while (true)
|
||
{
|
||
tips.gameObject.SetActive(false);
|
||
float time = UnityEngine.Random.Range(minTime, maxTime);
|
||
yield return new WaitForSeconds(time);
|
||
tips.gameObject.SetActive(true);
|
||
}
|
||
}
|
||
|
||
public LayerMask layerMask = new LayerMask();
|
||
/// <summary>
|
||
/// 检测无线电频率
|
||
/// </summary>
|
||
/// <param name="target">无线电</param>
|
||
/// <param name="interferenceMode">干扰模式</param>
|
||
/// <param name="transmittedPower">发射功率</param>
|
||
/// <param name="interferingFrequency">干扰频率</param>
|
||
/// <param name="interferenceAngle">干扰角度</param>
|
||
/// <param name="ground">地面的图层</param>
|
||
public void CheckSatellitePositioningFrequency(
|
||
string interferenceMode)
|
||
{
|
||
|
||
if (interferenceMode == "驱离")
|
||
{
|
||
transform.DOKill();
|
||
transform.LookAt(new Vector3(-500, 160, 1600));
|
||
transform.DOMove(new Vector3(-500, 160, 1600), 60);
|
||
}
|
||
else if (interferenceMode == "迫降")
|
||
{
|
||
transform.DOKill();
|
||
RaycastHit hit;
|
||
if (Physics.Raycast(transform.position, Vector3.down, out hit, Mathf.Infinity, layerMask))
|
||
{
|
||
if (hit.distance > 1f)
|
||
{
|
||
hit.point = new Vector3(hit.point.x, hit.point.y + 3, hit.point.z);
|
||
transform.DOMove(hit.point, 6);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
public string WRJName;
|
||
/// <summary>
|
||
/// 单个无人机数据写入
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
IEnumerator WeaponitemoneDataAddition()
|
||
{
|
||
yield return new WaitForSeconds(0.01f);
|
||
|
||
UnmannedAerialVehicle uav = unmannedAerialVehicles[0];
|
||
if (uav != null)
|
||
{
|
||
uav.unmannedAerialVehicleManage = this;
|
||
uav.batteryLife = batteryLife;
|
||
uav.classificationWindResistance = classificationWindResistance;
|
||
uav.maximumFlyingSpeed = maximumFlyingSpeed;
|
||
uav.RCS = RCS;
|
||
uav.satellitePositioningFrequency = satellitePositioningFrequency;
|
||
uav.dataLinkCommunicationFrequency = dataLinkCommunicationFrequency;
|
||
uav.electronicReconnaissanceCapability = electronicReconnaissanceCapability;
|
||
uav.opticalReconnaissanceCapability = opticalReconnaissanceCapability;
|
||
uav.wrjModel = wrjModel;
|
||
if (uav.tips != null)
|
||
uav.tips.text = wrjModel.ToString();
|
||
if (groupId > -1)
|
||
{
|
||
isGroup = true;
|
||
SetGroupTips(groupId);
|
||
}
|
||
WRJName = wrjModel.ToString();
|
||
}
|
||
|
||
}
|
||
#endregion
|
||
|
||
#region 阵型编队
|
||
/// <summary>
|
||
/// 阵型选择
|
||
/// </summary>
|
||
/// <param name="number"></param>
|
||
public void Formation(int number)
|
||
{
|
||
switch (number)
|
||
{
|
||
case 1:
|
||
GenerateFormation();
|
||
break;
|
||
case 2:
|
||
MatrixFormation(5);
|
||
break;
|
||
case 3:
|
||
MatrixFormation(30);
|
||
break;
|
||
case 4:
|
||
MatrixFormation(1);
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
|
||
}
|
||
|
||
|
||
|
||
/// <summary>
|
||
/// 无人机雁式阵型
|
||
/// </summary>
|
||
private void GenerateFormation()
|
||
{
|
||
int count = 1; // 每一排的物体数量
|
||
int currentCount = 0;
|
||
Vector3 startPos = new Vector3();
|
||
|
||
for (int i = 0; i < Mathf.Ceil(Mathf.Sqrt(totalObjects)); i++)
|
||
{
|
||
//Debug.Log("剩余。。。:" + (totalObjects - currentCount));
|
||
startPos = new Vector3(-i * 2, 0, -i * 2);
|
||
for (int j = 0; j < count; j++)//每排物体个数
|
||
{
|
||
|
||
if (currentCount < totalObjects)
|
||
{
|
||
Vector3 _vector3 = startPos + new Vector3(j * 2, 0, 0);
|
||
if (unmannedAerialVehicles[currentCount])
|
||
unmannedAerialVehicles[currentCount].transform.localPosition = _vector3;
|
||
currentCount++;
|
||
}
|
||
else
|
||
{
|
||
BoxCollider box = transform.GetComponent<BoxCollider>();
|
||
if (box)
|
||
{
|
||
box.center = new Vector3(0, 0, -i);
|
||
box.size = new Vector3(2 * count, 1, 2 * (i + 1));
|
||
}
|
||
}
|
||
}
|
||
count += 2; // 下一排增加两个物体
|
||
}
|
||
}
|
||
|
||
|
||
|
||
/// <summary>
|
||
/// 矩阵阵型
|
||
/// </summary>
|
||
private void MatrixFormation(int rows)
|
||
{
|
||
float offsetX = 2.0f; // 子物体之间的水平间距
|
||
float offsetY = 2.0f; // 子物体之间的垂直间距
|
||
float offsetZ = 2.0f; // 子物体之间的垂直间距
|
||
int currentCount = 0;
|
||
int cols = CanDivideEvenly(totalObjects, rows) ? totalObjects / rows : totalObjects / rows + 1;
|
||
for (int row = 0; row < rows; row++)
|
||
{
|
||
for (int col = 0; col < cols; col++)
|
||
{
|
||
if (currentCount < totalObjects)
|
||
{
|
||
Vector3 position = new Vector3(col * offsetX, 0, -row * offsetZ);
|
||
if (unmannedAerialVehicles[currentCount])
|
||
unmannedAerialVehicles[currentCount].transform.localPosition = position;
|
||
currentCount++;
|
||
}
|
||
}
|
||
}
|
||
BoxCollider box = transform.GetComponent<BoxCollider>();
|
||
if (box)
|
||
{
|
||
Debug.Log("cols..:" + cols);
|
||
Debug.Log("rows..:" + rows);
|
||
box.center = new Vector3(cols - 1, 0, -(rows - 1));
|
||
box.size = new Vector3(cols * 2, 1, 2 * rows);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 根据想定数据去设置无人机数量
|
||
/// </summary>
|
||
public void MatrixFormation(int rows, int wrjCount)
|
||
{
|
||
//for (int i = 0; i < unmannedAerialVehicles.Count; i++)
|
||
//{
|
||
// unmannedAerialVehicles[i].gameObject.SetActive(false);
|
||
//}
|
||
//for (int i = 0; i < wrjCount; i++)
|
||
//{
|
||
// unmannedAerialVehicles[i].gameObject.SetActive(true);
|
||
//}
|
||
//float offsetX = 2.0f; // 子物体之间的水平间距
|
||
//float offsetY = 2.0f; // 子物体之间的垂直间距
|
||
//float offsetZ = 2.0f; // 子物体之间的垂直间距
|
||
//int currentCount = 0;
|
||
//int cols = CanDivideEvenly(totalObjects, rows) ? totalObjects / rows : totalObjects / rows + 1;
|
||
//for (int row = 0; row < rows; row++)
|
||
//{
|
||
// for (int col = 0; col < cols; col++)
|
||
// {
|
||
// if (currentCount < totalObjects)
|
||
// {
|
||
// Vector3 position = new Vector3(col * offsetX, 0, -row * offsetZ);
|
||
// if (unmannedAerialVehicles[currentCount])
|
||
// unmannedAerialVehicles[currentCount].transform.localPosition = position;
|
||
// currentCount++;
|
||
// }
|
||
// }
|
||
//}
|
||
//BoxCollider box = transform.GetComponent<BoxCollider>();
|
||
//if (box)
|
||
//{
|
||
// //Debug.Log("cols..:" + cols);
|
||
// //Debug.Log("rows..:" + rows);
|
||
// box.center = new Vector3(cols - 1, 0, -(wrjCount - 1));
|
||
// box.size = new Vector3(cols * 2, 1, 2 * wrjCount);
|
||
//}
|
||
}
|
||
|
||
bool CanDivideEvenly(int dividend, int divisor)
|
||
{
|
||
return dividend % divisor == 0;
|
||
}
|
||
#endregion
|
||
|
||
/// <summary>
|
||
/// 关闭航线设置
|
||
/// </summary>
|
||
public void TurnOffCourseSettings()
|
||
{
|
||
if (airRoute)
|
||
{
|
||
DistanceMeasurement distanceMeasurement = airRoute.GetComponent<DistanceMeasurement>();
|
||
if (distanceMeasurement)
|
||
{
|
||
distanceMeasurement.isPathCanBePlanned = false;
|
||
}
|
||
}
|
||
}
|
||
|
||
public GameObject startPos;
|
||
public float hight = 200f;
|
||
/// <summary>
|
||
/// 开启航线设置
|
||
/// </summary>
|
||
public void RouteSettings()
|
||
{
|
||
if (airRoute)
|
||
{
|
||
DistanceMeasurement distanceMeasurement = airRoute.GetComponent<DistanceMeasurement>();
|
||
if (distanceMeasurement)
|
||
{
|
||
distanceMeasurement.isPathCanBePlanned = true;
|
||
positions.Clear();
|
||
positions.Enqueue(startPos.transform.position);
|
||
|
||
}
|
||
}
|
||
else
|
||
{
|
||
GameObject _object = Instantiate(LinePrefab);
|
||
airRoute = _object;
|
||
airRoute.transform.position = Vector3.zero;
|
||
DistanceMeasurement distanceMeasurement = airRoute.GetComponent<DistanceMeasurement>();
|
||
if (distanceMeasurement)
|
||
{
|
||
if (startPos)
|
||
{
|
||
startPos.transform.position = new Vector3(transform.position.x, hight, transform.position.z);
|
||
distanceMeasurement.isPathCanBePlanned = true;
|
||
distanceMeasurement.markers[0] = startPos.transform;
|
||
positions.Enqueue(startPos.transform.position);
|
||
distanceMeasurement.unmannedAerialVehicleManage = this;
|
||
}
|
||
else
|
||
{
|
||
SetStartPos(distanceMeasurement.PosPrefab);
|
||
distanceMeasurement.isPathCanBePlanned = true;
|
||
distanceMeasurement.markers[0] = startPos.transform;
|
||
positions.Enqueue(startPos.transform.position);
|
||
distanceMeasurement.unmannedAerialVehicleManage = this;
|
||
}
|
||
|
||
}
|
||
}
|
||
}
|
||
|
||
public void SetStartPos(GameObject _distanceMeasurement)
|
||
{
|
||
startPos = Instantiate(_distanceMeasurement, transform);
|
||
startPos.transform.localScale = Vector3.zero;
|
||
startPos.transform.position = new Vector3(transform.position.x, hight, transform.position.z);
|
||
}
|
||
|
||
private bool isMove = true;
|
||
/// <summary>
|
||
/// 按规划路径开始移动
|
||
/// </summary>
|
||
public void StartMoveObjectAlongPath()
|
||
{
|
||
if (isMove && positions.Count > 0)
|
||
{
|
||
isMove = false;
|
||
gamePos.gameObject.SetActive(true);
|
||
gamemap.gameObject.SetActive(true);
|
||
Vector3 _positions = positions.Dequeue();
|
||
var nowData = GetSyncData(_positions);
|
||
MyNetMQClient.instance.Send(nowData);
|
||
//DeviceManager.Instance.send2roomStr.Enqueue(nowData);
|
||
//MQTTManager.instance.SendData(MQTTManager.instance.DronePosition, nowData);
|
||
StartCoroutine(MoveObjectAlongPath(_positions)); // 启动协程,按规划的路线移动物体
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
/// <param name="_positions"></param>
|
||
/// <returns></returns>
|
||
public IEnumerator MoveObjectAlongPath(Vector3 _positions) // 协程:按路线移动物体
|
||
{
|
||
gamePos.gameObject.SetActive(true);
|
||
gamemap.gameObject.SetActive(true);
|
||
Vector3 targetPosition = new Vector3(_positions.x, hight, _positions.z);// 目标位置为当前顶点坐标
|
||
float _distance = Vector3.Distance(transform.position, targetPosition);
|
||
float _time = _distance / FireSpeed;
|
||
if (_positions.x != transform.position.x && _positions.z != transform.position.z)
|
||
transform.LookAt(targetPosition);
|
||
transform.DOMove(targetPosition, _time).SetEase(Ease.Linear);
|
||
yield return new WaitForSeconds(_time); // 等待一帧时间
|
||
isMove = true;
|
||
}
|
||
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
/// <param name="_positions"></param>
|
||
/// <param name="_isMove"></param>
|
||
/// <returns></returns>
|
||
public IEnumerator MoveObjectAlongPath(Vector3 _positions, bool _isMove) // 协程:按路线移动物体
|
||
{
|
||
|
||
Vector3 targetPosition = new Vector3(_positions.x, hight, _positions.z);// 目标位置为当前顶点坐标
|
||
float _distance = Vector3.Distance(transform.position, targetPosition);
|
||
float _time = _distance / FireSpeed;
|
||
if (_positions.x != transform.position.x && _positions.z != transform.position.z)
|
||
transform.LookAt(targetPosition);
|
||
transform.DOMove(targetPosition, _time).SetEase(Ease.Linear);
|
||
yield return new WaitForSeconds(_time); // 等待一帧时间
|
||
equipmentCommon.isMove = _isMove;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 无人机整体位置传递
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
protected string GetSyncData(Vector3 _positions)
|
||
{
|
||
return string.Format("{0},{1},{2},{3},{4}", "DronePosition", equipmentCommon.deviceID, _positions.x, _positions.y, _positions.z);
|
||
}
|
||
private void OnDestroy()
|
||
{
|
||
if (airRoute)
|
||
Destroy(airRoute.gameObject);
|
||
for (int i = 0; i < unmannedAerialVehicleManages.Count; i++)
|
||
{
|
||
if (unmannedAerialVehicleManages[i] == null)
|
||
{
|
||
unmannedAerialVehicleManages.RemoveAt(i);
|
||
}
|
||
}
|
||
StopCoroutine(ShowRadarTips(0, 0));
|
||
OnActivationChanged -= OnActivationChangedHandler;
|
||
|
||
}
|
||
|
||
|
||
}
|
||
public enum Pattern
|
||
{
|
||
待机,
|
||
警戒,
|
||
攻击
|
||
}
|
||
|