From 55a7e3e1090485524ce634a74aaf2282cc7e1ca3 Mon Sep 17 00:00:00 2001 From: YangHua <1475658476@qq.com> Date: Thu, 29 Feb 2024 22:23:45 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=89=93=E7=BB=84=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/Temp/Scripts/Mastermanagement.cs | 2 + .../Adam/Components/PostureController.cs | 17 ++- Assets/Zion/Scripts/Adam/FormationManager.cs | 103 ++++++++++++++---- .../Scripts/ModelFunction/EquipmentCommon.cs | 4 +- .../ModelFunction/SingleMachineTest.cs | 4 +- .../TerrestrialRadioInterferenceManger.cs | 6 +- .../UAV/UnmannedAerialVehicleManage.cs | 3 +- 7 files changed, 112 insertions(+), 27 deletions(-) diff --git a/Assets/Temp/Scripts/Mastermanagement.cs b/Assets/Temp/Scripts/Mastermanagement.cs index 33fb85ea..781fdaa7 100644 --- a/Assets/Temp/Scripts/Mastermanagement.cs +++ b/Assets/Temp/Scripts/Mastermanagement.cs @@ -89,6 +89,8 @@ public class Mastermanagement : MonoBehaviour //} weapongames.Remove(obj); DeviceManager.Instance.RemoveDevice(obj); + if (obj.GetComponent()) + FormationManager.Instance.RemoveAppointWRJ(obj.GetComponent()); Destroy(obj); } } diff --git a/Assets/Zion/Scripts/Adam/Components/PostureController.cs b/Assets/Zion/Scripts/Adam/Components/PostureController.cs index a3cdf58a..11dc05f6 100644 --- a/Assets/Zion/Scripts/Adam/Components/PostureController.cs +++ b/Assets/Zion/Scripts/Adam/Components/PostureController.cs @@ -142,7 +142,7 @@ public class PostureController : MonoBehaviour for (int i = 0; i < blueObjs.Count; i++) { CreatDeviceItem(blueContanier, blueObjs[i].name, blueObjs[i].deviceID, 1); - blueObjs[i].onDeviceDelete += RemoveItem; + blueObjs[i].onDeviceDelete += RemoveBlueItem; } } @@ -152,14 +152,29 @@ public class PostureController : MonoBehaviour public void RemoveItem(string id) { + UnmannedAerialVehicleManage temp = null; for (int i = 0; i < redObjs.Count; i++) { if (redObjs[i].deviceID == id) { + temp = redObjs[i].GetComponent(); redObjs.Remove(redObjs[i]); return; } } + FormationManager.Instance.RemoveAppointWRJ(temp); + } + + public void RemoveBlueItem(string id) + { + for (int i = 0; i < blueObjs.Count; i++) + { + if (blueObjs[i].deviceID == id) + { + blueObjs.Remove(blueObjs[i]); + return; + } + } } private void CreatDeviceItem(Transform contanier, string objName, string id, int redOrBlue) diff --git a/Assets/Zion/Scripts/Adam/FormationManager.cs b/Assets/Zion/Scripts/Adam/FormationManager.cs index b9b15181..543e8313 100644 --- a/Assets/Zion/Scripts/Adam/FormationManager.cs +++ b/Assets/Zion/Scripts/Adam/FormationManager.cs @@ -1,4 +1,5 @@ -using System; +using AdamSync; +using System; using System.Collections; using System.Collections.Generic; using System.Linq; @@ -25,6 +26,7 @@ public class FormationManager : MonoSingleton public List formationInfos = new List(); public FormationInfo formationInfo; public List allUavms = new List(); + public List formationIDs = new List(); // Start is called before the first frame update void Start() { @@ -58,12 +60,9 @@ public class FormationManager : MonoSingleton UnmannedAerialVehicleManage uavmTemp = hitInfo.collider.gameObject.GetComponent(); if (uavmTemp != null && !uavmTemp.isGroup) { - if (!formationInfo.uavms.Contains(uavmTemp)) + if (!formationIDs.Contains(uavmTemp.equipmentCommon.deviceID)) { - uavmTemp.isGroup = true; - uavmTemp.groupId = formationInfo.groupIndex; - uavmTemp.SetGroupTipsAndDatabaseInfo(formationInfo.groupIndex); - formationInfo.uavms.Add(uavmTemp); + formationIDs.Add(uavmTemp.equipmentCommon.deviceID); } } Debug.Log("拾取"); @@ -138,6 +137,23 @@ public class FormationManager : MonoSingleton uavms[j].modeSwitch(patternCut); } } + /// + /// 移除指定无人机 + /// + /// + public void RemoveAppointWRJ(UnmannedAerialVehicleManage uavm) + { + List uavms = GroupUAVM(uavm.groupId); + if (uavms.Contains(uavm)) + uavms.Remove(uavm); + if (allUavms.Contains(uavm)) + allUavms.Remove(uavm); + for (int j = 0; j < formationInfos.Count; j++) + { + if (formationInfos[j].uavms.Count == 0) + formationInfos.Remove(formationInfos[j]); + } + } private List GroupUAVM(int uavmGroupID) { @@ -155,26 +171,70 @@ public class FormationManager : MonoSingleton + public void OnStartFormation() { isStartFormation = true; - formationInfo = new FormationInfo(); - formationInfo.groupIndex = formationInfos.Count; CheckBtns(1); } public void OnSubmit() { isStartFormation = false; - if (formationInfo.uavms.Count > 0) + + string infoTemp = ""; + for (int i = 0; i < formationInfo.uavms.Count; i++) { - if (!formationInfos.Contains(formationInfo)) - formationInfos.Add(formationInfo); + infoTemp += formationInfo.uavms[i].equipmentCommon.deviceID + ","; } - formationInfo = null; + SendGroupToOther(formationInfos.Count.ToString(), infoTemp); + Debug.Log($"{infoTemp}"); CheckBtns(0); } + + private char[] separators = { ',' }; // 设置分隔符为逗号 + public void OnReciveMsg(string reciveInfo) + { + List uavms = GetAllWRJ(); + + var result = reciveInfo.Split(separators) // 对字符串进行切割操作 + .Where(s => !String.IsNullOrWhiteSpace(s) && s != "") // 移除空白或者只包含空格的元素 + .ToList(); + if (result.Count > 0) + { + if (result[0] == "group") + { + formationInfo = new FormationInfo(); + formationInfo.groupIndex = int.Parse(result[1]); + for (int i = 2; i < result.Count; i++) + { + for (int j = 0; j < uavms.Count; j++) + { + if (uavms[j].equipmentCommon.deviceID == result[i]) + { + uavms[j].groupId = int.Parse(result[1]); + uavms[j].isGroup = true; + uavms[j].SetGroupTipsAndDatabaseInfo(int.Parse(result[1])); + formationInfo.uavms.Add(uavms[j]); + } + } + } + if (!formationInfos.Contains(formationInfo)) + formationInfos.Add(formationInfo); + } + } + } + + /// + /// 打组发送给别人 + /// + private void SendGroupToOther(string groupIndex, string info) + { + string msg = $"send2room group,{groupIndex},{info}"; + _ = SyncCreateRoom.SendMessageAsync(msg); + } + public void OnCancel() { formationInfo = null; @@ -183,25 +243,30 @@ public class FormationManager : MonoSingleton public int wrjCount = 0; - /// - /// 动态添加已经生成得数据 - /// - public void WhenSpawn() + public List GetAllWRJ() { List equipList = DeviceManager.Instance.devices; - + List allUavmsTemp = new List(); for (int i = 0; i < equipList.Count; i++) { int index = i; if (equipList[index] != null && equipList[index].gameObject.layer == 11 && equipList[index].GetComponent()) { - if (!allUavms.Contains(equipList[index].GetComponent())) + if (!allUavmsTemp.Contains(equipList[index].GetComponent())) { - allUavms.Add(equipList[index].GetComponent()); + allUavmsTemp.Add(equipList[index].GetComponent()); } } } + return allUavmsTemp; + } + /// + /// 动态添加已经生成得数据 + /// + public void WhenSpawn() + { + allUavms = GetAllWRJ(); foreach (var uam in allUavms) { diff --git a/Assets/Zion/Scripts/ModelFunction/EquipmentCommon.cs b/Assets/Zion/Scripts/ModelFunction/EquipmentCommon.cs index a121faf2..697c9cc4 100644 --- a/Assets/Zion/Scripts/ModelFunction/EquipmentCommon.cs +++ b/Assets/Zion/Scripts/ModelFunction/EquipmentCommon.cs @@ -178,14 +178,14 @@ public class EquipmentCommon : MonoBehaviour break; case "地面无线电干扰": TerrestrialRadioInterferenceManger terrestrialRadioInterferenceManger = GetComponent(); - terrestrialRadioInterferenceManger.FillInTheData(weaponitemone); + terrestrialRadioInterferenceManger.FillInTheData(weaponitemone,deviceID); terrestrialRadioInterferenceManger.isStartRehearsing = isStartRehearsing; break; case "蜂群无人机": UnmannedAerialVehicleManage unmannedAerialVehicleManage = GetComponent(); unmannedAerialVehicleManage.MatrixFormation(30, 1); - unmannedAerialVehicleManage.FillInTheData(weaponitemone); + unmannedAerialVehicleManage.FillInTheData(weaponitemone, deviceID); unmannedAerialVehicleManage.isStartRehearsing = isStartRehearsing; DroneViewDisplay.Instance.CreateUI(unmannedAerialVehicleManage, false); diff --git a/Assets/Zion/Scripts/ModelFunction/SingleMachineTest.cs b/Assets/Zion/Scripts/ModelFunction/SingleMachineTest.cs index 7ffc2f0a..d5f61601 100644 --- a/Assets/Zion/Scripts/ModelFunction/SingleMachineTest.cs +++ b/Assets/Zion/Scripts/ModelFunction/SingleMachineTest.cs @@ -45,10 +45,10 @@ public class SingleMachineTest : MonoBehaviour { root = Newtonsoft.Json.JsonConvert.DeserializeObject(msg1); - unmannedAerialVehicleManages.ForEach(x => x.FillInTheData(root.data[2].list_para)); + //unmannedAerialVehicleManages.ForEach(x => x.FillInTheData(root.data[2].list_para)); radarMangers.ForEach(x => x.FillInTheData(root.data[0].list_para)); laserFireControlPlatformMangers.ForEach(x => x.FillInTheData(root.data[3].list_para)); - terrestrialRadioInterferenceMangers.ForEach(x => x.FillInTheData(root.data[1].list_para)); + //terrestrialRadioInterferenceMangers.ForEach(x => x.FillInTheData(root.data[1].list_para)); // 开始协程 //StartTimer(); } diff --git a/Assets/Zion/Scripts/ModelFunction/TerrestrialRadioInterference/TerrestrialRadioInterferenceManger.cs b/Assets/Zion/Scripts/ModelFunction/TerrestrialRadioInterference/TerrestrialRadioInterferenceManger.cs index ab174351..c6b89163 100644 --- a/Assets/Zion/Scripts/ModelFunction/TerrestrialRadioInterference/TerrestrialRadioInterferenceManger.cs +++ b/Assets/Zion/Scripts/ModelFunction/TerrestrialRadioInterference/TerrestrialRadioInterferenceManger.cs @@ -27,6 +27,8 @@ public class TerrestrialRadioInterferenceManger : MonoBehaviour public EquipmentCommon equipmentCommon; + public string deviceID; + public static List terrestrialRadioInterferenceMangers = new List(); #region 地面无线电干扰数据 /// @@ -312,9 +314,9 @@ public class TerrestrialRadioInterferenceManger : MonoBehaviour /// 数据写入 /// /// - public void FillInTheData(List weaponitemone) + public void FillInTheData(List weaponitemone, string _deviceId) { - + deviceID = _deviceId; for (int i = 0; i < weaponitemone.Count; i++) { switch (weaponitemone[i].para_name) diff --git a/Assets/Zion/Scripts/ModelFunction/UAV/UnmannedAerialVehicleManage.cs b/Assets/Zion/Scripts/ModelFunction/UAV/UnmannedAerialVehicleManage.cs index f1f6e971..426ca37b 100644 --- a/Assets/Zion/Scripts/ModelFunction/UAV/UnmannedAerialVehicleManage.cs +++ b/Assets/Zion/Scripts/ModelFunction/UAV/UnmannedAerialVehicleManage.cs @@ -59,6 +59,7 @@ public class UnmannedAerialVehicleManage : MonoBehaviour public EquipmentCommon equipmentCommon; + /// /// 打组ID /// @@ -601,7 +602,7 @@ public class UnmannedAerialVehicleManage : MonoBehaviour /// 数据写入 /// /// - public void FillInTheData(List weaponitemone) + public void FillInTheData(List weaponitemone, string _deviceId) { SenceInfo currentSceneInfo = new SenceInfo(); currentSceneInfo = UIBootstrap.Instance.currentSceneInfo.data;