From cddd9c869acb0fde8832045032fa46df6bf7fc07 Mon Sep 17 00:00:00 2001 From: YangHua <1475658476@qq.com> Date: Mon, 20 Nov 2023 18:35:43 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=95=B0=E6=8D=AE=E6=A0=BC?= =?UTF-8?q?=E5=BC=8F=EF=BC=8C=E6=B7=BB=E5=8A=A0=E6=8E=A5=E5=8F=97=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/Zion/Scripts/Adam/GameManager.cs | 39 +++++++++++----- .../UAV/UnmannedAerialVehicleManage.cs | 45 ++++++++++--------- 2 files changed, 51 insertions(+), 33 deletions(-) diff --git a/Assets/Zion/Scripts/Adam/GameManager.cs b/Assets/Zion/Scripts/Adam/GameManager.cs index 5e3bb562..5b658adf 100644 --- a/Assets/Zion/Scripts/Adam/GameManager.cs +++ b/Assets/Zion/Scripts/Adam/GameManager.cs @@ -17,10 +17,10 @@ public class GameManager : MonoBehaviour public TenkokuModule tenkokuModule; public System.Collections.Generic.List modelsInfo = new System.Collections.Generic.List(); public Transform dviceContent; - public GameObject wrjDrag; - public GameObject ldDrag; - public GameObject hpDrag; - public GameObject wxdDrag; + public DragController wrjDrag; + public DragController ldDrag; + public DragController hpDrag; + public DragController wxdDrag; public GameObject Teacher; public GameObject student; // Start is called before the first frame update @@ -55,8 +55,8 @@ public class GameManager : MonoBehaviour { for (int i = 0; i < UIBootstrap.Instance.GetDeviceByName("蜂群无人机").device_count; i++) { - GameObject wrj = Instantiate(wrjDrag, dviceContent); - wrj.GetComponent().deviceID = UIBootstrap.Instance.GetDeviceByName("蜂群无人机").id; + DragController wrj = Instantiate(wrjDrag, dviceContent); + wrj.deviceID = UIBootstrap.Instance.GetDeviceByName("蜂群无人机").id; } } } @@ -67,24 +67,24 @@ public class GameManager : MonoBehaviour { for (int i = 0; i < UIBootstrap.Instance.GetDeviceByName("探测雷达").device_count; i++) { - GameObject ld = Instantiate(ldDrag, dviceContent); - ld.GetComponent().deviceID = UIBootstrap.Instance.GetDeviceByName("探测雷达").id; + DragController ld = Instantiate(ldDrag, dviceContent); + ld.deviceID = UIBootstrap.Instance.GetDeviceByName("探测雷达").id; } } if (UIBootstrap.Instance.GetDeviceByName("激光火控平台").device_count > 0) { for (int i = 0; i < UIBootstrap.Instance.GetDeviceByName("激光火控平台").device_count; i++) { - GameObject hp = Instantiate(hpDrag, dviceContent); - hp.GetComponent().deviceID = UIBootstrap.Instance.GetDeviceByName("激光火控平台").id; + DragController hp = Instantiate(hpDrag, dviceContent); + hp.deviceID = UIBootstrap.Instance.GetDeviceByName("激光火控平台").id; } } if (UIBootstrap.Instance.GetDeviceByName("地面无线电干扰").device_count > 0) { for (int i = 0; i < UIBootstrap.Instance.GetDeviceByName("地面无线电干扰").device_count; i++) { - GameObject wxd = Instantiate(wxdDrag, dviceContent); - wxd.GetComponent().deviceID = UIBootstrap.Instance.GetDeviceByName("地面无线电干扰").id; + DragController wxd = Instantiate(wxdDrag, dviceContent); + wxd.deviceID = UIBootstrap.Instance.GetDeviceByName("地面无线电干扰").id; } } } @@ -112,6 +112,7 @@ public class GameManager : MonoBehaviour yield return new WaitForSeconds(0.5f); Debug.Log(msg); string[] data = msg.Split(','); + switch (data[0]) { case "online": @@ -131,6 +132,20 @@ public class GameManager : MonoBehaviour { UnmannedAerialVehicleManage.unmannedAerialVehicleManages[i].isStartRehearsing = true; } + break; + case "无人机List": + GameObject wrj = Instantiate(wrjDrag.model); + wrj.transform.position = new Vector3(float.Parse(data[1]), float.Parse(data[2]), float.Parse(data[3])); + wrj.transform.eulerAngles = new Vector3(float.Parse(data[4]), float.Parse(data[5]), float.Parse(data[6])); + break; + case "地面无线电干扰": + + break; + case "探测雷达": + + break; + case "激光火控平台": + break; case "Stop": GlobalFlag.isStartRehearsing = false; diff --git a/Assets/Zion/Scripts/ModelFunction/UAV/UnmannedAerialVehicleManage.cs b/Assets/Zion/Scripts/ModelFunction/UAV/UnmannedAerialVehicleManage.cs index 3eba82c5..0e2ef9c2 100644 --- a/Assets/Zion/Scripts/ModelFunction/UAV/UnmannedAerialVehicleManage.cs +++ b/Assets/Zion/Scripts/ModelFunction/UAV/UnmannedAerialVehicleManage.cs @@ -37,7 +37,7 @@ public class UnmannedAerialVehicleManage : MonoBehaviour /// 布尔值变化时触发的事件 /// public event System.Action OnActivationChanged; - + /// /// 间隔时间 /// @@ -58,7 +58,7 @@ public class UnmannedAerialVehicleManage : MonoBehaviour /// 设备通用脚本 /// private Weaponitemone weaponitemones; - + /// /// 无人机预制体 /// @@ -83,14 +83,14 @@ public class UnmannedAerialVehicleManage : MonoBehaviour /// /// 已有路径 /// - public Queue positions=new Queue(); - public Vector3 endPosition=new Vector3(); + public Queue positions = new Queue(); + public Vector3 endPosition = new Vector3(); /// /// 飞行速度 /// public float FireSpeed = 20.0f; - + #region 无人机数据 /// @@ -137,7 +137,7 @@ public class UnmannedAerialVehicleManage : MonoBehaviour Formation(1);//默认阵型 // 订阅布尔值变化事件 OnActivationChanged += OnActivationChangedHandler; - + } // Update is called once per frame @@ -155,7 +155,7 @@ public class UnmannedAerialVehicleManage : MonoBehaviour } } } - if (isStartRehearsing && isStartRehearsing&&pattern == Pattern.攻击) + if (isStartRehearsing && isStartRehearsing && pattern == Pattern.攻击) { if (airRoute) { @@ -169,7 +169,8 @@ public class UnmannedAerialVehicleManage : MonoBehaviour /// public void modeSwitch(int patternCut) { - switch (patternCut) { + switch (patternCut) + { case 0://待机 pattern = Pattern.待机; break; @@ -178,7 +179,7 @@ public class UnmannedAerialVehicleManage : MonoBehaviour break; case 2: pattern = Pattern.攻击; - + break; default: break; @@ -195,16 +196,16 @@ public class UnmannedAerialVehicleManage : MonoBehaviour { if (newValue) { - + } else { - + } } - + #endregion #region 数据写入 @@ -216,13 +217,14 @@ public class UnmannedAerialVehicleManage : MonoBehaviour { if (equipmentCommon) { - string msg = $"send2room {equipmentCommon.equipmentType}+{transform.position.ToString().Replace(" ","")}+{transform.eulerAngles.ToString().Replace(" ", "")}"; + string msg = $"send2room {equipmentCommon.equipmentType}+{transform.position.ToString().Replace(" ", "")}+{transform.eulerAngles.ToString().Replace(" ", "").Replace("(", "").Replace(")", "")}"; Debug.Log(msg); _ = SyncCreateRoom.SendMessageAsync(msg); } - for (int i=0;i< weaponitemone.Count; i++) + for (int i = 0; i < weaponitemone.Count; i++) { - switch (weaponitemone[i].para_name) { + switch (weaponitemone[i].para_name) + { case "续航时间:": batteryLife = weaponitemone[i].para_value; break; @@ -251,7 +253,7 @@ public class UnmannedAerialVehicleManage : MonoBehaviour default: break; } - if(i== (weaponitemone.Count - 1)) + if (i == (weaponitemone.Count - 1)) { StartCoroutine(WeaponitemoneDataAddition()); } @@ -265,7 +267,7 @@ public class UnmannedAerialVehicleManage : MonoBehaviour IEnumerator WeaponitemoneDataAddition() { yield return new WaitForSeconds(0.1f); - for(int i=0;i< unmannedAerialVehicles.Count; i++) + for (int i = 0; i < unmannedAerialVehicles.Count; i++) { unmannedAerialVehicles[i].batteryLife = batteryLife; unmannedAerialVehicles[i].classificationWindResistance = classificationWindResistance; @@ -287,7 +289,8 @@ public class UnmannedAerialVehicleManage : MonoBehaviour /// public void Formation(int number) { - switch (number) { + switch (number) + { case 1: GenerateFormation(); break; @@ -369,8 +372,8 @@ public class UnmannedAerialVehicleManage : MonoBehaviour { Debug.Log("cols..:" + cols); Debug.Log("rows..:" + rows); - box.center = new Vector3(cols-1, 0, -(rows-1)); - box.size = new Vector3(cols*2, 1, 2 * rows); + box.center = new Vector3(cols - 1, 0, -(rows - 1)); + box.size = new Vector3(cols * 2, 1, 2 * rows); } } @@ -431,7 +434,7 @@ public class UnmannedAerialVehicleManage : MonoBehaviour /// public void StartMoveObjectAlongPath() { - if (isMove&&positions.Count > 0) + if (isMove && positions.Count > 0) { isMove = false; StartCoroutine(MoveObjectAlongPath(positions.Dequeue())); // 启动协程,按规划的路线移动物体