using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using DG.Tweening;
using System.Linq;
using AdamSync;
using static InterfaceManager;
///
/// 无人机
///
public class UnmannedAerialVehicle : MonoBehaviour
{
///
/// 所属无人机蜂群
///
public UnmannedAerialVehicleManage unmannedAerialVehicleManage;
///
/// 序列编号
///
public string serialNumber = "";
#region 无人机数据
///
/// 续航时间
///
public string batteryLife;
///
/// 抗风等级
///
public string classificationWindResistance;
///
/// 最大飞行速度
///
public string maximumFlyingSpeed;
///
/// RCS
///
public string RCS;
///
/// 卫星定位频点
///
public string satellitePositioningFrequency;
///
/// 数据链通信频点
///
public string dataLinkCommunicationFrequency;
///
/// 电子侦察能力
///
public string electronicReconnaissanceCapability;
///
/// 光学侦察能力
///
public string opticalReconnaissanceCapability;
#endregion
///
/// 飞行速度
///
public float FireSpeed = 20.0f;
///
/// 检测范围半径
///
public float detectionRadius = 50; //
///
/// 爆炸预制体
///
public GameObject explodePrefab;
private void OnTriggerEnter(Collider other)
{
if (unmannedAerialVehicleManage.equipmentCommon.isPlayer && other.tag == "AttackTarget")
{
AddBao(other.transform);
// 销毁objectToDestroy对象
BeAssaulted("攻击到目标");
}
}
///
/// 被攻击
///
///
public void BeAssaulted(string type)
{
switch (type)
{
case "激光打击":
AddBao(true);
//Debug.Log(transform.name+"被激光打击销毁了");
break;
case "无线电干扰":
Vector3 _pos = transform.position - new Vector3(0, 30, 0);
transform.LookAt(_pos);
transform.DOMove(_pos, 1).OnComplete(() =>
{
AddBao(true);
});
//Debug.Log(transform.name + "无人机被无线电干扰销毁了");
break;
case "攻击到目标":
AddBao(true);
//Debug.Log(transform.name + "无人机自杀式攻击销毁了");
break;
case "没有攻击到目标":
AddBao(true);
//Debug.Log(transform.name + "无人机自杀式没有攻击到目标撞击地面销毁了");
break;
default:
break;
}
}
///
/// 销毁单体无人机
///
public void AddBao(bool isPassMessage)
{
if (isPassMessage)
{
string nowData = GetSyncDis();
Debug.Log(nowData);
//_ = SyncCreateRoom.SendMessageAsync(string.Format("send2room {0}", nowData));
DeviceManager.Instance.send2roomStr.Enqueue(nowData);
}
GameObject Bao = Instantiate(explodePrefab, transform);
Bao.transform.localPosition = Vector3.zero;
Bao.transform.SetParent(null);
Bao.SetActive(true);
Destroy(gameObject);
// 获取组件
//Component component = gameObject.GetComponent();
//// 移除组件
//if (component != null)
//{
// Destroy(component);
// transform.localScale = Vector3.zero;
//}
}
///
/// 销毁蓝方设备
///
///
void AddBao(Transform _transform)
{
EquipmentCommon _equipmentCommon = _transform.GetComponent();
string nowData = string.Format("{0},{1}", "SetToBeDestroyed", _equipmentCommon.deviceID);
Debug.Log(nowData);
_ = SyncCreateRoom.SendMessageAsync(string.Format("send2room {0}", nowData));
Dictionary headers = new Dictionary();
headers.Add("id", _equipmentCommon.deviceID);
StartCoroutine(GetString(Url_Deletepracticedevicedetail, headers, data => {
Debug.Log(data);
}));
GameObject Bao = Instantiate(explodePrefab, _transform);
Bao.transform.localPosition = Vector3.zero;
Bao.transform.SetParent(null);
Bao.SetActive(true);
Destroy(_transform.gameObject);
}
private void OnBecameInvisible()
{
Debug.Log("测试");
}
void OnDestroy()
{
transform.DOKill();
}
///
/// 发起攻击
///
public void AttAck(Transform target)
{
Debug.Log("开始攻击目标..:" + target.name);
Vector3 _v3 = target.position;
transform.DOLookAt(_v3, 0.1f).OnComplete(() =>
{
float distance = Vector3.Distance(transform.position, target.position);
transform.DOMove(target.position, distance / FireSpeed).SetEase(Ease.Linear).OnComplete(() =>
{
if (!target)
{
BeAssaulted("没有攻击到目标");
}
});
});
}
///
/// 发起攻击
///
public void AttAck(Vector3 target)
{
transform.DOLookAt(target, 0.1f).OnComplete(() =>
{
float distance = Vector3.Distance(transform.position, target);
transform.DOMove(target, distance / FireSpeed).SetEase(Ease.Linear).OnComplete(() =>
{
});
});
}
///
/// 单个无人机被销毁
///
///
protected string GetSyncDis()
{
return string.Format("{0},{1},{2}", "DroneWasDestroyed", unmannedAerialVehicleManage.equipmentCommon.deviceID, serialNumber);
}
}