using System.Collections;
using System.Collections.Generic;
using UnityEngine;
///
/// 单机测试脚本
///
public class SingleMachineTest : MonoBehaviour
{
public List equipmentCommons = new List();
///
/// 无人机
///
public List unmannedAerialVehicleManages = new List();
///
/// 雷达控制
///
public List radarMangers = new List();
///
/// 激光火控平台
///
public List laserFireControlPlatformMangers = new List();
///
/// 地面无线电干扰控制
///
public List terrestrialRadioInterferenceMangers = new List();
private Coroutine timerCoroutine; // 协程对象
private bool isTimerRunning = false; // 定时器运行状态
public float interval = 2.0f; // 间隔时间
///
/// 测试用
///
public string msg1;
///
/// 测试接受数据
///
private AdamThinkDevicesData.DeviceData root;
void Start()
{
root = Newtonsoft.Json.JsonConvert.DeserializeObject(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();
// }
// }
//}
}
[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); // 等待一段时间后继续执行
}
}
///
/// 启动演练
///
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);
}
}
///
/// 暂停演练
///
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);
}
}
}