From 018aec1fabecf18eac001705b750eb3a5607b8b6 Mon Sep 17 00:00:00 2001 From: Isamu Mogi Date: Fri, 3 May 2024 00:02:15 +0900 Subject: [PATCH] =?UTF-8?q?Unity2023.1=E4=BB=A5=E9=99=8D=E3=81=A7FindObjec?= =?UTF-8?q?tsOfType=E7=B3=BBAPI=E3=81=8CObsolete=E8=AD=A6=E5=91=8A?= =?UTF-8?q?=E3=82=92=E5=87=BA=E3=81=99=E3=81=AE=E3=81=AB=E5=AF=BE=E5=BF=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Unity 2023.1以降のバージョンでUnityEngine.Object.FindObjectsOfType系APIがObsoleteになり、次の警告が発生していました。 ``` Assets/VRM10_Samples/VRM10Viewer/VRM10ViewerUI.cs(250,24): warning CS0618: 'Object.FindObjectOfType()' is obsolete: 'Object.FindObjectOfType has been deprecated. Use Object.FindFirstObjectByType instead or if finding any instance is acceptable the faster Object.FindAnyObjectByType' Assets/VRM10_Samples/VRM10Viewer/VRM10ViewerUI.cs(208,31): warning CS0618: 'Object.FindObjectsOfType()' is obsolete: 'Object.FindObjectsOfType has been deprecated. Use Object.FindObjectsByType instead which lets you decide whether you need the results sorted or not. FindObjectsOfType sorts the results by InstanceID but if you do not need this using FindObjectSortMode.None is considerably faster.' ``` 代わりにFindObjectsBy系APIを使うようにしました。これはUnity 2021.3にも存在しているので、そのまま使うことができました。 FindObjectOfType()とFindFirstObjectByType()の違いに関してはドキュメントからは読み取れませんでしたが、 Unity-Technologiesgが公開しているUnity 6000のソースコードを見る限り、動作は同一に見えるためそのまま置き換えました。 https://github.com/Unity-Technologies/UnityCsReference/blob/6000.0/Runtime/Export/Scripting/UnityEngineObject.bindings.cs#L586-L602 --- .../Runtime/BlendShape/PreviewSceneManager.cs | 2 +- .../FirstPerson/VRMFirstPersonCameraManager.cs | 2 +- .../VRM/Runtime/LookAt/LookAtTargetSwitcher.cs | 4 ++-- .../Expression/Preview/PreviewSceneManager.cs | 2 +- .../System/FastSpringBoneService.cs | 2 +- .../VRM10FirstPersonSample/VRM10CanvasManager.cs | 4 ++-- .../VRM10_Samples/VRM10Viewer/VRM10ViewerUI.cs | 16 ++++++++-------- .../FirstPersonSample/CanvasManager.cs | 4 ++-- Assets/VRM_Samples/SimpleViewer/ViewerUI.cs | 10 +++++----- 9 files changed, 23 insertions(+), 23 deletions(-) diff --git a/Assets/VRM/Runtime/BlendShape/PreviewSceneManager.cs b/Assets/VRM/Runtime/BlendShape/PreviewSceneManager.cs index 15875e7be..843ff1291 100644 --- a/Assets/VRM/Runtime/BlendShape/PreviewSceneManager.cs +++ b/Assets/VRM/Runtime/BlendShape/PreviewSceneManager.cs @@ -25,7 +25,7 @@ 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 - var managers = GameObject.FindObjectsOfType(); + var managers = GameObject.FindObjectsByType(FindObjectsSortMode.InstanceID); 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 dda06faa7..8126111ef 100644 --- a/Assets/VRM/Runtime/FirstPerson/VRMFirstPersonCameraManager.cs +++ b/Assets/VRM/Runtime/FirstPerson/VRMFirstPersonCameraManager.cs @@ -57,7 +57,7 @@ namespace VRM void Reset() { - var cameras = GameObject.FindObjectsOfType(); + var cameras = GameObject.FindObjectsByType(FindObjectsSortMode.InstanceID); 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 c6bb6ccaa..f7c99ec3e 100644 --- a/Assets/VRM/Runtime/LookAt/LookAtTargetSwitcher.cs +++ b/Assets/VRM/Runtime/LookAt/LookAtTargetSwitcher.cs @@ -20,8 +20,8 @@ namespace VRM private void Reset() { - m_lookAtHead = GameObject.FindObjectOfType(); - m_blinker = GameObject.FindObjectOfType(); + m_lookAtHead = GameObject.FindFirstObjectByType(); + m_blinker = GameObject.FindFirstObjectByType(); } 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 51d83ba51..3a9c8d836 100644 --- a/Assets/VRM10/Runtime/Components/Expression/Preview/PreviewSceneManager.cs +++ b/Assets/VRM10/Runtime/Components/Expression/Preview/PreviewSceneManager.cs @@ -27,7 +27,7 @@ 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 - var managers = GameObject.FindObjectsOfType(); + var managers = GameObject.FindObjectsByType(FindObjectsSortMode.InstanceID); 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 d33caa111..da1e52f28 100644 --- a/Assets/VRM10/Runtime/FastSpringBone/System/FastSpringBoneService.cs +++ b/Assets/VRM10/Runtime/FastSpringBone/System/FastSpringBoneService.cs @@ -49,7 +49,7 @@ namespace UniVRM10.FastSpringBones.System { if (_instance) return _instance; - _instance = FindObjectOfType(); + _instance = FindFirstObjectByType(); 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 9cded7de8..6e01fd11e 100644 --- a/Assets/VRM10_Samples/VRM10FirstPersonSample/VRM10CanvasManager.cs +++ b/Assets/VRM10_Samples/VRM10FirstPersonSample/VRM10CanvasManager.cs @@ -15,8 +15,8 @@ namespace UniVRM10.FirstPersonSample private void Reset() { - LoadVRMButton = GameObject.FindObjectsOfType