From 96ddfa040ddac1a58ee863621e282b2df8ff004c Mon Sep 17 00:00:00 2001 From: MrGadget <9826063+MrGadget1024@users.noreply.github.com> Date: Sat, 20 Jul 2024 10:30:20 -0400 Subject: [PATCH] fix(AutoLANClientController): Use FindAnyObjectByType --- .../Scripts/AutoLANNetworkDiscovery.cs | 11 +++++++++-- .../AutoLANClientController/Scripts/CanvasHUD.cs | 12 +++++++++--- .../Scripts/CustomNetworkManager.cs | 13 ++++++++++--- 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/Assets/Mirror/Examples/AutoLANClientController/Scripts/AutoLANNetworkDiscovery.cs b/Assets/Mirror/Examples/AutoLANClientController/Scripts/AutoLANNetworkDiscovery.cs index d84b5a488..89b7fefc6 100644 --- a/Assets/Mirror/Examples/AutoLANClientController/Scripts/AutoLANNetworkDiscovery.cs +++ b/Assets/Mirror/Examples/AutoLANClientController/Scripts/AutoLANNetworkDiscovery.cs @@ -89,10 +89,17 @@ protected override void ProcessResponse(ServerResponse response, IPEndPoint endp //OnServerFound.Invoke(response); if (canvasHUD == null) - { canvasHUD = GameObject.FindObjectOfType(); } + { +#if UNITY_2022_2_OR_NEWER + canvasHUD = GameObject.FindAnyObjectByType(); +#else + // Deprecated in Unity 2023.1 + canvasHUD = GameObject.FindObjectOfType(); +#endif + } canvasHUD.OnDiscoveredServer(response); } #endregion } -} \ No newline at end of file +} diff --git a/Assets/Mirror/Examples/AutoLANClientController/Scripts/CanvasHUD.cs b/Assets/Mirror/Examples/AutoLANClientController/Scripts/CanvasHUD.cs index f80f8d835..0cfc69b39 100644 --- a/Assets/Mirror/Examples/AutoLANClientController/Scripts/CanvasHUD.cs +++ b/Assets/Mirror/Examples/AutoLANClientController/Scripts/CanvasHUD.cs @@ -39,7 +39,14 @@ private void Start() inputFieldAddress.onValueChanged.AddListener(delegate { OnValueChangedAddress(); }); if (networkDiscovery == null) - { networkDiscovery = GameObject.FindObjectOfType(); } + { +#if UNITY_2022_2_OR_NEWER + networkDiscovery = GameObject.FindAnyObjectByType(); +#else + // Deprecated in Unity 2023.1 + networkDiscovery = GameObject.FindObjectOfType(); +#endif + } // skips waiting for users to press ui button if (alwaysAutoStart) @@ -194,5 +201,4 @@ public void OnValueChangedAddress() NetworkManager.singleton.networkAddress = inputFieldAddress.text; } } - -} \ No newline at end of file +} diff --git a/Assets/Mirror/Examples/AutoLANClientController/Scripts/CustomNetworkManager.cs b/Assets/Mirror/Examples/AutoLANClientController/Scripts/CustomNetworkManager.cs index 32590d46c..392e282b3 100644 --- a/Assets/Mirror/Examples/AutoLANClientController/Scripts/CustomNetworkManager.cs +++ b/Assets/Mirror/Examples/AutoLANClientController/Scripts/CustomNetworkManager.cs @@ -44,7 +44,14 @@ public override void Start() { base.Start(); if (canvasHUD == null) - { canvasHUD = GameObject.FindObjectOfType(); } + { +#if UNITY_2022_2_OR_NEWER + canvasHUD = GameObject.FindAnyObjectByType(); +#else + // Deprecated in Unity 2023.1 + canvasHUD = GameObject.FindObjectOfType(); +#endif + } } /// @@ -64,7 +71,7 @@ public override void OnDestroy() //UnityEngine.Debug.Log("OnDestroy"); } - #endregion +#endregion #region Start & Stop @@ -326,4 +333,4 @@ public override void OnStopClient() #endregion } -} \ No newline at end of file +}