From c1d7a4b099d85270504d4cb9c2cc02f95b466c26 Mon Sep 17 00:00:00 2001 From: Isamu Mogi Date: Fri, 3 May 2024 00:01:38 +0900 Subject: [PATCH 1/6] =?UTF-8?q?Unity2023.1=E4=BB=A5=E9=99=8D=E3=81=A7GetSc?= =?UTF-8?q?riptingDefineSymbolsForGroup=E7=B3=BBAPI=E3=81=8CObsolete?= =?UTF-8?q?=E8=AD=A6=E5=91=8A=E3=81=8C=E5=87=BA=E3=82=8B=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 Unity 2023.1以降のバージョンでPlayerSettings.GetScriptingDefineSymbolsForGroup()系の関数がObsoleteになり、次の警告が発生していました。 ``` Assets\UniGLTF\Editor\UniGLTF\UniGLTFPreference.cs(109,27): warning CS0618: 'PlayerSettings.GetScriptingDefineSymbolsForGroup(BuildTargetGroup)' is obsolete: 'Use GetScriptingDefineSymbols(NamedBuildTarget buildTarget) instead' Assets\UniGLTF\Editor\UniGLTF\UniGLTFPreference.cs(116,27): warning CS0618: 'PlayerSettings.GetScriptingDefineSymbolsForGroup(BuildTargetGroup)' is obsolete: 'Use GetScriptingDefineSymbols(NamedBuildTarget buildTarget) instead' Assets\UniGLTF\Editor\UniGLTF\UniGLTFPreference.cs(117,13): warning CS0618: 'PlayerSettings.SetScriptingDefineSymbolsForGroup(BuildTargetGroup, string)' is obsolete: 'Use SetScriptingDefineSymbols(NamedBuildTarget buildTarget, string defines) instead' Assets\UniGLTF\Editor\UniGLTF\UniGLTFPreference.cs(125,27): warning CS0618: 'PlayerSettings.GetScriptingDefineSymbolsForGroup(BuildTargetGroup)' is obsolete: 'Use GetScriptingDefineSymbols(NamedBuildTarget buildTarget) instead' Assets\UniGLTF\Editor\UniGLTF\UniGLTFPreference.cs(126,13): warning CS0618: 'PlayerSettings.SetScriptingDefineSymbolsForGroup(BuildTargetGroup, string)' is obsolete: 'Use SetScriptingDefineSymbols(NamedBuildTarget buildTarget, string defines) instead' ``` 代わりにGetScriptingDefineSymbols系APIを使うようにしました。これはUnity 2021.3にも存在しているので、そのまま置き換えることができました。 --- .../Editor/UniGLTF/UniGLTFPreference.cs | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/Assets/UniGLTF/Editor/UniGLTF/UniGLTFPreference.cs b/Assets/UniGLTF/Editor/UniGLTF/UniGLTFPreference.cs index 2906a996a..2d03c7085 100644 --- a/Assets/UniGLTF/Editor/UniGLTF/UniGLTFPreference.cs +++ b/Assets/UniGLTF/Editor/UniGLTF/UniGLTFPreference.cs @@ -105,27 +105,29 @@ namespace UniGLTF public static bool HasSymbol(string symbol) { - var target = EditorUserBuildSettings.selectedBuildTargetGroup; - var current = PlayerSettings.GetScriptingDefineSymbolsForGroup(target).Split(';'); + var buildTarget = UnityEditor.Build.NamedBuildTarget.FromBuildTargetGroup( + EditorUserBuildSettings.selectedBuildTargetGroup + ); + PlayerSettings.GetScriptingDefineSymbols(buildTarget, out var current); return current.Contains(symbol); } public static void AddSymbol(string symbol) { - var target = EditorUserBuildSettings.selectedBuildTargetGroup; - var current = PlayerSettings.GetScriptingDefineSymbolsForGroup(target).Split(';'); - PlayerSettings.SetScriptingDefineSymbolsForGroup(target, - string.Join(";", current.Concat(new[] { symbol })) + var buildTarget = UnityEditor.Build.NamedBuildTarget.FromBuildTargetGroup( + EditorUserBuildSettings.selectedBuildTargetGroup ); + PlayerSettings.GetScriptingDefineSymbols(buildTarget, out var current); + PlayerSettings.SetScriptingDefineSymbols(buildTarget, current.Append(symbol).ToArray()); } public static void RemoveSymbol(string symbol) { - var target = EditorUserBuildSettings.selectedBuildTargetGroup; - var current = PlayerSettings.GetScriptingDefineSymbolsForGroup(target).Split(';'); - PlayerSettings.SetScriptingDefineSymbolsForGroup(target, - string.Join(";", current.Where(x => x != symbol)) + var buildTarget = UnityEditor.Build.NamedBuildTarget.FromBuildTargetGroup( + EditorUserBuildSettings.selectedBuildTargetGroup ); + PlayerSettings.GetScriptingDefineSymbols(buildTarget, out var current); + PlayerSettings.SetScriptingDefineSymbols(buildTarget, current.Where(x => x != symbol).ToArray()); } public static void ToggleSymbol(string title, string symbol) From 018aec1fabecf18eac001705b750eb3a5607b8b6 Mon Sep 17 00:00:00 2001 From: Isamu Mogi Date: Fri, 3 May 2024 00:02:15 +0900 Subject: [PATCH 2/6] =?UTF-8?q?Unity2023.1=E4=BB=A5=E9=99=8D=E3=81=A7FindO?= =?UTF-8?q?bjectsOfType=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