fix: Safer version for FindAnyObjectByType (#3765)

Unity docs are a mess on when FindAnyObjectByType was implemented:
- 2021.3 says it is
- 2022.1 says it's not
- 2022.2 says it is
This commit is contained in:
MrGadget 2024-02-16 11:22:59 -05:00 committed by GitHub
parent 2ed1d7329c
commit 490dea82ab
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 8 additions and 8 deletions

View File

@ -30,7 +30,7 @@ public class PlayerPredicted : NetworkBehaviour
void Awake()
{
// find the white ball once
#if UNITY_2021_3_OR_NEWER
#if UNITY_2022_2_OR_NEWER
whiteBall = FindAnyObjectByType<WhiteBallPredicted>();
#else
// Deprecated in Unity 2023.1

View File

@ -83,7 +83,7 @@ public override void OnStartAuthority()
characterController.enabled = true;
this.enabled = true;
#if UNITY_2021_3_OR_NEWER
#if UNITY_2022_2_OR_NEWER
sceneReferencer = GameObject.FindAnyObjectByType<SceneReferencer>();
#else
// Deprecated in Unity 2023.1

View File

@ -10,7 +10,7 @@ public class PlayerEmpty : NetworkBehaviour
public override void OnStartAuthority()
{
// enable UI located in the scene, after empty player spawns in.
#if UNITY_2021_3_OR_NEWER
#if UNITY_2022_2_OR_NEWER
sceneReferencer = GameObject.FindAnyObjectByType<SceneReferencer>();
#else
// Deprecated in Unity 2023.1

View File

@ -26,7 +26,7 @@ public override void OnStartAuthority()
if (isOwned)
{
#if UNITY_2021_3_OR_NEWER
#if UNITY_2022_2_OR_NEWER
couchPlayerManager = GameObject.FindAnyObjectByType<CouchPlayerManager>();
#else
// Deprecated in Unity 2023.1

View File

@ -23,7 +23,7 @@ public class CouchPlayerManager : NetworkBehaviour
public override void OnStartAuthority()
{
// hook up UI to local player, for cmd communication
#if UNITY_2021_3_OR_NEWER
#if UNITY_2022_2_OR_NEWER
canvasScript = GameObject.FindAnyObjectByType<CanvasScript>();
#else
// Deprecated in Unity 2023.1

View File

@ -33,7 +33,7 @@ public class MatchController : NetworkBehaviour
void Awake()
{
#if UNITY_2021_3_OR_NEWER
#if UNITY_2022_2_OR_NEWER
canvasController = GameObject.FindAnyObjectByType<CanvasController>();
#else
// Deprecated in Unity 2023.1

View File

@ -19,7 +19,7 @@ public class MatchGUI : MonoBehaviour
public void Awake()
{
#if UNITY_2021_3_OR_NEWER
#if UNITY_2022_2_OR_NEWER
canvasController = GameObject.FindAnyObjectByType<CanvasController>();
#else
// Deprecated in Unity 2023.1

View File

@ -188,7 +188,7 @@ private void OnClientDisconnect()
// you first add this script to a gameobject.
private void Reset()
{
#if UNITY_2021_3_OR_NEWER
#if UNITY_2022_2_OR_NEWER
if (!FindAnyObjectByType<NetworkManager>())
Debug.LogError("This component requires a NetworkManager component to be present in the scene. Please add!");
#else