fix(AutoLANClientController): Use FindAnyObjectByType

This commit is contained in:
MrGadget 2024-07-20 10:30:20 -04:00
parent ef4760d4e1
commit 96ddfa040d
3 changed files with 28 additions and 8 deletions

View File

@ -89,7 +89,14 @@ protected override void ProcessResponse(ServerResponse response, IPEndPoint endp
//OnServerFound.Invoke(response); //OnServerFound.Invoke(response);
if (canvasHUD == null) if (canvasHUD == null)
{ canvasHUD = GameObject.FindObjectOfType<CanvasHUD>(); } {
#if UNITY_2022_2_OR_NEWER
canvasHUD = GameObject.FindAnyObjectByType<CanvasHUD>();
#else
// Deprecated in Unity 2023.1
canvasHUD = GameObject.FindObjectOfType<CanvasHUD>();
#endif
}
canvasHUD.OnDiscoveredServer(response); canvasHUD.OnDiscoveredServer(response);
} }

View File

@ -39,7 +39,14 @@ private void Start()
inputFieldAddress.onValueChanged.AddListener(delegate { OnValueChangedAddress(); }); inputFieldAddress.onValueChanged.AddListener(delegate { OnValueChangedAddress(); });
if (networkDiscovery == null) if (networkDiscovery == null)
{ networkDiscovery = GameObject.FindObjectOfType<AutoLANNetworkDiscovery>(); } {
#if UNITY_2022_2_OR_NEWER
networkDiscovery = GameObject.FindAnyObjectByType<AutoLANNetworkDiscovery>();
#else
// Deprecated in Unity 2023.1
networkDiscovery = GameObject.FindObjectOfType<AutoLANNetworkDiscovery>();
#endif
}
// skips waiting for users to press ui button // skips waiting for users to press ui button
if (alwaysAutoStart) if (alwaysAutoStart)
@ -194,5 +201,4 @@ public void OnValueChangedAddress()
NetworkManager.singleton.networkAddress = inputFieldAddress.text; NetworkManager.singleton.networkAddress = inputFieldAddress.text;
} }
} }
} }

View File

@ -44,7 +44,14 @@ public override void Start()
{ {
base.Start(); base.Start();
if (canvasHUD == null) if (canvasHUD == null)
{ canvasHUD = GameObject.FindObjectOfType<CanvasHUD>(); } {
#if UNITY_2022_2_OR_NEWER
canvasHUD = GameObject.FindAnyObjectByType<CanvasHUD>();
#else
// Deprecated in Unity 2023.1
canvasHUD = GameObject.FindObjectOfType<CanvasHUD>();
#endif
}
} }
/// <summary> /// <summary>
@ -64,7 +71,7 @@ public override void OnDestroy()
//UnityEngine.Debug.Log("OnDestroy"); //UnityEngine.Debug.Log("OnDestroy");
} }
#endregion #endregion
#region Start & Stop #region Start & Stop