NewN_UAVPlane/Assets/Temp/Scripts/Spectrumdetection.cs

349 lines
10 KiB
C#

using AdamThinkDevicesData;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
public class Spectrumdetection : MonoBehaviour
{
public EquipmentCommon equipmentCommon;
#region
/// <summary>
/// 探测距离
/// </summary>
public string Detectionrange;
/// <summary>
/// 批目标处理能力
/// </summary>
public string Batchcapacity;
/// <summary>
/// 探测频率
/// </summary>
public string frequency;
/// <summary>
/// 探测成功率
/// </summary>
public string Detectionsuccessrate;
/// <summary>
/// 探测响应时间
/// </summary>
public string Responsetime;
/// <summary>
/// 测向精度
/// </summary>
public string Directionfindingaccuracy;
/// <summary>
/// 最小探测速度
/// </summary>
public string Minimumdetectionvelocity;
#endregion
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 GameObject SpectrumdetectionUI;
/// <summary>
/// 显示UI频段页面
/// </summary>
public Image Frequencyiamge;
/// <summary>
/// 关闭按钮
/// </summary>
public Button frenbutton;
/// <summary>
/// 选择最终的频段
/// </summary>
public Toggle toggle1, toggle2, toggle3, toggle4, toggle5, toggle6, toggle7;
/// <summary>
/// 最终的波段
/// </summary>
public string Frequency;
void Start()
{
equipmentCommon = GetComponent<EquipmentCommon>();
// 订阅布尔值变化事件
OnActivationChanged += OnActivationChangedHandler;
_isStartRehearsing = GlobalFlag.isStartRehearsing;
Microwave();
}
private void Microwave()
{
frenbutton.onClick.AddListener(() =>
{
Frequencyiamge.gameObject.SetActive(false);
});
toggle1.onValueChanged.AddListener((ison) =>
{
if (ison)
{
Frequency = "HUF";
}
});
toggle2.onValueChanged.AddListener((ison) =>
{
if (ison)
{
Frequency = "L";
}
});
toggle3.onValueChanged.AddListener((ison) =>
{
if (ison)
{
Frequency = "S";
}
});
toggle4.onValueChanged.AddListener((ison) =>
{
if (ison)
{
Frequency = "C";
}
});
toggle5.onValueChanged.AddListener((ison) =>
{
if (ison)
{
Frequency = "X";
}
});
toggle6.onValueChanged.AddListener((ison) =>
{
if (ison)
{
Frequency = "Ku";
}
});
toggle7.onValueChanged.AddListener((ison) =>
{
if (ison)
{
Frequency = "Ka";
}
});
}
/// <summary>
/// 演习是否启动
/// </summary>
void OnActivationChangedHandler(bool bol)
{
if (bol)
{
Debug.Log("开始演练");
}
else
{
Debug.Log("结束演练");
}
}
/// <summary>
/// 读取设备参数
/// </summary>
public void FillInTheData(List<List_paraItem> weaponitemone)
{
for (int i = 0; i < weaponitemone.Count; i++)
{
switch (weaponitemone[i].para_name)
{
case "探测距离:":
Detectionrange = weaponitemone[i].para_value;
break;
case "批目标处理能力:":
Batchcapacity = weaponitemone[i].para_value;
break;
case "侦测频率:":
string[] str = weaponitemone[i].para_value.Split(',');
if (str.Length > 0)
{
for (int j = 0; j < str.Length; j++)
{
switch (str[j])
{
case "0":
frequency += "UHF" + ",";
break;
case "1":
frequency += "L" + ",";
break;
case "2":
frequency += "S" + ",";
break;
case "3":
frequency += "C" + ",";
break;
case "4":
frequency += "X" + ",";
break;
case "5":
frequency += "Ku" + ",";
break;
case "6":
frequency += "Ka" + ",";
break;
default:
break;
}
}
}
break;
case "探测成功率:":
Detectionsuccessrate = weaponitemone[i].para_value;
break;
case "探测响应时间:":
Responsetime = weaponitemone[i].para_value;
break;
case "测向精度:":
Directionfindingaccuracy = weaponitemone[i].para_value;
break;
case "最小探测速度:":
Minimumdetectionvelocity = weaponitemone[i].para_value;
break;
default:
break;
}
}
Microwavefrequency();
}
private void Microwavefrequency()
{
if (frequency.Length>0)
{
string[] str = frequency.Split(',');
for (int i = 0; i < str.Length; i++)
{
switch (str[i])
{
case "UHF":
toggle1.gameObject.SetActive(true);
break;
case "L":
toggle2.gameObject.SetActive(true);
break ;
case "S":
toggle3.gameObject.SetActive(true);
break;
case "C":
toggle4.gameObject.SetActive(true);
break;
case "X":
toggle5.gameObject.SetActive(true);
break;
case "Ku":
toggle6.gameObject.SetActive(true);
break;
case "Ka":
toggle7.gameObject.SetActive(true);
break;
default:
break;
}
}
}
}
void Update()
{
Search();//微波武器朝向无人机
Emittedray();
}
/// <summary>
/// 点击物体生成页面
/// </summary>
/// <exception cref="NotImplementedException"></exception>
private void Emittedray()
{
if (Input.GetMouseButtonDown(0)&& UIBootstrap.Instance.GetRoleByIDPracticeId(GlobalFlag.practiceSeatId) != "0")
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (EventSystem.current.IsPointerOverGameObject())
{
return;
}
if (Physics.Raycast(ray,out hit,1000))
{
EquipmentCommon equipmentCommon1=hit.collider.GetComponent<EquipmentCommon>();
if (equipmentCommon.deviceID==equipmentCommon1.deviceID)
{
Frequencyiamge.transform.position = Camera.main.WorldToScreenPoint(hit.point);
Frequencyiamge.gameObject.SetActive(true);
}
}
}
}
/// <summary>
/// 搜索范围内的无人机
/// </summary>
private void Search()
{
Collider[] colliders = Physics.OverlapSphere(transform.position, float.Parse(Detectionrange) * 100);
for (int i = 0; i < colliders.Length; i++)
{
if (colliders[i].transform.gameObject.tag=="WRJ")
{
Debug.LogError("进来了");
UnmannedAerialVehicle unmannedAerialVehicle = null;
if (colliders[i].GetComponent<UnmannedAerialVehicle>())
{
unmannedAerialVehicle = colliders[i].GetComponent<UnmannedAerialVehicle>();
if (unmannedAerialVehicle !=null)
{
Microwaveweapon microwaveweapon = Microwaveweapon.MicrowaveweaponList.Find(x => (x != null && x.ismicow == false));
if (microwaveweapon)
{
microwaveweapon.ismicow = true;
microwaveweapon.miceopos = unmannedAerialVehicle.transform;
microwaveweapon.Orientation();
}
}
}
}
}
}
private void OnMouseDown()
{
if (equipmentCommon.isPlayer)
{
SpectrumdetectionUI.SetActive(true);
}
//SpectrumdetectionUI.SetActive(true);
}
private void OnDestroy()
{
Destroy(Frequencyiamge.gameObject);
OnActivationChanged -= OnActivationChangedHandler;
}
}