299 lines
8.6 KiB
C#
299 lines
8.6 KiB
C#
using AdamSync;
|
|
using AdamThinkDevicesData;
|
|
using DG.Tweening;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
/// <summary>
|
|
/// 微波武器
|
|
/// </summary>
|
|
public class Microwaveweapon : MonoBehaviour
|
|
{
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public EquipmentCommon equipment;
|
|
/// <summary>
|
|
/// 把自身对象存到链表
|
|
/// </summary>
|
|
public static List<Microwaveweapon> MicrowaveweaponList = new List<Microwaveweapon>();
|
|
#region 微波武器
|
|
/// <summary>
|
|
/// 储能间隔时间
|
|
/// </summary>
|
|
public string Storageintervaltime;
|
|
/// <summary>
|
|
/// 毁伤目标累计作用时间
|
|
/// </summary>
|
|
public string Microwavedamagetime;
|
|
/// <summary>
|
|
/// 干扰距离
|
|
/// </summary>
|
|
public string Microwaveinterferencedistance;
|
|
/// <summary>
|
|
/// 干扰角度
|
|
/// </summary>
|
|
public string MicrowaveinterferenceAngle;
|
|
#endregion
|
|
|
|
/// <summary>
|
|
/// 是否演练开关
|
|
/// </summary>
|
|
private bool _isStartRehearsing = false;
|
|
public bool isStartRehearsing
|
|
{
|
|
get { return _isStartRehearsing; }
|
|
set
|
|
{
|
|
if (_isStartRehearsing != value)
|
|
{
|
|
_isStartRehearsing = value;
|
|
OnActivationChanged?.Invoke(_isStartRehearsing);
|
|
}
|
|
}
|
|
}
|
|
public event System.Action<bool> OnActivationChanged;
|
|
#region
|
|
/// <summary>
|
|
/// 看向开关
|
|
/// </summary>
|
|
public bool ismicow = false;
|
|
/// <summary>
|
|
/// 微波武器打击
|
|
/// </summary>
|
|
public GameObject microwavemoder;
|
|
public GameObject microwavepoint;
|
|
public Transform miceopos;//看向无人机和打击无人机
|
|
/// <summary>
|
|
/// 微博显示
|
|
/// </summary>
|
|
public MicrowaveweaponAttack microblog;
|
|
/// <summary>
|
|
/// 微波武器发射的速度
|
|
/// </summary>
|
|
public float micspeed = 20;
|
|
|
|
public float micdistance = 0;
|
|
#endregion
|
|
/// <summary>
|
|
/// 接收每次间隔打击时间
|
|
/// </summary>
|
|
public float microwtimer;
|
|
/// <summary>
|
|
/// 关闭协程
|
|
/// </summary>
|
|
public Coroutine coroutine;
|
|
/// <summary>
|
|
/// 击毁特效
|
|
/// </summary>
|
|
public GameObject Destructioneffect;
|
|
void Start()
|
|
{
|
|
equipment = GetComponent<EquipmentCommon>();
|
|
MicrowaveweaponList.Add(this);
|
|
// 订阅布尔值变化事件
|
|
OnActivationChanged += OnActivationChangedHandler;
|
|
|
|
}
|
|
/// <summary>
|
|
/// 演练是否开始开关
|
|
/// </summary>
|
|
void OnActivationChangedHandler(bool bol)
|
|
{
|
|
if (bol)
|
|
{
|
|
Debug.Log("开始演练");
|
|
Openmode();
|
|
}
|
|
else
|
|
{
|
|
Debug.Log("暂停演练");
|
|
Offmode();
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 关闭激光打击
|
|
/// </summary>
|
|
private void Offmode()
|
|
{
|
|
if (equipment.isPlayer && coroutine != null)
|
|
{
|
|
StopCoroutine(Timern());
|
|
coroutine = null;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 开启激光打击
|
|
/// </summary>
|
|
private void Openmode()
|
|
{
|
|
if (equipment.isPlayer && coroutine == null)
|
|
{
|
|
StartCoroutine(Timern());
|
|
}
|
|
}
|
|
public IEnumerator Timern()
|
|
{
|
|
while (true)
|
|
{
|
|
yield return new WaitForSeconds(microwtimer + 1.5f);
|
|
if (miceopos != null && ismicow)
|
|
{
|
|
Launchattack();
|
|
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 攻击无人机位置上全
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
/// <exception cref="NotImplementedException"></exception>
|
|
protected string Getmicdata()
|
|
{
|
|
//Debug.Log("上传位置");
|
|
return string.Format("{0},{1},{2},{3},{4}", "Micow", equipment.deviceID, miceopos.transform.position.x, miceopos.transform.position.y, miceopos.transform.position.z);
|
|
}
|
|
private void OnMouseDown()
|
|
{
|
|
GameManager.Instance.GetAllImportance();
|
|
}
|
|
/// <summary>
|
|
/// 获取设备的参数
|
|
/// </summary>
|
|
public void FillInTheData(List<List_paraItem> weaponitemone)
|
|
{
|
|
for (int i = 0; i < weaponitemone.Count; i++)
|
|
{
|
|
switch (weaponitemone[i].para_name)
|
|
{
|
|
case "储能间隔时间:":
|
|
Storageintervaltime = weaponitemone[i].para_value;
|
|
microwtimer = float.Parse(Storageintervaltime);
|
|
break;
|
|
case "毁伤目标累积作用时间:":
|
|
Microwavedamagetime = weaponitemone[i].para_value;
|
|
break;
|
|
case "干扰距离:":
|
|
Microwaveinterferencedistance = weaponitemone[i].para_value;
|
|
micdistance = float.Parse(Microwaveinterferencedistance) * 1000;
|
|
break;
|
|
case "干扰角度:":
|
|
MicrowaveinterferenceAngle = weaponitemone[i].para_value;
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
void Update()
|
|
{
|
|
|
|
}
|
|
/// <summary>
|
|
/// 微波武器朝向无人机
|
|
/// </summary>
|
|
public void Orientation()
|
|
{
|
|
if (miceopos != null)
|
|
{
|
|
microwavepoint.transform.DOLookAt(miceopos.position, 0.1f).SetEase(Ease.Linear);
|
|
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 激光发起攻击
|
|
/// </summary>
|
|
public void Launchattack()
|
|
{
|
|
if (miceopos != null&&Vector3.Distance(miceopos.position, transform.position) < micdistance)
|
|
{
|
|
//micdistance = Vector3.Distance(miceopos.position, transform.position);
|
|
var newdata = Getmicdata();
|
|
//DeviceManager.Instance.send2roomStr.Enqueue(newdata);
|
|
MyNetMQClient.instance.Send(newdata);
|
|
//_ = SyncCreateRoom.SendMessageAsync(string.Format("send2room {0}", newdata));
|
|
//MQTTManager.instance.SendData(MQTTManager.instance.Micow, newdata);
|
|
microblog.MicrowaveDisplay(Vector3.Distance(miceopos.position, transform.position) / 10 + 1, 0.5f);
|
|
Closeattack(miceopos);
|
|
}
|
|
else
|
|
{
|
|
ismicow = false;
|
|
miceopos = null;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 上传服务器即关闭激光
|
|
/// </summary>
|
|
/// <param name="pos"></param>
|
|
/// <returns></returns>
|
|
private void Closeattack(Transform pos)
|
|
{
|
|
UnmannedAerialVehicle unmannedAerialVehicle = pos.GetComponent<UnmannedAerialVehicle>();
|
|
if (unmannedAerialVehicle != null)
|
|
{
|
|
StartCoroutine(Destructiondata(unmannedAerialVehicle));
|
|
StartCoroutine(Offlaserstrike());
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 击毁无人机
|
|
/// </summary>
|
|
public IEnumerator Destructiondata(UnmannedAerialVehicle unmannedAerialVehicle)
|
|
{
|
|
var newdata = Aeroplane(unmannedAerialVehicle);
|
|
MyNetMQClient.instance.Send(newdata);
|
|
//DeviceManager.Instance.send2roomStr.Enqueue(newdata);
|
|
//MQTTManager.instance.SendData(MQTTManager.instance.Planedata, newdata);
|
|
yield return new WaitForSeconds(0.5f);
|
|
GameObject game = Instantiate(Destructioneffect, unmannedAerialVehicle.transform);
|
|
game.transform.localPosition = Vector3.zero;
|
|
game.transform.SetParent(null);
|
|
game.SetActive(true);
|
|
Destroy(unmannedAerialVehicle.gameObject);
|
|
|
|
}
|
|
/// <summary>
|
|
/// 销毁无人机
|
|
/// </summary>
|
|
/// <param name="unmannedAerialVehicle"></param>
|
|
/// <returns></returns>
|
|
public string Aeroplane(UnmannedAerialVehicle unmannedAerialVehicle)
|
|
{
|
|
return string.Format("{0},{1},{2}", "Planedata", unmannedAerialVehicle.unmannedAerialVehicleManage.equipmentCommon.deviceID, unmannedAerialVehicle.serialNumber);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 关闭激光
|
|
/// </summary>
|
|
public IEnumerator Offlaserstrike()
|
|
{
|
|
yield return new WaitForSeconds(1.5f);
|
|
microblog.MicrowaveDisplay(0, 0f);
|
|
ismicow = false;
|
|
}
|
|
/// <summary>
|
|
/// 接受数据微波武器激光下发
|
|
/// </summary>
|
|
public void Microwavetransmission(string[] data)
|
|
{
|
|
//接收激光下发的位置
|
|
Vector3 vector = new Vector3(float.Parse(data[2]), float.Parse(data[3]), float.Parse(data[4]));
|
|
float _micdistance = Vector3.Distance(vector, transform.position);
|
|
microwavepoint.transform.DOLookAt(vector, 0.1f).SetEase(Ease.Linear).OnComplete(() =>
|
|
{
|
|
microblog.MicrowaveDisplay(_micdistance / 10 + 1, 0.5f);
|
|
StartCoroutine(Offlaserstrike());
|
|
});
|
|
|
|
}
|
|
private void OnDestroy()
|
|
{
|
|
OnActivationChanged -= OnActivationChangedHandler;
|
|
}
|
|
}
|