134 lines
4.2 KiB
C#
134 lines
4.2 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
/// <summary>
|
|
/// 单机测试脚本
|
|
/// </summary>
|
|
public class SingleMachineTest : MonoBehaviour
|
|
{
|
|
|
|
public List<EquipmentCommon> equipmentCommons = new List<EquipmentCommon>();
|
|
/// <summary>
|
|
/// 无人机
|
|
/// </summary>
|
|
public List<UnmannedAerialVehicleManage> unmannedAerialVehicleManages = new List<UnmannedAerialVehicleManage>();
|
|
/// <summary>
|
|
/// 雷达控制
|
|
/// </summary>
|
|
public List<RadarManger> radarMangers = new List<RadarManger>();
|
|
/// <summary>
|
|
/// 激光火控平台
|
|
/// </summary>
|
|
public List<LaserFireControlPlatformManger> laserFireControlPlatformMangers = new List<LaserFireControlPlatformManger>();
|
|
/// <summary>
|
|
/// 地面无线电干扰控制
|
|
/// </summary>
|
|
public List<TerrestrialRadioInterferenceManger> terrestrialRadioInterferenceMangers = new List<TerrestrialRadioInterferenceManger>();
|
|
|
|
|
|
|
|
private Coroutine timerCoroutine; // 协程对象
|
|
private bool isTimerRunning = false; // 定时器运行状态
|
|
public float interval = 2.0f; // 间隔时间
|
|
|
|
|
|
/// <summary>
|
|
/// 测试用
|
|
/// </summary>
|
|
public string msg1;
|
|
/// <summary>
|
|
/// 测试接受数据
|
|
/// </summary>
|
|
private AdamThinkDevicesData.DeviceData root;
|
|
void Start()
|
|
{
|
|
root = Newtonsoft.Json.JsonConvert.DeserializeObject<AdamThinkDevicesData.DeviceData>(msg1);
|
|
|
|
//unmannedAerialVehicleManages.ForEach(x => x.FillInTheData(root.data[2].list_para));
|
|
radarMangers.ForEach(x => x.FillInTheData(root.data[0].list_para));
|
|
laserFireControlPlatformMangers.ForEach(x => x.FillInTheData(root.data[3].list_para));
|
|
//terrestrialRadioInterferenceMangers.ForEach(x => x.FillInTheData(root.data[1].list_para));
|
|
// 开始协程
|
|
//StartTimer();
|
|
}
|
|
|
|
void FixedUpdate()
|
|
{
|
|
//if (Input.GetMouseButtonDown(1))
|
|
//{
|
|
// Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
|
|
// RaycastHit hitInfo;
|
|
// if (Physics.Raycast(ray, out hitInfo, 1000))
|
|
// {
|
|
// if (hitInfo.collider.tag == "WRJ")
|
|
// {
|
|
// UnmannedAerialVehicleUI.Instance.unmannedAerialVehicleManage = hitInfo.collider.GetComponent<UnmannedAerialVehicleManage>();
|
|
|
|
// }
|
|
// }
|
|
//}
|
|
}
|
|
|
|
[ContextMenu("Add")]
|
|
public void Add()
|
|
{
|
|
if (isTimerRunning)
|
|
{
|
|
isTimerRunning = false;
|
|
// 暂停定时器
|
|
Debug.Log("暂停定时器执行调用: " + Time.time);
|
|
StopTimer();
|
|
}
|
|
else
|
|
{
|
|
isTimerRunning = true;
|
|
// 继续定时器
|
|
Debug.Log("继续定时器执行调用: " + Time.time);
|
|
StartTimer();
|
|
}
|
|
}
|
|
|
|
IEnumerator Timer()
|
|
{
|
|
while (true)
|
|
{
|
|
//Debug.Log("执行调用: " + Time.time);
|
|
yield return new WaitForSeconds(interval); // 等待一段时间后继续执行
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 启动演练
|
|
/// </summary>
|
|
void StartTimer()
|
|
{
|
|
if (timerCoroutine == null)
|
|
{
|
|
timerCoroutine = StartCoroutine(Timer());
|
|
|
|
equipmentCommons.ForEach(x => x.isPlayer = true);
|
|
unmannedAerialVehicleManages.ForEach(x => x.isStartRehearsing = true);
|
|
radarMangers.ForEach(x => x.isStartRehearsing = true);
|
|
laserFireControlPlatformMangers.ForEach(x => x.isStartRehearsing = true);
|
|
terrestrialRadioInterferenceMangers.ForEach(x => x.isStartRehearsing = true);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 暂停演练
|
|
/// </summary>
|
|
void StopTimer()
|
|
{
|
|
if (timerCoroutine != null)
|
|
{
|
|
StopCoroutine(timerCoroutine);
|
|
timerCoroutine = null;
|
|
unmannedAerialVehicleManages.ForEach(x => x.isStartRehearsing = false);
|
|
radarMangers.ForEach(x => x.isStartRehearsing = false);
|
|
laserFireControlPlatformMangers.ForEach(x => x.isStartRehearsing = false);
|
|
terrestrialRadioInterferenceMangers.ForEach(x => x.isStartRehearsing = false);
|
|
}
|
|
}
|
|
}
|