455 lines
14 KiB
C#
455 lines
14 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using AdamThinkDevicesData;
|
|
using AdamSync;
|
|
using System.Linq;
|
|
using UnityEngine.UI;
|
|
using System;
|
|
|
|
/// <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 RCS;
|
|
/// <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 float nearBlindArea = 5f; //
|
|
/// <summary>
|
|
/// 批量标处理能力
|
|
/// </summary>
|
|
public float rcs = 0;
|
|
/// <summary>
|
|
/// 渲染小地图摄像机
|
|
/// </summary>
|
|
public Camera minCamera;
|
|
/// <summary>
|
|
/// 激活面板预设体
|
|
/// </summary>
|
|
public Image imageprs;
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public RawImage rawImage;
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
private bool onlyOne = true;
|
|
/// <summary>
|
|
/// 接收无人机显示在地图上的参数大小
|
|
/// </summary>
|
|
public float Mapsize;
|
|
void Awake()
|
|
{
|
|
//失活摄像机
|
|
minCamera.gameObject.SetActive(false);
|
|
radarCenter = this.transform;
|
|
}
|
|
void Start()
|
|
{
|
|
|
|
equipmentCommon = GetComponent<EquipmentCommon>();
|
|
|
|
// 订阅布尔值变化事件
|
|
OnActivationChanged += OnActivationChangedHandler;
|
|
//DroneViewDisplay.Instance.CreateUI(equipmentCommon.deviceID, minCamera, rawImage);
|
|
}
|
|
public Transform radarCenter;
|
|
public List<GameObject> targets = new List<GameObject>();
|
|
public Image radarBackground;
|
|
public GameObject targetPointPrefab;
|
|
void Update()
|
|
{
|
|
//老师点了开始演习就激活摄像机
|
|
if (isStartRehearsing)
|
|
{
|
|
minCamera.gameObject.SetActive(true);
|
|
targets = GameObject.FindGameObjectsWithTag("WRJ").ToList().FindAll(a => a.GetComponent<UnmannedAerialVehicleManage>().GetRCS() > rcs);
|
|
|
|
foreach (Transform child in rawImage.transform)
|
|
{
|
|
Destroy(child.gameObject);
|
|
}
|
|
|
|
foreach (GameObject target in targets)
|
|
{
|
|
Vector3 relativePosition = target.transform.position - radarCenter.position;
|
|
Vector2 radarPosition = new Vector2(relativePosition.x, relativePosition.z) * 0.1f;
|
|
GameObject point = Instantiate(targetPointPrefab, rawImage.transform);
|
|
RectTransform rt = point.GetComponent<RectTransform>();
|
|
rt.anchoredPosition = radarPosition;
|
|
}
|
|
|
|
}
|
|
//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<UnmannedAerialVehicleManage>();
|
|
if (unmannedAerialVehicleManage && unmannedAerialVehicleManage.gamemap)
|
|
{
|
|
unmannedAerialVehicleManage.gamemap.transform.localScale = new Vector3(Mapsize, 1, Mapsize);
|
|
//Debug.Log("改变了无人机显示大小");
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
|
|
#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();
|
|
//Deadzone();
|
|
}
|
|
}
|
|
|
|
/// <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)
|
|
{
|
|
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 "RCS:":
|
|
RCS = weaponitemone[i].para_value;
|
|
rcs = float.Parse(RCS);
|
|
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;
|
|
}
|
|
}
|
|
|
|
/// <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); // 改变动画的播放速度为新速度值
|
|
}
|
|
}
|
|
|
|
public List<Collider> colliders = new List<Collider>();
|
|
|
|
public List<Collider> attackColliders1 = new List<Collider>();
|
|
/// <summary>
|
|
/// 检索
|
|
/// </summary>
|
|
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<UnmannedAerialVehicle>();
|
|
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();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 雷达盲区让目标消失在地图上
|
|
/// </summary>
|
|
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<UnmannedAerialVehicleManage>();
|
|
if (unmannedAerialVehicle)
|
|
{
|
|
unmannedAerialVehicle.gamemap.SetActive(false);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 检测鼠标点击的方法
|
|
/// </summary>
|
|
private void OnMouseDown()
|
|
{
|
|
if (equipmentCommon.isPlayer && GlobalFlag.blueOrRed == 1)
|
|
{
|
|
GameManager.Instance.GetAllImportance();
|
|
imageprs.gameObject.SetActive(true);
|
|
}
|
|
}
|
|
private void OnDestroy()
|
|
{
|
|
Destroy(RadarUi.gameObject);
|
|
OnActivationChanged -= OnActivationChangedHandler;
|
|
}
|
|
}
|