From ec803964b40b341f325d012fafef386dab270537 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B4=A6=E5=8F=B7=E5=90=8D?= <3077614386@qq.com> Date: Tue, 21 Nov 2023 19:24:19 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=8D=E7=BD=AE=E5=AE=9E=E6=97=B6=E6=8E=A8?= =?UTF-8?q?=E9=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/Zion/Scenes/单机演练.unity | 27 +++++- Assets/Zion/Scripts/Adam/GameManager.cs | 2 +- .../Adam/Utility/Sync/SyncPlayerTransform.cs | 16 ++++ Assets/Zion/Scripts/Adam/WRJManager.cs | 2 +- .../Scripts/ModelFunction/EquipmentCommon.cs | 94 +++++++++++++++---- .../UAV/UnmannedAerialVehicleManage.cs | 8 +- 6 files changed, 121 insertions(+), 28 deletions(-) diff --git a/Assets/Zion/Scenes/单机演练.unity b/Assets/Zion/Scenes/单机演练.unity index 58449823..5c1a0232 100644 --- a/Assets/Zion/Scenes/单机演练.unity +++ b/Assets/Zion/Scenes/单机演练.unity @@ -406,7 +406,7 @@ MonoBehaviour: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 144713087} - m_Enabled: 1 + m_Enabled: 0 m_EditorHideFlags: 0 m_Script: {fileID: 11500000, guid: 014683e72ff868e4c9c0d3eec7d87a26, type: 3} m_Name: @@ -653,6 +653,11 @@ PrefabInstance: propertyPath: m_Name value: "\u5730\u9762\u65E0\u7EBF\u7535\u5E72\u6270" objectReference: {fileID: 0} + - target: {fileID: 625513913607457920, guid: 121324ce722bdb944a7cc1c7c3a5077f, + type: 3} + propertyPath: m_IsActive + value: 0 + objectReference: {fileID: 0} m_RemovedComponents: [] m_SourcePrefab: {fileID: 100100000, guid: 121324ce722bdb944a7cc1c7c3a5077f, type: 3} --- !u!114 &480997535 stripped @@ -908,6 +913,11 @@ PrefabInstance: propertyPath: m_Name value: "\u63A2\u6D4B\u96F7\u8FBE" objectReference: {fileID: 0} + - target: {fileID: 3977472425108262603, guid: 2b2524df6b4053a4aa08b1f5fe4d62f5, + type: 3} + propertyPath: m_IsActive + value: 0 + objectReference: {fileID: 0} m_RemovedComponents: [] m_SourcePrefab: {fileID: 100100000, guid: 2b2524df6b4053a4aa08b1f5fe4d62f5, type: 3} --- !u!1 &954663048 @@ -1302,6 +1312,11 @@ PrefabInstance: propertyPath: m_Name value: "\u65E0\u4EBA\u673AList" objectReference: {fileID: 0} + - target: {fileID: 6865737300552731157, guid: 8425122cf585dcc47bbf3eff95ecf176, + type: 3} + propertyPath: m_IsActive + value: 1 + objectReference: {fileID: 0} - target: {fileID: 6865737300552731159, guid: 8425122cf585dcc47bbf3eff95ecf176, type: 3} propertyPath: m_LocalPosition.x @@ -1848,6 +1863,11 @@ PrefabInstance: propertyPath: m_Name value: "\u6FC0\u5149\u706B\u63A7\u5E73\u53F0" objectReference: {fileID: 0} + - target: {fileID: 7615181139496386322, guid: 7abae14e48a106d4c8120d0eba515162, + type: 3} + propertyPath: m_IsActive + value: 0 + objectReference: {fileID: 0} - target: {fileID: 7615181139496386328, guid: 7abae14e48a106d4c8120d0eba515162, type: 3} propertyPath: m_LocalPosition.x @@ -1922,6 +1942,11 @@ PrefabInstance: propertyPath: m_Name value: "\u6FC0\u5149\u706B\u63A7\u5E73\u53F0" objectReference: {fileID: 0} + - target: {fileID: 7615181139496386322, guid: 7abae14e48a106d4c8120d0eba515162, + type: 3} + propertyPath: m_IsActive + value: 0 + objectReference: {fileID: 0} - target: {fileID: 7615181139496386328, guid: 7abae14e48a106d4c8120d0eba515162, type: 3} propertyPath: m_LocalPosition.x diff --git a/Assets/Zion/Scripts/Adam/GameManager.cs b/Assets/Zion/Scripts/Adam/GameManager.cs index fc2bc4d9..95d26ce9 100644 --- a/Assets/Zion/Scripts/Adam/GameManager.cs +++ b/Assets/Zion/Scripts/Adam/GameManager.cs @@ -104,7 +104,7 @@ public class GameManager : MonoBehaviour private void Update() { - if (Input.GetMouseButtonDown(1)) + if (UIBootstrap.Instance.GetRoleByIDPracticeId(GlobalFlag.practiceSeatId) == "0"&&Input.GetMouseButtonDown(1)) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hitInfo; diff --git a/Assets/Zion/Scripts/Adam/Utility/Sync/SyncPlayerTransform.cs b/Assets/Zion/Scripts/Adam/Utility/Sync/SyncPlayerTransform.cs index 1f8746f0..50a871db 100644 --- a/Assets/Zion/Scripts/Adam/Utility/Sync/SyncPlayerTransform.cs +++ b/Assets/Zion/Scripts/Adam/Utility/Sync/SyncPlayerTransform.cs @@ -22,6 +22,22 @@ namespace AdamSync } } + private void Update() + { + if (Input.GetMouseButtonDown(1)) + { + Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); + RaycastHit hitInfo; + if (Physics.Raycast(ray, out hitInfo, 1000)) + { + if (hitInfo.collider.tag == "WRJ") + { + UnmannedAerialVehicleUI.Instance.unmannedAerialVehicleManage = hitInfo.collider.GetComponent(); + } + } + } + } + private IEnumerator SendMsg() { while (true) diff --git a/Assets/Zion/Scripts/Adam/WRJManager.cs b/Assets/Zion/Scripts/Adam/WRJManager.cs index 4ee3be15..b7e218f8 100644 --- a/Assets/Zion/Scripts/Adam/WRJManager.cs +++ b/Assets/Zion/Scripts/Adam/WRJManager.cs @@ -21,7 +21,7 @@ namespace Assets.Zion.Scripts.Adam private void Update() { - if (Input.GetMouseButtonDown(1)) + if (UIBootstrap.Instance.GetRoleByIDPracticeId(GlobalFlag.practiceSeatId) == "0" && Input.GetMouseButtonDown(1)) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hitInfo; diff --git a/Assets/Zion/Scripts/ModelFunction/EquipmentCommon.cs b/Assets/Zion/Scripts/ModelFunction/EquipmentCommon.cs index f95c4e27..c6cf3be2 100644 --- a/Assets/Zion/Scripts/ModelFunction/EquipmentCommon.cs +++ b/Assets/Zion/Scripts/ModelFunction/EquipmentCommon.cs @@ -21,13 +21,35 @@ public class EquipmentCommon : MonoBehaviour /// public static List equipmentCommons = new List(); public string equipmentType = ""; - private bool _isStartRehearsing = false; + + /// + /// 设备唯一ID + /// public string deviceID; - public bool isPlayer = false; + /// + /// 是否是本人创建的设备 + /// + public bool isPlayer + { + get { return _isPlayer; } + set + { + if (_isPlayer != value) + { + _isPlayer = value; + OnActivationIsPlayer?.Invoke(_isPlayer); + } + } + } + public event System.Action OnActivationIsPlayer; + private bool _isPlayer = false; + // 布尔值变化时触发的事件 public event System.Action OnActivationChanged; + + private bool _isStartRehearsing = false; // 属性绑定布尔值,并在值变化时触发事件 public bool isStartRehearsing { @@ -48,20 +70,23 @@ public class EquipmentCommon : MonoBehaviour equipmentCommons.Add(this); // 订阅布尔值变化事件 OnActivationChanged += OnActivationChangedHandler; + // + OnActivationIsPlayer += OnActivationChangedIsPlayer; + } + void OnActivationChangedIsPlayer(bool newValue) + { + if(newValue&& equipmentType== "无人机List"&& isOnlyOne) + { + isOnlyOne = false; + StartCoroutine(SendMsg()); + } } - /// - /// + /// 导条 暂停开始控制 /// /// void OnActivationChangedHandler(bool newValue) { - if (equipmentCommon) - { - //string msg = $"send2room {equipmentCommon.equipmentType}+{transform.position.ToString().Replace(" ", "").Replace("(", "").Replace(")", "")}+{transform.eulerAngles.ToString().Replace(" ", "").Replace("(", "").Replace(")", "")}"; - //Debug.Log(msg); - //_ = SyncCreateRoom.SendMessageAsync(msg); - } switch (equipmentType) { case "激光火控平台": @@ -88,21 +113,16 @@ public class EquipmentCommon : MonoBehaviour public char replaceInfo; public Dictionary replaceInfoDic = new Dictionary(); - //public void ResultsInfo(bool b, string s) - //{ - // Debug.Log(s); - // ReturnDeviceID result = JsonConvert.DeserializeObject(s); - // Debug.Log(result.data); - //} + /// - /// + /// 物体生成时接受数据 /// /// public void FillInTheData(List weaponitemone) { - if (!isPlayer) return; - if (equipmentCommon) + //向其他的单位发送创建信息 + if (isPlayer&& equipmentCommon)//但是是由我自主创建的时候发送一次 且只发送一次 { string paraListJson = JsonConvert.SerializeObject(weaponitemone); replaceInfoDic.Add("PracticeId", GlobalFlag.roomID); @@ -117,7 +137,8 @@ public class EquipmentCommon : MonoBehaviour _ = SyncCreateRoom.SendMessageAsync(msg); })); } - + + //填入数据 switch (equipmentType) { case "激光火控平台": @@ -142,6 +163,39 @@ public class EquipmentCommon : MonoBehaviour } } + + + //位置实时传送 + private string latestData = ""; + private bool isOnlyOne = true; + public IEnumerator SendMsg() + { + while (true) + { + yield return new WaitForSeconds(0.01f); + + var nowData = GetSyncData(); + if (!nowData.Equals(latestData)) + { + latestData = nowData; + Debug.Log(latestData); + _ = SyncCreateRoom.SendMessageAsync(string.Format("WRJ {0}", nowData)); + } + } + } + protected string GetSyncData() + { + return string.Format("{0},{1},{2},{3},{4},{5},{6}", equipmentCommon.deviceID, transform.position.x, transform.position.y, transform.position.z, transform.eulerAngles.x, transform.eulerAngles.y, transform.eulerAngles.z); + } + + + private void Update() + { + if (Input.GetKeyDown(KeyCode.T)) + { + isPlayer = !isPlayer; + } + } } public enum SelectedSide diff --git a/Assets/Zion/Scripts/ModelFunction/UAV/UnmannedAerialVehicleManage.cs b/Assets/Zion/Scripts/ModelFunction/UAV/UnmannedAerialVehicleManage.cs index 2b7ce47a..cd6a0f86 100644 --- a/Assets/Zion/Scripts/ModelFunction/UAV/UnmannedAerialVehicleManage.cs +++ b/Assets/Zion/Scripts/ModelFunction/UAV/UnmannedAerialVehicleManage.cs @@ -143,7 +143,7 @@ public class UnmannedAerialVehicleManage : MonoBehaviour // Update is called once per frame void Update() { - if (isStartRehearsing && isStartRehearsing && pattern == Pattern.攻击) + if (isStartRehearsing && equipmentCommon.isPlayer && pattern == Pattern.攻击) { if (airRoute) { @@ -440,10 +440,8 @@ public class UnmannedAerialVehicleManage : MonoBehaviour isMove = true; } - private void OnMouseEnter() - { - UnmannedAerialVehicleUI.Instance.unmannedAerialVehicleManage = transform.GetComponent(); - } + + } public enum Pattern {