297 lines
9.2 KiB
C#
297 lines
9.2 KiB
C#
using AdamSync;
|
|
using AdamThinkDevicesData;
|
|
using DG.Tweening;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class Microwaveweapon : MonoBehaviour
|
|
{
|
|
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;//看向无人机和打击无人机
|
|
public GameObject InnerLaserlineRendererPrefab1;//用来发射微波激光武器
|
|
public GameObject OuterLaserlineRendererPrefab1;//用来绘制射线的
|
|
public LineRenderer InnerLaserlineRenderer1;
|
|
public LineRenderer OuterLaserlineRenderer1;
|
|
/// <summary>
|
|
/// 微波武器发射的速度
|
|
/// </summary>
|
|
public float micspeed = 20;
|
|
#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;
|
|
//微波武器进攻的地方
|
|
GameObject sendgame = Instantiate(InnerLaserlineRendererPrefab1);
|
|
sendgame.transform.position = Vector3.zero;
|
|
InnerLaserlineRenderer1 = sendgame.GetComponent<LineRenderer>();
|
|
if (InnerLaserlineRenderer1)
|
|
{
|
|
InnerLaserlineRenderer1.positionCount = 2;
|
|
InnerLaserlineRenderer1.SetPosition(0, microwavepoint.transform.position);
|
|
InnerLaserlineRenderer1.SetPosition(1, microwavepoint.transform.position);
|
|
}
|
|
|
|
GameObject sendsgames = Instantiate(OuterLaserlineRendererPrefab1);
|
|
sendsgames.transform.position = Vector3.zero;
|
|
OuterLaserlineRenderer1 = sendsgames.GetComponent<LineRenderer>();
|
|
if (OuterLaserlineRenderer1)
|
|
{
|
|
OuterLaserlineRenderer1.positionCount = 2;
|
|
OuterLaserlineRenderer1.SetPosition(0, microwavepoint.transform.position);
|
|
OuterLaserlineRenderer1.SetPosition(1, microwavepoint.transform.position);
|
|
}
|
|
}
|
|
/// <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);
|
|
Debug.LogError("攻击了");
|
|
if (microwtimer>0&&miceopos!=null)
|
|
{
|
|
Launchattack();
|
|
var newdata = Getmicdata();
|
|
_ = SyncCreateRoom.SendMessageAsync(string.Format("send2room {0}", newdata));
|
|
}
|
|
}
|
|
}
|
|
/// <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);
|
|
}
|
|
|
|
/// <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;
|
|
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);
|
|
ismicow = false;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 激光发起攻击
|
|
/// </summary>
|
|
public void Launchattack()
|
|
{
|
|
if (miceopos!=null)
|
|
{
|
|
if (InnerLaserlineRenderer1)
|
|
{
|
|
InnerLaserlineRenderer1.SetPosition(0, microwavepoint.transform.position);
|
|
InnerLaserlineRenderer1.SetPosition(1, miceopos.transform.position);
|
|
}
|
|
if (OuterLaserlineRenderer1)
|
|
{
|
|
OuterLaserlineRenderer1.SetPosition(0, microwavepoint.transform.position);
|
|
OuterLaserlineRenderer1.SetPosition(1, miceopos.transform.position);
|
|
}
|
|
Closeattack(miceopos);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 上传服务器即关闭激光
|
|
/// </summary>
|
|
/// <param name="pos"></param>
|
|
/// <returns></returns>
|
|
private void Closeattack(Transform pos)
|
|
{
|
|
UnmannedAerialVehicle unmannedAerialVehicle =pos.GetComponent<UnmannedAerialVehicle>();
|
|
if (unmannedAerialVehicle!=null)
|
|
{
|
|
Destructiondata(unmannedAerialVehicle);
|
|
StartCoroutine(Offlaserstrike());
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 击毁无人机
|
|
/// </summary>
|
|
public void Destructiondata(UnmannedAerialVehicle unmannedAerialVehicle)
|
|
{
|
|
var newdata = Aeroplane(unmannedAerialVehicle);
|
|
DeviceManager.Instance.send2roomStr.Enqueue(newdata);
|
|
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(1f);
|
|
if (InnerLaserlineRenderer1)
|
|
{
|
|
InnerLaserlineRenderer1.SetPosition(0, microwavepoint.transform.position);//射线起点位置
|
|
InnerLaserlineRenderer1.SetPosition(1, microwavepoint.transform.position);//射线终点位置
|
|
}
|
|
if (OuterLaserlineRenderer1)
|
|
{
|
|
OuterLaserlineRenderer1.SetPosition(0, microwavepoint.transform.position);//射线起点位置
|
|
OuterLaserlineRenderer1.SetPosition(1, microwavepoint.transform.position);//射线终点位置
|
|
}
|
|
ismicow = false;
|
|
}
|
|
private void OnDestroy()
|
|
{
|
|
OnActivationChanged -= OnActivationChangedHandler;
|
|
}
|
|
}
|