diff --git a/Assets/Zion/Scripts/Adam/DeviceManager.cs b/Assets/Zion/Scripts/Adam/DeviceManager.cs index 40aedb7e..3ff32a95 100644 --- a/Assets/Zion/Scripts/Adam/DeviceManager.cs +++ b/Assets/Zion/Scripts/Adam/DeviceManager.cs @@ -14,7 +14,17 @@ public class DeviceManager : MonoSingleton { SyncCreateRoom.send2roomRequset += GetSend2roomMsg; } - + /// + /// 发送消息 + /// + public Queue send2roomStr = new Queue(); + private void Update() + { + if (send2roomStr.Count > 0) + { + _ = SyncCreateRoom.SendMessageAsync(string.Format("send2room {0}", send2roomStr.Dequeue())); + } + } public void AddDevice(EquipmentCommon d) { diff --git a/Assets/Zion/Scripts/ModelFunction/EquipmentCommon.cs b/Assets/Zion/Scripts/ModelFunction/EquipmentCommon.cs index 42afaaf2..ce69c8d5 100644 --- a/Assets/Zion/Scripts/ModelFunction/EquipmentCommon.cs +++ b/Assets/Zion/Scripts/ModelFunction/EquipmentCommon.cs @@ -164,17 +164,7 @@ public class EquipmentCommon : MonoBehaviour } - /// - /// 发送消息 - /// - public Queue send2roomStr = new Queue(); - private void Update() - { - if (send2roomStr.Count > 0) - { - _ = SyncCreateRoom.SendMessageAsync(string.Format("send2room {0}", send2roomStr.Dequeue())); - } - } + //位置实时传送 private string latestData = ""; @@ -218,15 +208,17 @@ public class EquipmentCommon : MonoBehaviour if (laserFireControlPlatformManger) laserFireControlPlatformManger.NonSelfGeneratedEmissionLaser(data); break; - case "SingleDronePosition"://单个无人机位置信息传递 + case "SingleDronePosition"://无人机攻击目标锁定 UnmannedAerialVehicleManage unmannedAerialVehicleManage = GetComponent(); if (unmannedAerialVehicleManage) { - UnmannedAerialVehicle unmannedAerialVehicle = unmannedAerialVehicleManage.unmannedAerialVehicles.Find(x => x.serialNumber == data[2]); - if (unmannedAerialVehicle) + for(int i=0;i< unmannedAerialVehicleManage.unmannedAerialVehicles.Count; i++) { - Vector3 Pos = new Vector3(float.Parse(data[3]), float.Parse(data[4]), float.Parse(data[5])); - unmannedAerialVehicle.AttAck(Pos); + if (unmannedAerialVehicleManage.unmannedAerialVehicles[i]) + { + Vector3 Pos = new Vector3(float.Parse(data[2]), float.Parse(data[3]), float.Parse(data[4])); + unmannedAerialVehicleManage.unmannedAerialVehicles[i].AttAck(Pos); + } } } break; diff --git a/Assets/Zion/Scripts/ModelFunction/UAV/UnmannedAerialVehicle.cs b/Assets/Zion/Scripts/ModelFunction/UAV/UnmannedAerialVehicle.cs index ff2cec3e..d78022e4 100644 --- a/Assets/Zion/Scripts/ModelFunction/UAV/UnmannedAerialVehicle.cs +++ b/Assets/Zion/Scripts/ModelFunction/UAV/UnmannedAerialVehicle.cs @@ -61,96 +61,15 @@ public class UnmannedAerialVehicle : MonoBehaviour /// 检测范围半径 /// public float detectionRadius = 50; // - /// - /// 是否正在攻击目标 - /// - public bool isEngagedTarget = false; + /// /// 爆炸预制体 /// 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; - } - } - } - - /// - /// 攻击目标 - /// - public void AttackATarget() - { - - if (!isEngagedTarget) - { - List colliders = Physics.OverlapSphere(transform.position, detectionRadius).ToList(); // 检索范围内的所有碰撞体 - List 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); - } - } - } - - /// - /// 发起攻击 - /// - 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("没有攻击到目标"); - } - }); - }); - } - - /// - /// 发起攻击 - /// - 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) { @@ -163,13 +82,6 @@ public class UnmannedAerialVehicle : MonoBehaviour } } - //[] - //public void AddBeAssaulted() - //{ - // BeAssaulted("无线电干扰"); - //} - - /// /// 被攻击 /// @@ -215,7 +127,7 @@ public class UnmannedAerialVehicle : MonoBehaviour string nowData = GetSyncDis(); Debug.Log(nowData); //_ = SyncCreateRoom.SendMessageAsync(string.Format("send2room {0}", nowData)); - unmannedAerialVehicleManage.equipmentCommon.send2roomStr.Enqueue(nowData); + DeviceManager.Instance.send2roomStr.Enqueue(nowData); } GameObject Bao = Instantiate(explodePrefab, transform); Bao.transform.localPosition = Vector3.zero; @@ -258,31 +170,48 @@ public class UnmannedAerialVehicle : MonoBehaviour void OnDestroy() { - transform.DOKill(); } - - - public void SendMsg(Transform attackTarget) - { - string nowData = GetSyncData(attackTarget); - Debug.Log(nowData); - unmannedAerialVehicleManage.equipmentCommon.send2roomStr.Enqueue(nowData); - //_ = SyncCreateRoom.SendMessageAsync(string.Format("send2room {0}", nowData)); - } - /// - /// 单个无人机攻击目标传递 + /// 发起攻击 /// - /// - protected string GetSyncData(Transform attackTarget) + public void AttAck(Transform target) { - return string.Format("{0},{1},{2},{3},{4},{5}", "SingleDronePosition", unmannedAerialVehicleManage.equipmentCommon.deviceID, serialNumber, - attackTarget.position.x, attackTarget.position.y, attackTarget.position.z); - + 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(() => + { + + }); + }); + } + + + + /// /// 单个无人机被销毁 /// diff --git a/Assets/Zion/Scripts/ModelFunction/UAV/UnmannedAerialVehicleManage.cs b/Assets/Zion/Scripts/ModelFunction/UAV/UnmannedAerialVehicleManage.cs index f7d8dd71..b79d0811 100644 --- a/Assets/Zion/Scripts/ModelFunction/UAV/UnmannedAerialVehicleManage.cs +++ b/Assets/Zion/Scripts/ModelFunction/UAV/UnmannedAerialVehicleManage.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using UnityEngine; using AdamThinkDevicesData; using AdamSync; +using System.Linq; /// /// 单个无人机蜂群控制 @@ -78,7 +79,14 @@ public class UnmannedAerialVehicleManage : MonoBehaviour /// public float FireSpeed = 20.0f; - + /// + /// 检测范围半径 + /// + public float detectionRadius = 50; // + /// + /// 是否正在攻击目标 + /// + public bool isEngagedTarget = false; #region 无人机数据 /// @@ -115,6 +123,8 @@ public class UnmannedAerialVehicleManage : MonoBehaviour public string opticalReconnaissanceCapability; #endregion + + // Start is called before the first frame update void Start() { @@ -140,8 +150,21 @@ public class UnmannedAerialVehicleManage : MonoBehaviour 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 } + + /// + /// 攻击打击 + /// + private void SelectiveAttackDrone() + { + if (isEngagedTarget) return; + List colliders = Physics.OverlapSphere(transform.position, detectionRadius).ToList(); // 检索范围内的所有碰撞体 + List 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 _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)); + } + /// + /// 无人机攻击目标传递 + /// + /// + 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 启动暂停 /// /// 导条变化调用