fix(AutoLANClientController): Use FindAnyObjectByType

This commit is contained in:
MrGadget 2024-07-20 10:30:20 -04:00
parent e887d11b1e
commit c82ae00ef7
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);
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);
}

View File

@ -39,7 +39,14 @@ private void Start()
inputFieldAddress.onValueChanged.AddListener(delegate { OnValueChangedAddress(); });
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
if (alwaysAutoStart)
@ -194,5 +201,4 @@ public void OnValueChangedAddress()
NetworkManager.singleton.networkAddress = inputFieldAddress.text;
}
}
}

View File

@ -44,7 +44,14 @@ public override void Start()
{
base.Start();
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>
@ -64,7 +71,7 @@ public override void OnDestroy()
//UnityEngine.Debug.Log("OnDestroy");
}
#endregion
#endregion
#region Start & Stop