339 lines
9.7 KiB
C#
339 lines
9.7 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using AdamThinkDevicesData;
|
|
using AdamSync;
|
|
using System.Linq;
|
|
using UnityEngine.UI;
|
|
|
|
/// <summary>
|
|
/// 雷达控制
|
|
/// </summary>
|
|
public class RadarManger : MonoBehaviour
|
|
{
|
|
|
|
public EquipmentCommon equipmentCommon;
|
|
#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>
|
|
private Coroutine timerCoroutine;
|
|
/// <summary>
|
|
/// 定时器运行状态
|
|
/// </summary>
|
|
private bool isTimerRunning = false;
|
|
/// <summary>
|
|
/// 间隔时间
|
|
/// </summary>
|
|
public float interval = 5.0f;
|
|
#endregion
|
|
/// <summary>
|
|
/// 雷达UI预制体
|
|
/// </summary>
|
|
public GameObject RadarUiPrefab;
|
|
/// <summary>
|
|
/// 雷达UI
|
|
/// </summary>
|
|
public GameObject RadarUi;
|
|
/// <summary>
|
|
/// 雷达动画
|
|
/// </summary>
|
|
public Animator aniRandar;
|
|
/// <summary>
|
|
/// 雷达UI动画播放
|
|
/// </summary>
|
|
public Animator aniRandarUI;
|
|
|
|
#region 雷达数据
|
|
/// <summary>
|
|
/// 转台转速
|
|
/// </summary>
|
|
public string TurntableSpeed;
|
|
/// <summary>
|
|
/// 探测距离
|
|
/// </summary>
|
|
public string DetectionRange;
|
|
/// <summary>
|
|
/// 近盲区
|
|
/// </summary>
|
|
public string NearBlindArea;
|
|
/// <summary>
|
|
/// 批量标处理能力
|
|
/// </summary>
|
|
public string BatchStandardProcessingCapability;
|
|
/// <summary>
|
|
/// 探测成功率
|
|
/// </summary>
|
|
public string DetectionSuccessRate;
|
|
/// <summary>
|
|
/// 最小探测速度
|
|
/// </summary>
|
|
public string MinimumDetectionVelocity;
|
|
/// <summary>
|
|
/// 距离分辨率
|
|
/// </summary>
|
|
public string RangeResolution;
|
|
/// <summary>
|
|
/// 方位分辨率
|
|
/// </summary>
|
|
public string AzimuthResolution;
|
|
/// <summary>
|
|
/// 方位波束宽度
|
|
/// </summary>
|
|
public string AzimuthBeamwidth;
|
|
/// <summary>
|
|
/// 俯仰波束宽度
|
|
/// </summary>
|
|
public string PitchBeamwidth;
|
|
|
|
#endregion
|
|
/// <summary>
|
|
/// 检测范围半径
|
|
/// </summary>
|
|
public float detectionRadius = 5f; //
|
|
/// <summary>
|
|
/// 批量标处理能力
|
|
/// </summary>
|
|
public int NumberOfProbes = 0;
|
|
/// <summary>
|
|
/// 渲染小地图摄像机
|
|
/// </summary>
|
|
public Camera minCamera;
|
|
/// <summary>
|
|
/// 激活面板预设体
|
|
/// </summary>
|
|
public Image imageprs;
|
|
|
|
public RawImage rawImage;
|
|
void Awake()
|
|
{
|
|
|
|
}
|
|
void Start()
|
|
{
|
|
|
|
equipmentCommon = GetComponent<EquipmentCommon>();
|
|
|
|
// 订阅布尔值变化事件
|
|
OnActivationChanged += OnActivationChangedHandler;
|
|
DroneViewDisplay.Instance.CreateUI(equipmentCommon.deviceID, minCamera, rawImage);
|
|
}
|
|
|
|
#region 启动暂停
|
|
/// <summary>
|
|
/// 导条变化调用
|
|
/// </summary>
|
|
/// <param name="newValue"></param>
|
|
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();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 开启
|
|
/// </summary>
|
|
public void StartTimer()
|
|
{
|
|
if (equipmentCommon.isPlayer && timerCoroutine == null)
|
|
{
|
|
//timerCoroutine = StartCoroutine(Timer());
|
|
isTimerRunning = true;
|
|
}
|
|
}
|
|
/// <summary>s
|
|
/// 停止
|
|
/// </summary>
|
|
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<Animator>();
|
|
RadarRotationSpeed(TurntableSpeed);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 数据写入
|
|
/// </summary>
|
|
/// <param name="weaponitemone"></param>
|
|
public void FillInTheData(List<List_paraItem> weaponitemone)
|
|
{
|
|
//if (equipmentCommon)
|
|
//{
|
|
// string msg = $"send2room {equipmentCommon.equipmentType}+{transform.position.ToString().Replace(" ", "").Replace("(", "").Replace(")", "")}+{transform.eulerAngles.ToString().Replace(" ", "").Replace("(", "").Replace(")", "")}";
|
|
// Debug.Log(msg);
|
|
// _ = SyncCreateRoom.SendMessageAsync(msg);
|
|
//}
|
|
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;
|
|
detectionRadius = float.Parse(DetectionRange) * 100;
|
|
minCamera.orthographicSize = detectionRadius;
|
|
break;
|
|
case "近盲区:":
|
|
NearBlindArea = weaponitemone[i].para_value;
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 雷达转动速度
|
|
/// </summary>
|
|
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); // 改变动画的播放速度为新速度值
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 检索
|
|
/// </summary>
|
|
public void RetrievalUAV()
|
|
{
|
|
List<Collider> colliders = Physics.OverlapSphere(transform.position, detectionRadius).ToList(); // 检索范围内的所有碰撞体
|
|
var colliders2 = colliders.FindAll(x => x.tag == "WRJ");
|
|
minCamera.orthographicSize = detectionRadius;
|
|
if (colliders2.Count > 0)
|
|
{
|
|
for (int i = 0; i < colliders2.Count; i++)
|
|
{
|
|
UnmannedAerialVehicle unmannedAerialVehicle = colliders2[i].GetComponent<UnmannedAerialVehicle>();
|
|
if (unmannedAerialVehicle)
|
|
{
|
|
LaserFireControlPlatformManger laserFireControlPlatformManger = LaserFireControlPlatformManger.laserFireControlPlatformMangers.Find(x => (x != null && x.isLasing == false && x.lasertime <= 0));
|
|
if (laserFireControlPlatformManger)
|
|
{
|
|
laserFireControlPlatformManger.lasertime = laserFireControlPlatformManger.storageIntervalTime;
|
|
laserFireControlPlatformManger.isLasing = true;
|
|
laserFireControlPlatformManger.targetPoint = unmannedAerialVehicle.transform;
|
|
laserFireControlPlatformManger.Lasing();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
//private void OnMouseEnter()
|
|
//{
|
|
// if (UIBootstrap.Instance.GetRoleByIDPracticeId(GlobalFlag.practiceSeatId) != "0")
|
|
// {
|
|
// Debug.LogError("鼠标进入");
|
|
// RadarUi.transform.localScale = Vector3.one;
|
|
// minCamera.transform.position = new Vector3(transform.position.x, 350, transform.position.z);
|
|
// }
|
|
//}
|
|
|
|
//private void OnMouseExit()
|
|
//{
|
|
// Debug.LogError("鼠标离开");
|
|
// RadarUi.transform.localScale = Vector3.zero;
|
|
//}
|
|
/// <summary>
|
|
/// 检测鼠标点击的方法
|
|
/// </summary>
|
|
private void OnMouseDown()
|
|
{
|
|
if (equipmentCommon.isPlayer && GlobalFlag.blueOrRed == 1)
|
|
{
|
|
|
|
imageprs.gameObject.SetActive(true);
|
|
}
|
|
}
|
|
private void OnDestroy()
|
|
{
|
|
Destroy(RadarUi.gameObject);
|
|
OnActivationChanged -= OnActivationChangedHandler;
|
|
}
|
|
}
|