无人机攻击交互
This commit is contained in:
parent
4e53845d3f
commit
61df6df538
|
@ -14,7 +14,17 @@ public class DeviceManager : MonoSingleton<DeviceManager>
|
||||||
{
|
{
|
||||||
SyncCreateRoom.send2roomRequset += GetSend2roomMsg;
|
SyncCreateRoom.send2roomRequset += GetSend2roomMsg;
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 发送消息
|
||||||
|
/// </summary>
|
||||||
|
public Queue<string> send2roomStr = new Queue<string>();
|
||||||
|
private void Update()
|
||||||
|
{
|
||||||
|
if (send2roomStr.Count > 0)
|
||||||
|
{
|
||||||
|
_ = SyncCreateRoom.SendMessageAsync(string.Format("send2room {0}", send2roomStr.Dequeue()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void AddDevice(EquipmentCommon d)
|
public void AddDevice(EquipmentCommon d)
|
||||||
{
|
{
|
||||||
|
|
|
@ -164,17 +164,7 @@ public class EquipmentCommon : MonoBehaviour
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 发送消息
|
|
||||||
/// </summary>
|
|
||||||
public Queue<string> send2roomStr = new Queue<string>();
|
|
||||||
private void Update()
|
|
||||||
{
|
|
||||||
if (send2roomStr.Count > 0)
|
|
||||||
{
|
|
||||||
_ = SyncCreateRoom.SendMessageAsync(string.Format("send2room {0}", send2roomStr.Dequeue()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//位置实时传送
|
//位置实时传送
|
||||||
private string latestData = "";
|
private string latestData = "";
|
||||||
|
@ -218,15 +208,17 @@ public class EquipmentCommon : MonoBehaviour
|
||||||
if (laserFireControlPlatformManger)
|
if (laserFireControlPlatformManger)
|
||||||
laserFireControlPlatformManger.NonSelfGeneratedEmissionLaser(data);
|
laserFireControlPlatformManger.NonSelfGeneratedEmissionLaser(data);
|
||||||
break;
|
break;
|
||||||
case "SingleDronePosition"://单个无人机位置信息传递
|
case "SingleDronePosition"://无人机攻击目标锁定
|
||||||
UnmannedAerialVehicleManage unmannedAerialVehicleManage = GetComponent<UnmannedAerialVehicleManage>();
|
UnmannedAerialVehicleManage unmannedAerialVehicleManage = GetComponent<UnmannedAerialVehicleManage>();
|
||||||
if (unmannedAerialVehicleManage)
|
if (unmannedAerialVehicleManage)
|
||||||
{
|
{
|
||||||
UnmannedAerialVehicle unmannedAerialVehicle = unmannedAerialVehicleManage.unmannedAerialVehicles.Find(x => x.serialNumber == data[2]);
|
for(int i=0;i< unmannedAerialVehicleManage.unmannedAerialVehicles.Count; i++)
|
||||||
if (unmannedAerialVehicle)
|
|
||||||
{
|
{
|
||||||
Vector3 Pos = new Vector3(float.Parse(data[3]), float.Parse(data[4]), float.Parse(data[5]));
|
if (unmannedAerialVehicleManage.unmannedAerialVehicles[i])
|
||||||
unmannedAerialVehicle.AttAck(Pos);
|
{
|
||||||
|
Vector3 Pos = new Vector3(float.Parse(data[2]), float.Parse(data[3]), float.Parse(data[4]));
|
||||||
|
unmannedAerialVehicleManage.unmannedAerialVehicles[i].AttAck(Pos);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -61,96 +61,15 @@ public class UnmannedAerialVehicle : MonoBehaviour
|
||||||
/// 检测范围半径
|
/// 检测范围半径
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public float detectionRadius = 50; //
|
public float detectionRadius = 50; //
|
||||||
/// <summary>
|
|
||||||
/// 是否正在攻击目标
|
|
||||||
/// </summary>
|
|
||||||
public bool isEngagedTarget = false;
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 爆炸预制体
|
/// 爆炸预制体
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public GameObject explodePrefab;
|
public GameObject explodePrefab;
|
||||||
|
|
||||||
// Start is called before the first frame update
|
|
||||||
void Start()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update is called once per frame
|
|
||||||
void Update()
|
|
||||||
{
|
|
||||||
if (unmannedAerialVehicleManage && unmannedAerialVehicleManage.equipmentCommon.isPlayer && unmannedAerialVehicleManage.isStartRehearsing)
|
|
||||||
{
|
|
||||||
switch (unmannedAerialVehicleManage.pattern)
|
|
||||||
{
|
|
||||||
case Pattern.待机:
|
|
||||||
break;
|
|
||||||
case Pattern.警戒:
|
|
||||||
AttackATarget();
|
|
||||||
break;
|
|
||||||
case Pattern.攻击:
|
|
||||||
AttackATarget();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 攻击目标
|
|
||||||
/// </summary>
|
|
||||||
public void AttackATarget()
|
|
||||||
{
|
|
||||||
|
|
||||||
if (!isEngagedTarget)
|
|
||||||
{
|
|
||||||
List<Collider> colliders = Physics.OverlapSphere(transform.position, detectionRadius).ToList(); // 检索范围内的所有碰撞体
|
|
||||||
List<Collider> colliders1 = colliders.FindAll(x => x.transform.tag == "AttackTarget");
|
|
||||||
if (colliders1.Count > 0)
|
|
||||||
{
|
|
||||||
colliders1.ForEach(x => Debug.Log(x.transform.name));
|
|
||||||
int _number = Random.Range(0, colliders1.Count - 1);
|
|
||||||
isEngagedTarget = true;
|
|
||||||
Debug.Log(colliders1[_number].transform.name);
|
|
||||||
AttAck(colliders1[_number].transform);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 发起攻击
|
|
||||||
/// </summary>
|
|
||||||
private void AttAck(Transform target)
|
|
||||||
{
|
|
||||||
Debug.Log("开始攻击目标..:" + target.name);
|
|
||||||
Vector3 _v3 = target.position;
|
|
||||||
SendMsg(target);
|
|
||||||
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(() =>
|
|
||||||
{
|
|
||||||
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnTriggerEnter(Collider other)
|
private void OnTriggerEnter(Collider other)
|
||||||
{
|
{
|
||||||
|
@ -163,13 +82,6 @@ public class UnmannedAerialVehicle : MonoBehaviour
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//[]
|
|
||||||
//public void AddBeAssaulted()
|
|
||||||
//{
|
|
||||||
// BeAssaulted("无线电干扰");
|
|
||||||
//}
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 被攻击
|
/// 被攻击
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -215,7 +127,7 @@ public class UnmannedAerialVehicle : MonoBehaviour
|
||||||
string nowData = GetSyncDis();
|
string nowData = GetSyncDis();
|
||||||
Debug.Log(nowData);
|
Debug.Log(nowData);
|
||||||
//_ = SyncCreateRoom.SendMessageAsync(string.Format("send2room {0}", nowData));
|
//_ = SyncCreateRoom.SendMessageAsync(string.Format("send2room {0}", nowData));
|
||||||
unmannedAerialVehicleManage.equipmentCommon.send2roomStr.Enqueue(nowData);
|
DeviceManager.Instance.send2roomStr.Enqueue(nowData);
|
||||||
}
|
}
|
||||||
GameObject Bao = Instantiate(explodePrefab, transform);
|
GameObject Bao = Instantiate(explodePrefab, transform);
|
||||||
Bao.transform.localPosition = Vector3.zero;
|
Bao.transform.localPosition = Vector3.zero;
|
||||||
|
@ -258,31 +170,48 @@ public class UnmannedAerialVehicle : MonoBehaviour
|
||||||
|
|
||||||
void OnDestroy()
|
void OnDestroy()
|
||||||
{
|
{
|
||||||
|
|
||||||
transform.DOKill();
|
transform.DOKill();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
public void SendMsg(Transform attackTarget)
|
/// 发起攻击
|
||||||
|
/// </summary>
|
||||||
|
public void AttAck(Transform target)
|
||||||
{
|
{
|
||||||
string nowData = GetSyncData(attackTarget);
|
Debug.Log("开始攻击目标..:" + target.name);
|
||||||
Debug.Log(nowData);
|
Vector3 _v3 = target.position;
|
||||||
unmannedAerialVehicleManage.equipmentCommon.send2roomStr.Enqueue(nowData);
|
|
||||||
//_ = SyncCreateRoom.SendMessageAsync(string.Format("send2room {0}", nowData));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
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>
|
||||||
/// 单个无人机攻击目标传递
|
/// 发起攻击
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
public void AttAck(Vector3 target)
|
||||||
protected string GetSyncData(Transform attackTarget)
|
|
||||||
{
|
{
|
||||||
return string.Format("{0},{1},{2},{3},{4},{5}", "SingleDronePosition", unmannedAerialVehicleManage.equipmentCommon.deviceID, serialNumber,
|
transform.DOLookAt(target, 0.1f).OnComplete(() =>
|
||||||
attackTarget.position.x, attackTarget.position.y, attackTarget.position.z);
|
{
|
||||||
|
float distance = Vector3.Distance(transform.position, target);
|
||||||
|
transform.DOMove(target, distance / FireSpeed).SetEase(Ease.Linear).OnComplete(() =>
|
||||||
|
{
|
||||||
|
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 单个无人机被销毁
|
/// 单个无人机被销毁
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
@ -5,6 +5,7 @@ using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using AdamThinkDevicesData;
|
using AdamThinkDevicesData;
|
||||||
using AdamSync;
|
using AdamSync;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 单个无人机蜂群控制
|
/// 单个无人机蜂群控制
|
||||||
|
@ -78,7 +79,14 @@ public class UnmannedAerialVehicleManage : MonoBehaviour
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public float FireSpeed = 20.0f;
|
public float FireSpeed = 20.0f;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 检测范围半径
|
||||||
|
/// </summary>
|
||||||
|
public float detectionRadius = 50; //
|
||||||
|
/// <summary>
|
||||||
|
/// 是否正在攻击目标
|
||||||
|
/// </summary>
|
||||||
|
public bool isEngagedTarget = false;
|
||||||
|
|
||||||
#region 无人机数据
|
#region 无人机数据
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -115,6 +123,8 @@ public class UnmannedAerialVehicleManage : MonoBehaviour
|
||||||
public string opticalReconnaissanceCapability;
|
public string opticalReconnaissanceCapability;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
// Start is called before the first frame update
|
// Start is called before the first frame update
|
||||||
void Start()
|
void Start()
|
||||||
{
|
{
|
||||||
|
@ -140,7 +150,20 @@ public class UnmannedAerialVehicleManage : MonoBehaviour
|
||||||
StartMoveObjectAlongPath();
|
StartMoveObjectAlongPath();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (equipmentCommon.isPlayer &&isStartRehearsing)
|
||||||
|
{
|
||||||
|
switch (pattern)
|
||||||
|
{
|
||||||
|
case Pattern.待机:
|
||||||
|
break;
|
||||||
|
case Pattern.警戒:
|
||||||
|
SelectiveAttackDrone();
|
||||||
|
break;
|
||||||
|
case Pattern.攻击:
|
||||||
|
SelectiveAttackDrone();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -167,6 +190,47 @@ public class UnmannedAerialVehicleManage : MonoBehaviour
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 攻击打击
|
||||||
|
/// </summary>
|
||||||
|
private void SelectiveAttackDrone()
|
||||||
|
{
|
||||||
|
if (isEngagedTarget) return;
|
||||||
|
List<Collider> colliders = Physics.OverlapSphere(transform.position, detectionRadius).ToList(); // 检索范围内的所有碰撞体
|
||||||
|
List<Collider> colliders1 = colliders.FindAll(x => x.transform.tag == "AttackTarget");
|
||||||
|
if (colliders1.Count > 0)
|
||||||
|
{
|
||||||
|
isEngagedTarget = true;
|
||||||
|
colliders1.ForEach(x => Debug.Log(x.transform.name));
|
||||||
|
int _number = UnityEngine.Random.Range(0, colliders1.Count - 1);
|
||||||
|
List<UnmannedAerialVehicle> _unmannedAerialVehicles = unmannedAerialVehicles.FindAll(x => x != null);
|
||||||
|
SendMsg(colliders1[_number].transform);
|
||||||
|
for (int i = 0; i < _unmannedAerialVehicles.Count; i++)
|
||||||
|
{
|
||||||
|
_unmannedAerialVehicles[i].AttAck(colliders1[_number].transform);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SendMsg(Transform attackTarget)
|
||||||
|
{
|
||||||
|
string nowData = GetSyncData(attackTarget);
|
||||||
|
Debug.Log(nowData);
|
||||||
|
_ = SyncCreateRoom.SendMessageAsync(string.Format("send2room {0}", nowData));
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 无人机攻击目标传递
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
protected string GetSyncData(Transform attackTarget)
|
||||||
|
{
|
||||||
|
return string.Format("{0},{1},{2},{3},{4}", "SingleDronePosition", equipmentCommon.deviceID,
|
||||||
|
attackTarget.position.x, attackTarget.position.y, attackTarget.position.z);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#region 启动暂停
|
#region 启动暂停
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 导条变化调用
|
/// 导条变化调用
|
||||||
|
|
Loading…
Reference in New Issue