From 698a4dbc8e09a12b24360567c5fb35880c916d31 Mon Sep 17 00:00:00 2001 From: Isamu Mogi Date: Tue, 14 May 2024 20:15:56 +0900 Subject: [PATCH] =?UTF-8?q?Unity2022.2.4=E4=BB=A5=E4=B8=8B=E3=81=A82021.3.?= =?UTF-8?q?17=E4=BB=A5=E4=B8=8B=E3=81=A7FindObjectBy=E7=B3=BBAPI=E3=81=8C?= =?UTF-8?q?=E5=AD=98=E5=9C=A8=E3=81=97=E3=81=AA=E3=81=84=E3=81=AE=E3=81=AB?= =?UTF-8?q?=E5=AF=BE=E5=BF=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit FindObjectsBy系のAPIは、UniVRMがサポートしているUnityのうち、次の範囲のバージョンには存在しない。 - 2021.3.0~2021.3.17 - 2022.1.0~2022.1.24 - 2022.2.0~2022.2.4 そのため、該当するバージョンのUnityではコンパイルエラーが発生していた。UNITY_2022_3_OR_NEWERで分岐することで、旧APIと新APIを安全に選択するようにした。 厳密にはUNITY_2022_2_5_OR_NEWERを用いたいが、そのようなシンボルは存在していなかった。 --- .../Runtime/BlendShape/PreviewSceneManager.cs | 4 +++ .../VRMFirstPersonCameraManager.cs | 4 +++ .../Runtime/LookAt/LookAtTargetSwitcher.cs | 5 +++ .../Expression/Preview/PreviewSceneManager.cs | 4 +++ .../System/FastSpringBoneService.cs | 4 +++ .../VRM10CanvasManager.cs | 5 +++ .../VRM10Viewer/VRM10ViewerUI.cs | 32 +++++++++++++++++++ .../FirstPersonSample/CanvasManager.cs | 5 +++ Assets/VRM_Samples/SimpleViewer/ViewerUI.cs | 18 +++++++++++ 9 files changed, 81 insertions(+) diff --git a/Assets/VRM/Runtime/BlendShape/PreviewSceneManager.cs b/Assets/VRM/Runtime/BlendShape/PreviewSceneManager.cs index 843ff1291..e334356ac 100644 --- a/Assets/VRM/Runtime/BlendShape/PreviewSceneManager.cs +++ b/Assets/VRM/Runtime/BlendShape/PreviewSceneManager.cs @@ -25,7 +25,11 @@ namespace VRM PreviewSceneManager manager = null; // if we already instantiated a PreviewInstance previously but just lost the reference, then use that same instance instead of making a new one +#if UNITY_2022_3_OR_NEWER var managers = GameObject.FindObjectsByType(FindObjectsSortMode.InstanceID); +#else + var managers = GameObject.FindObjectsOfType(); +#endif foreach (var x in managers) { if (x.Prefab == prefab) diff --git a/Assets/VRM/Runtime/FirstPerson/VRMFirstPersonCameraManager.cs b/Assets/VRM/Runtime/FirstPerson/VRMFirstPersonCameraManager.cs index 8126111ef..21817a5af 100644 --- a/Assets/VRM/Runtime/FirstPerson/VRMFirstPersonCameraManager.cs +++ b/Assets/VRM/Runtime/FirstPerson/VRMFirstPersonCameraManager.cs @@ -57,7 +57,11 @@ namespace VRM void Reset() { +#if UNITY_2022_3_OR_NEWER var cameras = GameObject.FindObjectsByType(FindObjectsSortMode.InstanceID); +#else + var cameras = GameObject.FindObjectsOfType(); +#endif m_firstPersonCamera = Camera.main; m_thirdPersonCameras = cameras.Where(x => x != m_firstPersonCamera).ToArray(); } diff --git a/Assets/VRM/Runtime/LookAt/LookAtTargetSwitcher.cs b/Assets/VRM/Runtime/LookAt/LookAtTargetSwitcher.cs index f7c99ec3e..8f4812f76 100644 --- a/Assets/VRM/Runtime/LookAt/LookAtTargetSwitcher.cs +++ b/Assets/VRM/Runtime/LookAt/LookAtTargetSwitcher.cs @@ -20,8 +20,13 @@ namespace VRM private void Reset() { +#if UNITY_2022_3_OR_NEWER m_lookAtHead = GameObject.FindFirstObjectByType(); m_blinker = GameObject.FindFirstObjectByType(); +#else + m_lookAtHead = GameObject.FindObjectOfType(); + m_blinker = GameObject.FindObjectOfType(); +#endif } float CalcScore(Transform target) diff --git a/Assets/VRM10/Runtime/Components/Expression/Preview/PreviewSceneManager.cs b/Assets/VRM10/Runtime/Components/Expression/Preview/PreviewSceneManager.cs index 3a9c8d836..418d0eebe 100644 --- a/Assets/VRM10/Runtime/Components/Expression/Preview/PreviewSceneManager.cs +++ b/Assets/VRM10/Runtime/Components/Expression/Preview/PreviewSceneManager.cs @@ -27,7 +27,11 @@ namespace UniVRM10 PreviewSceneManager manager = null; // if we already instantiated a PreviewInstance previously but just lost the reference, then use that same instance instead of making a new one +#if UNITY_2022_3_OR_NEWER var managers = GameObject.FindObjectsByType(FindObjectsSortMode.InstanceID); +#else + var managers = GameObject.FindObjectsOfType(); +#endif foreach (var x in managers) { if (x.Prefab == prefab) diff --git a/Assets/VRM10/Runtime/FastSpringBone/System/FastSpringBoneService.cs b/Assets/VRM10/Runtime/FastSpringBone/System/FastSpringBoneService.cs index da1e52f28..aef3a652f 100644 --- a/Assets/VRM10/Runtime/FastSpringBone/System/FastSpringBoneService.cs +++ b/Assets/VRM10/Runtime/FastSpringBone/System/FastSpringBoneService.cs @@ -49,7 +49,11 @@ namespace UniVRM10.FastSpringBones.System { if (_instance) return _instance; +#if UNITY_2022_3_OR_NEWER _instance = FindFirstObjectByType(); +#else + _instance = FindObjectOfType(); +#endif if (_instance) return _instance; var gameObject = new GameObject("FastSpringBone Service"); diff --git a/Assets/VRM10_Samples/VRM10FirstPersonSample/VRM10CanvasManager.cs b/Assets/VRM10_Samples/VRM10FirstPersonSample/VRM10CanvasManager.cs index 6e01fd11e..09fae2b50 100644 --- a/Assets/VRM10_Samples/VRM10FirstPersonSample/VRM10CanvasManager.cs +++ b/Assets/VRM10_Samples/VRM10FirstPersonSample/VRM10CanvasManager.cs @@ -15,8 +15,13 @@ namespace UniVRM10.FirstPersonSample private void Reset() { +#if UNITY_2022_3_OR_NEWER LoadVRMButton = GameObject.FindObjectsByType