From 8ddc76956dd3895fad29facea5f08227613566c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B4=A6=E5=8F=B7=E5=90=8D?= <3077614386@qq.com> Date: Thu, 23 Nov 2023 23:18:14 +0800 Subject: [PATCH] =?UTF-8?q?=E6=97=A0=E4=BA=BA=E6=9C=BA=E7=BE=A4=E8=B7=AF?= =?UTF-8?q?=E7=BA=BF=E5=8F=8A=E9=A3=9E=E8=A1=8C=E8=A7=84=E5=88=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Prefebs/Models/moder/无人机List.prefab | 4 +- Assets/Zion/Scenes/InitConnect.unity | 2 +- Assets/Zion/Scenes/单机演练.unity | 8 +-- .../DrawingLine/ObjectPlanner.cs | 20 ++++---- .../Scripts/ModelFunction/EquipmentCommon.cs | 47 ++++++++--------- .../UAV/UnmannedAerialVehicleManage.cs | 51 +++++++++++++------ 6 files changed, 74 insertions(+), 58 deletions(-) diff --git a/Assets/GameAssets/Prefebs/Models/moder/无人机List.prefab b/Assets/GameAssets/Prefebs/Models/moder/无人机List.prefab index c564519b..c0bba40c 100644 --- a/Assets/GameAssets/Prefebs/Models/moder/无人机List.prefab +++ b/Assets/GameAssets/Prefebs/Models/moder/无人机List.prefab @@ -345,11 +345,13 @@ MonoBehaviour: - {fileID: 5185013363439366923} - {fileID: 6839647458606122297} - {fileID: 4299622186163530999} - LinePrefab: {fileID: 739704727871026136, guid: 01a28b65d7e53484b8bab2f3cc69ab91, + LinePrefab: {fileID: 739704727871026136, guid: 3e35ca2d6b8539a45b9b9bd9ec287f2b, type: 3} airRoute: {fileID: 0} endPosition: {x: 0, y: 0, z: 0} FireSpeed: 20 + detectionRadius: 50 + isEngagedTarget: 0 batteryLife: 1 classificationWindResistance: 1 maximumFlyingSpeed: 1 diff --git a/Assets/Zion/Scenes/InitConnect.unity b/Assets/Zion/Scenes/InitConnect.unity index 65d97e7b..27ab351d 100644 --- a/Assets/Zion/Scenes/InitConnect.unity +++ b/Assets/Zion/Scenes/InitConnect.unity @@ -240,7 +240,7 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: isLinkAgain: 0 - serverIP: 127.0.0.1 + serverIP: 192.168.6.63 port: 12345 --- !u!4 &2132962759 Transform: diff --git a/Assets/Zion/Scenes/单机演练.unity b/Assets/Zion/Scenes/单机演练.unity index 54078ba6..c94b7cbf 100644 --- a/Assets/Zion/Scenes/单机演练.unity +++ b/Assets/Zion/Scenes/单机演练.unity @@ -767,7 +767,7 @@ PrefabInstance: - target: {fileID: 625513913607457920, guid: 121324ce722bdb944a7cc1c7c3a5077f, type: 3} propertyPath: m_IsActive - value: 1 + value: 0 objectReference: {fileID: 0} m_RemovedComponents: [] m_SourcePrefab: {fileID: 100100000, guid: 121324ce722bdb944a7cc1c7c3a5077f, type: 3} @@ -1039,7 +1039,7 @@ PrefabInstance: - target: {fileID: 3977472425108262603, guid: 2b2524df6b4053a4aa08b1f5fe4d62f5, type: 3} propertyPath: m_IsActive - value: 1 + value: 0 objectReference: {fileID: 0} m_RemovedComponents: [] m_SourcePrefab: {fileID: 100100000, guid: 2b2524df6b4053a4aa08b1f5fe4d62f5, type: 3} @@ -2006,7 +2006,7 @@ PrefabInstance: - target: {fileID: 7615181139496386322, guid: 7abae14e48a106d4c8120d0eba515162, type: 3} propertyPath: m_IsActive - value: 1 + value: 0 objectReference: {fileID: 0} - target: {fileID: 7615181139496386328, guid: 7abae14e48a106d4c8120d0eba515162, type: 3} @@ -2085,7 +2085,7 @@ PrefabInstance: - target: {fileID: 7615181139496386322, guid: 7abae14e48a106d4c8120d0eba515162, type: 3} propertyPath: m_IsActive - value: 1 + value: 0 objectReference: {fileID: 0} - target: {fileID: 7615181139496386328, guid: 7abae14e48a106d4c8120d0eba515162, type: 3} diff --git a/Assets/Zion/Scripts/ModelFunction/DrawingLine/ObjectPlanner.cs b/Assets/Zion/Scripts/ModelFunction/DrawingLine/ObjectPlanner.cs index 5d227ed4..a8968978 100644 --- a/Assets/Zion/Scripts/ModelFunction/DrawingLine/ObjectPlanner.cs +++ b/Assets/Zion/Scripts/ModelFunction/DrawingLine/ObjectPlanner.cs @@ -60,16 +60,16 @@ public class ObjectPlanner : MonoBehaviour { isPlanning = false; // 停止规划路线 - Vector3[] positions = new Vector3[lineRenderer.positionCount]; // 创建用于存储顶点坐标的数组 - lineRenderer.GetPositions(positions); // 获取线条的顶点坐标 - if (unmannedAerialVehicleManage) - { - for (int i = 0; i < positions.Length; i++) - { - unmannedAerialVehicleManage.positions.Enqueue(positions[i]); - unmannedAerialVehicleManage.endPosition = positions[positions.Length - 1]; - } - } + //Vector3[] positions = new Vector3[lineRenderer.positionCount]; // 创建用于存储顶点坐标的数组 + //lineRenderer.GetPositions(positions); // 获取线条的顶点坐标 + //if (unmannedAerialVehicleManage) + //{ + // for (int i = 0; i < positions.Length; i++) + // { + // unmannedAerialVehicleManage.positions.Enqueue(positions[i]); + // unmannedAerialVehicleManage.endPosition = positions[positions.Length - 1]; + // } + //} } } } diff --git a/Assets/Zion/Scripts/ModelFunction/EquipmentCommon.cs b/Assets/Zion/Scripts/ModelFunction/EquipmentCommon.cs index ce69c8d5..cb7957de 100644 --- a/Assets/Zion/Scripts/ModelFunction/EquipmentCommon.cs +++ b/Assets/Zion/Scripts/ModelFunction/EquipmentCommon.cs @@ -76,13 +76,9 @@ public class EquipmentCommon : MonoBehaviour } void OnActivationChangedIsPlayer(bool newValue) { - if (newValue && equipmentType == "无人机List" && isOnlyOne) + if (newValue && equipmentType == "无人机List") { - isOnlyOne = false; - latestData = GetSyncData(); - InvokeRepeating("SendMsg", 0, 0.01f); - UnmannedAerialVehicleManage unmannedAerialVehicleManage = GetComponent(); - //unmannedAerialVehicleManage.unmannedAerialVehicles.ForEach(x => x.AddSendMsg());//每个无人机位置传递开启 + } } /// @@ -163,30 +159,29 @@ public class EquipmentCommon : MonoBehaviour } } + /// + /// 已有路径 + /// + public Queue positions = new Queue(); - - //位置实时传送 - private string latestData = ""; - private bool isOnlyOne = true; - public void SendMsg() + public bool isMove = true; + /// + /// 按规划路径开始移动 + /// + public void StartMoveObjectAlongPath() { - var nowData = GetSyncData(); - if (!nowData.Equals(latestData)) + if (isMove && positions.Count > 0) { - latestData = nowData; - Debug.Log(latestData); - _ = SyncCreateRoom.SendMessageAsync(string.Format("send2room {0}", nowData)); + isMove = false; + Vector3 _positions = positions.Dequeue(); + UnmannedAerialVehicleManage unmannedAerialVehicleManage = GetComponent(); + if (unmannedAerialVehicleManage) + StartCoroutine(unmannedAerialVehicleManage.MoveObjectAlongPath(_positions,isMove)); // 启动协程,按规划的路线移动物体 } } - /// - /// 无人机整体位置传递 - /// - /// - protected string GetSyncData() - { - return string.Format("{0},{1},{2},{3},{4},{5},{6},{7}", "DronePosition", equipmentCommon.deviceID, transform.position.x, transform.position.y, transform.position.z, transform.eulerAngles.x, transform.eulerAngles.y, transform.eulerAngles.z); - } + + /// @@ -199,9 +194,7 @@ public class EquipmentCommon : MonoBehaviour { case "DronePosition"://无人机位置信息传递 Vector3 pos = new Vector3(float.Parse(data[2]), float.Parse(data[3]), float.Parse(data[4])); - Vector3 rot = new Vector3(float.Parse(data[5]), float.Parse(data[6]), float.Parse(data[7])); - transform.position = pos; - transform.eulerAngles = rot; + positions.Enqueue(pos); break; case "Lasing"://激光发射位置传递 LaserFireControlPlatformManger laserFireControlPlatformManger = GetComponent(); diff --git a/Assets/Zion/Scripts/ModelFunction/UAV/UnmannedAerialVehicleManage.cs b/Assets/Zion/Scripts/ModelFunction/UAV/UnmannedAerialVehicleManage.cs index eb9a0f9c..f718558a 100644 --- a/Assets/Zion/Scripts/ModelFunction/UAV/UnmannedAerialVehicleManage.cs +++ b/Assets/Zion/Scripts/ModelFunction/UAV/UnmannedAerialVehicleManage.cs @@ -445,10 +445,10 @@ public class UnmannedAerialVehicleManage : MonoBehaviour { if (airRoute) { - ObjectPlanner objectPlanner = airRoute.GetComponent(); - if (objectPlanner) + DistanceMeasurement distanceMeasurement = airRoute.GetComponent(); + if (distanceMeasurement) { - objectPlanner.isPathCanBePlanned = false; + distanceMeasurement.isPathCanBePlanned = false; } } } @@ -460,11 +460,10 @@ public class UnmannedAerialVehicleManage : MonoBehaviour { if (airRoute) { - ObjectPlanner objectPlanner = airRoute.GetComponent(); - if (objectPlanner) + DistanceMeasurement distanceMeasurement = airRoute.GetComponent(); + if (distanceMeasurement) { - objectPlanner.isPathCanBePlanned = true; - objectPlanner.lineRenderer.SetVertexCount(0); + distanceMeasurement.isPathCanBePlanned = true; positions.Clear(); } } @@ -473,12 +472,12 @@ public class UnmannedAerialVehicleManage : MonoBehaviour GameObject _object = Instantiate(LinePrefab); airRoute = _object; airRoute.transform.position = Vector3.zero; - ObjectPlanner objectPlanner = airRoute.GetComponent(); - if (objectPlanner) + DistanceMeasurement distanceMeasurement = airRoute.GetComponent(); + if (distanceMeasurement) { - objectPlanner.unmannedAerialVehicleManage = this; - objectPlanner.isPathCanBePlanned = true; - objectPlanner.SetSelectedObject(transform.gameObject); + distanceMeasurement.isPathCanBePlanned = true; + distanceMeasurement.markers[0] = transform; + distanceMeasurement.unmannedAerialVehicleManage = this; } } } @@ -492,13 +491,16 @@ public class UnmannedAerialVehicleManage : MonoBehaviour if (isMove && positions.Count > 0) { isMove = false; - StartCoroutine(MoveObjectAlongPath(positions.Dequeue())); // 启动协程,按规划的路线移动物体 + Vector3 _positions = positions.Dequeue(); + var nowData = GetSyncData(_positions); + _ = SyncCreateRoom.SendMessageAsync(string.Format("send2room {0}", nowData)); + StartCoroutine(MoveObjectAlongPath(_positions)); // 启动协程,按规划的路线移动物体 } } - IEnumerator MoveObjectAlongPath(Vector3 positions) // 协程:按路线移动物体 + public IEnumerator MoveObjectAlongPath(Vector3 _positions) // 协程:按路线移动物体 { - Vector3 targetPosition = new Vector3(positions.x, 150, positions.z);// 目标位置为当前顶点坐标 + Vector3 targetPosition = new Vector3(_positions.x, 150, _positions.z);// 目标位置为当前顶点坐标 float _distance = Vector3.Distance(transform.position, targetPosition); float _time = _distance / FireSpeed; transform.LookAt(endPosition); @@ -506,6 +508,25 @@ public class UnmannedAerialVehicleManage : MonoBehaviour yield return new WaitForSeconds(_time); // 等待一帧时间 isMove = true; } + public IEnumerator MoveObjectAlongPath(Vector3 _positions,bool _isMove) // 协程:按路线移动物体 + { + Vector3 targetPosition = new Vector3(_positions.x, 150, _positions.z);// 目标位置为当前顶点坐标 + float _distance = Vector3.Distance(transform.position, targetPosition); + float _time = _distance / FireSpeed; + transform.LookAt(endPosition); + transform.DOMove(targetPosition, _time).SetEase(Ease.Linear); + yield return new WaitForSeconds(_time); // 等待一帧时间 + equipmentCommon.isMove = true; + } + + /// + /// 无人机整体位置传递 + /// + /// + protected string GetSyncData(Vector3 _positions) + { + return string.Format("{0},{1},{2},{3},{4}", "DronePosition", equipmentCommon.deviceID, _positions.x, _positions.y, _positions.z); + } private void OnDestroy() { OnActivationChanged -= OnActivationChangedHandler;