From 50b1551f2f44f4be0295b149cac29f4d8c8e5d3c Mon Sep 17 00:00:00 2001 From: Koji Hasegawa Date: Sun, 1 Dec 2024 04:48:29 +0900 Subject: [PATCH 1/2] Fix to use FindObject(s)ByType when Unity 2022.3 or newer --- Runtime/AgentInspector.cs | 5 +++++ Runtime/Autopilot.cs | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/Runtime/AgentInspector.cs b/Runtime/AgentInspector.cs index dff908b..615cc05 100644 --- a/Runtime/AgentInspector.cs +++ b/Runtime/AgentInspector.cs @@ -18,6 +18,11 @@ public class AgentInspector : MonoBehaviour /// Returns the running Agent instance array. /// No caching. /// +#if UNITY_2022_3_OR_NEWER + public static AgentInspector[] Instances => FindObjectsByType(FindObjectsSortMode.None); + // Note: Supported in Unity 2020.3.4, 2021.3.18, 2022.2.5 or later. +#else public static AgentInspector[] Instances => FindObjectsOfType(); +#endif } } diff --git a/Runtime/Autopilot.cs b/Runtime/Autopilot.cs index 0fdfb5d..4c1faf2 100644 --- a/Runtime/Autopilot.cs +++ b/Runtime/Autopilot.cs @@ -55,7 +55,12 @@ public static Autopilot Instance { get { +#if UNITY_2022_3_OR_NEWER + var autopilot = FindAnyObjectByType(); + // Note: Supported in Unity 2020.3.4, 2021.3.18, 2022.2.5 or later. +#else var autopilot = FindObjectOfType(); +#endif if (autopilot == null) { throw new InvalidOperationException("Autopilot instance not found"); From d6d66604c34f4d3c804c47894b3ab80dd48ffa82 Mon Sep 17 00:00:00 2001 From: Koji Hasegawa Date: Sun, 1 Dec 2024 04:51:39 +0900 Subject: [PATCH 2/2] Fix test asset name --- Tests/Runtime/Agents/UGUIPlaybackAgentTest.cs | 1 - Tests/TestAssets/PlaybackAgent.asset | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/Tests/Runtime/Agents/UGUIPlaybackAgentTest.cs b/Tests/Runtime/Agents/UGUIPlaybackAgentTest.cs index 2b89dec..2ca1047 100644 --- a/Tests/Runtime/Agents/UGUIPlaybackAgentTest.cs +++ b/Tests/Runtime/Agents/UGUIPlaybackAgentTest.cs @@ -116,7 +116,6 @@ public async Task Run_WithAssetFile() #endif agent.Logger = Debug.unityLogger; agent.Random = new RandomFactory(0).CreateRandom(); - agent.name = TestContext.CurrentContext.Test.Name; using (var cancellationTokenSource = new CancellationTokenSource()) { diff --git a/Tests/TestAssets/PlaybackAgent.asset b/Tests/TestAssets/PlaybackAgent.asset index 471da42..2788d46 100644 --- a/Tests/TestAssets/PlaybackAgent.asset +++ b/Tests/TestAssets/PlaybackAgent.asset @@ -10,7 +10,7 @@ MonoBehaviour: m_Enabled: 1 m_EditorHideFlags: 0 m_Script: {fileID: 11500000, guid: d429d6926ea8c4f688c2bfed7e53d7cf, type: 3} - m_Name: Run_WithAssetFile + m_Name: PlaybackAgent m_EditorClassIdentifier: description: recordedJson: {fileID: 4900000, guid: 7847549ddc204e628dbc7746afd8f03f, type: 3}