226 lines
6.0 KiB
C#
226 lines
6.0 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using DG.Tweening;
|
|
using System.Linq;
|
|
using AdamSync;
|
|
|
|
/// <summary>
|
|
/// 无人机
|
|
/// </summary>
|
|
public class UnmannedAerialVehicle : MonoBehaviour
|
|
{
|
|
/// <summary>
|
|
/// 所属无人机蜂群
|
|
/// </summary>
|
|
public UnmannedAerialVehicleManage unmannedAerialVehicleManage;
|
|
/// <summary>
|
|
/// 序列编号
|
|
/// </summary>
|
|
public string serialNumber = "";
|
|
|
|
#region 无人机数据
|
|
/// <summary>
|
|
/// 续航时间
|
|
/// </summary>
|
|
public string batteryLife;
|
|
/// <summary>
|
|
/// 抗风等级
|
|
/// </summary>
|
|
public string classificationWindResistance;
|
|
/// <summary>
|
|
/// 最大飞行速度
|
|
/// </summary>
|
|
public string maximumFlyingSpeed;
|
|
/// <summary>
|
|
/// RCS
|
|
/// </summary>
|
|
public string RCS;
|
|
/// <summary>
|
|
/// 卫星定位频点
|
|
/// </summary>
|
|
public string satellitePositioningFrequency;
|
|
/// <summary>
|
|
/// 数据链通信频点
|
|
/// </summary>
|
|
public string dataLinkCommunicationFrequency;
|
|
/// <summary>
|
|
/// 电子侦察能力
|
|
/// </summary>
|
|
public string electronicReconnaissanceCapability;
|
|
/// <summary>
|
|
/// 光学侦察能力
|
|
/// </summary>
|
|
public string opticalReconnaissanceCapability;
|
|
#endregion
|
|
/// <summary>
|
|
/// 飞行速度
|
|
/// </summary>
|
|
public float FireSpeed = 20.0f;
|
|
/// <summary>
|
|
/// 检测范围半径
|
|
/// </summary>
|
|
public float detectionRadius = 50; //
|
|
|
|
/// <summary>
|
|
/// 爆炸预制体
|
|
/// </summary>
|
|
public GameObject explodePrefab;
|
|
|
|
|
|
|
|
|
|
|
|
private void OnTriggerEnter(Collider other)
|
|
{
|
|
if (unmannedAerialVehicleManage.equipmentCommon.isPlayer && other.tag == "AttackTarget")
|
|
{
|
|
AddBao(other.transform);
|
|
// 销毁objectToDestroy对象
|
|
BeAssaulted("攻击到目标");
|
|
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 被攻击
|
|
/// </summary>
|
|
/// <param name="type"></param>
|
|
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;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 销毁单体无人机
|
|
/// </summary>
|
|
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<BoxCollider>();
|
|
//// 移除组件
|
|
//if (component != null)
|
|
//{
|
|
// Destroy(component);
|
|
// transform.localScale = Vector3.zero;
|
|
//}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 销毁蓝方设备
|
|
/// </summary>
|
|
/// <param name="_transform"></param>
|
|
void AddBao(Transform _transform)
|
|
{
|
|
EquipmentCommon _equipmentCommon = _transform.GetComponent<EquipmentCommon>();
|
|
string nowData = string.Format("{0},{1}", "SetToBeDestroyed", _equipmentCommon.deviceID);
|
|
Debug.Log(nowData);
|
|
_ = SyncCreateRoom.SendMessageAsync(string.Format("send2room {0}", nowData));
|
|
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();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 发起攻击
|
|
/// </summary>
|
|
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("没有攻击到目标");
|
|
}
|
|
});
|
|
});
|
|
}
|
|
|
|
/// <summary>
|
|
/// 发起攻击
|
|
/// </summary>
|
|
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(() =>
|
|
{
|
|
|
|
});
|
|
});
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 单个无人机被销毁
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
protected string GetSyncDis()
|
|
{
|
|
return string.Format("{0},{1},{2}", "DroneWasDestroyed", unmannedAerialVehicleManage.equipmentCommon.deviceID, serialNumber);
|
|
}
|
|
|
|
|
|
}
|