diff --git a/Annotations/EmergencyExitAnnotation.cs b/Annotations/EmergencyExitAnnotation.cs index 175eaaa..34fbea8 100644 --- a/Annotations/EmergencyExitAnnotation.cs +++ b/Annotations/EmergencyExitAnnotation.cs @@ -8,7 +8,7 @@ namespace DeNA.Anjin.Annotations { /// /// Attach this component to the "Return to Title Scene" button or each other buttons that are displayed in the event of communication errors. - /// As soon as the component appears on the screen, it is click by EmergencyExitAgent + /// As soon as the component appears on the screen, it is click by UGUIEmergencyExitAgent /// [RequireComponent(typeof(Button))] public class EmergencyExitAnnotation : MonoBehaviour diff --git a/Editor/Localization/ja.po b/Editor/Localization/ja.po index f13f25f..113c664 100644 --- a/Editor/Localization/ja.po +++ b/Editor/Localization/ja.po @@ -232,6 +232,25 @@ msgid "Agents to serial execution" msgstr "連続実行するAgentを指定します" +#: Editor/UI/Agents/UGUIEmergencyExitAgentEditor.cs + +# intervalMillis +msgid "Interval [ms]" +msgstr "間隔[ミリ秒]" + +# intervalMillis tooltip +msgid "Interval in milliseconds to check for the appearance of the EmergencyExitAnnotation component." +msgstr "EmergencyExitAnnotationコンポーネントの出現を確認する間隔をミリ秒で指定します" + +# screenshot +msgid "Screenshot" +msgstr "スクリーンショット" + +# screenshot tooltip +msgid "Take a screenshot when click the EmergencyExit button." +msgstr "EmergencyExitボタンクリック時にスクリーンショットを撮影します" + + #: Editor/UI/Agents/UGUIMonkeyAgentEditor.cs # lifespanSec (same as DoNothingAgentEditor.cs) diff --git a/Editor/UI/Agents/EmergencyExitAgentEditor.cs b/Editor/UI/Agents/EmergencyExitAgentEditor.cs deleted file mode 100644 index 49b44c7..0000000 --- a/Editor/UI/Agents/EmergencyExitAgentEditor.cs +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright (c) 2023 DeNA Co., Ltd. -// This software is released under the MIT License. - -using DeNA.Anjin.Agents; -using UnityEditor; -using UnityEngine; - -namespace DeNA.Anjin.Editor.UI.Agents -{ - /// - /// Editor GUI for DoNothingAgent - /// - [CustomEditor(typeof(EmergencyExitAgent))] - public class EmergencyExitAgentEditor : UnityEditor.Editor - { - private static readonly string s_description = L10n.Tr("Description"); - private static readonly string s_descriptionTooltip = L10n.Tr("Description about this agent instance"); - - /// - public override void OnInspectorGUI() - { - serializedObject.Update(); - - EditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(EmergencyExitAgent.description)), - new GUIContent(s_description, s_descriptionTooltip)); - - serializedObject.ApplyModifiedProperties(); - } - } -} diff --git a/Editor/UI/Agents/UGUIEmergencyExitAgentEditor.cs b/Editor/UI/Agents/UGUIEmergencyExitAgentEditor.cs new file mode 100644 index 0000000..556a5d9 --- /dev/null +++ b/Editor/UI/Agents/UGUIEmergencyExitAgentEditor.cs @@ -0,0 +1,66 @@ +// Copyright (c) 2023-2024 DeNA Co., Ltd. +// This software is released under the MIT License. + +using DeNA.Anjin.Agents; +using UnityEditor; +using UnityEngine; + +namespace DeNA.Anjin.Editor.UI.Agents +{ + /// + /// Editor GUI for UGUIEmergencyExitAgent + /// + [CustomEditor(typeof(UGUIEmergencyExitAgent))] + public class UGUIEmergencyExitAgentEditor : UnityEditor.Editor + { + private const float SpacerPixels = 10f; + + // @formatter:off + private static readonly string s_description = L10n.Tr("Description"); + private static readonly string s_descriptionTooltip = L10n.Tr("Description about this agent instance"); + private SerializedProperty _descriptionProp; + private GUIContent _descriptionLabel; + + private static readonly string s_intervalMillis = L10n.Tr("Interval [ms]"); + private static readonly string s_intervalMillisTooltip = L10n.Tr("Interval in milliseconds to check for the appearance of the EmergencyExitAnnotation component."); + private SerializedProperty _intervalMillisProp; + private GUIContent _intervalMillisLabel; + + private static readonly string s_screenshot = L10n.Tr("Screenshot"); + private static readonly string s_screenshotTooltip = L10n.Tr("Take a screenshot when click the EmergencyExit button."); + private SerializedProperty _screenshotProp; + private GUIContent _screenshotLabel; + // @formatter:on + + private void OnEnable() + { + Initialize(); + } + + private void Initialize() + { + _descriptionProp = serializedObject.FindProperty(nameof(UGUIEmergencyExitAgent.description)); + _descriptionLabel = new GUIContent(s_description, s_descriptionTooltip); + + _intervalMillisProp = serializedObject.FindProperty(nameof(UGUIEmergencyExitAgent.intervalMillis)); + _intervalMillisLabel = new GUIContent(s_intervalMillis, s_intervalMillisTooltip); + + _screenshotProp = serializedObject.FindProperty(nameof(UGUIEmergencyExitAgent.screenshot)); + _screenshotLabel = new GUIContent(s_screenshot, s_screenshotTooltip); + } + + /// + public override void OnInspectorGUI() + { + serializedObject.Update(); + + EditorGUILayout.PropertyField(_descriptionProp, _descriptionLabel); + GUILayout.Space(SpacerPixels); + + EditorGUILayout.PropertyField(_intervalMillisProp, _intervalMillisLabel); + EditorGUILayout.PropertyField(_screenshotProp, _screenshotLabel); + + serializedObject.ApplyModifiedProperties(); + } + } +} diff --git a/Editor/UI/Agents/EmergencyExitAgentEditor.cs.meta b/Editor/UI/Agents/UGUIEmergencyExitAgentEditor.cs.meta similarity index 100% rename from Editor/UI/Agents/EmergencyExitAgentEditor.cs.meta rename to Editor/UI/Agents/UGUIEmergencyExitAgentEditor.cs.meta diff --git a/README.md b/README.md index d29a47e..af606e1 100644 --- a/README.md +++ b/README.md @@ -415,13 +415,21 @@ This Agent instance (.asset file) can contain the following. > Recommend enabling a `Handle Exception` to interrupt Autopilot if an exception occurs during execution. -### EmergencyExitAgent +### UGUIEmergencyExitAgent -An Agent that monitors the appearance of the `EmergencyExitAnnotations` component in the `DeNA.Anjin.Annotations` assembly and clicks on it as soon as it appears. -This can be used in games that contain behavior that is irregular in the execution of the test scenario, for example, communication errors or "return to title screen" buttons that are triggered by a daybreak. +An Agent that monitors the appearance of the `EmergencyExitAnnotations` component in the Scene and clicks on it as soon as it appears. +This can be used in games that contain behavior that is irregular in the execution of the test scenario, for example, communication errors or "Return to Title Screen" buttons that are triggered by a daybreak. It should always be started at the same time as other Agents (that actually perform game operations). -This can be accomplished with `ParallelCompositeAgent`, but it is easier to set it up as an `Scene Crossing Agents` in AutopilotSettings. +Generally, you add to `Scene Crossing Agents` in `AutopilotSettings`. +If you want to change the settings for each Scene, use with `ParallelCompositeAgent`. + +This Agent instance (.asset file) can contain the following. + +
+
Interval
Interval in milliseconds to check for the appearance of the EmergencyExitAnnotation component.
+
Screenshot
Take a screenshot when click the EmergencyExit button.
+
@@ -600,7 +608,7 @@ The `GameObject` to which this component is attached avoids manipulation by the ### EmergencyExitAnnotations -When a `Button` to which this component is attached appears, the `EmergencyExitAgent` will immediately attempt to click on it. +When a `Button` to which this component is attached appears, the `UGUIEmergencyExitAgent` will immediately attempt to click on it. It is intended to be attached to buttons that are irregular in the execution of the test scenario, such as the "return to title screen" button due to a communication error or a daybreak. diff --git a/README_ja.md b/README_ja.md index 6d74946..55bfa84 100644 --- a/README_ja.md +++ b/README_ja.md @@ -420,13 +420,21 @@ Sceneごとに設定を変えたい場合は、`ParallelCompositeAgent` と合 > 実行中に例外が発生した時点でオートパイロットを中断するために、`Handle Exception` の有効化をお勧めします。 -### EmergencyExitAgent +### UGUIEmergencyExitAgent -`DeNA.Anjin.Annotations` アセンブリに含まれる `EmergencyExitAnnotations` コンポーネントの出現を監視し、表示されたら即クリックするAgentです。 +Sceneに含まれる `EmergencyExitAnnotations` コンポーネントの出現を監視し、表示されたら即クリックするAgentです。 たとえば通信エラーや日またぎで「タイトル画面に戻る」ボタンのような、テストシナリオ遂行上イレギュラーとなる振る舞いが含まれるゲームで利用できます。 常に、他の(実際にゲーム操作を行なう)Agentと同時に起動しておく必要があります。 -`ParallelCompositeAgent` でも実現できますが、AutopilotSettingsの `Scene Crossing Agents` に追加するほうが簡単です。 +一般的には、`AutopilotSettings` の `Scene Crossing Agents` に追加します。 +Sceneごとに設定を変えたい場合は、`ParallelCompositeAgent` と合わせて使用します。 + +このAgentのインスタンス(.assetファイル)には以下を設定できます。 + +
+
間隔
EmergencyExitAnnotationコンポーネントの出現を確認する間隔をミリ秒で指定します
+
スクリーンショット
EmergencyExitボタンクリック時にスクリーンショットを撮影します
+
@@ -606,7 +614,7 @@ Anjinの操作を制御するためのアノテーションを定義していま ### EmergencyExitAnnotations -このコンポーネントがアタッチされた`Button`が表示されると、`EmergencyExitAgent`はすぐにクリックを試みます。 +このコンポーネントがアタッチされた`Button`が表示されると、`UGUIEmergencyExitAgent`はすぐにクリックを試みます。 通信エラーや日またぎで「タイトル画面に戻る」ボタンのような、テストシナリオ遂行上イレギュラーとなるボタンに付けることを想定しています。 diff --git a/Runtime/Agents/EmergencyExitAgent.cs b/Runtime/Agents/EmergencyExitAgent.cs deleted file mode 100644 index 13b8bbc..0000000 --- a/Runtime/Agents/EmergencyExitAgent.cs +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright (c) 2023 DeNA Co., Ltd. -// This software is released under the MIT License. - -using System.Diagnostics.CodeAnalysis; -using System.Threading; -using Cysharp.Threading.Tasks; -using DeNA.Anjin.Annotations; -using UnityEngine; -using UnityEngine.EventSystems; -using UnityEngine.UI; - -namespace DeNA.Anjin.Agents -{ - /// - /// Search and click EmergencyExit annotation component. - /// This agent will not be terminate and will continue to be observe. - /// - [CreateAssetMenu(fileName = "New EmergencyExitAgent", menuName = "Anjin/Emergency Exit Agent", order = 21)] - public class EmergencyExitAgent : AbstractAgent - { - /// - [SuppressMessage("Blocker Bug", "S2190:Recursion should not be infinite")] - [SuppressMessage("ReSharper", "FunctionNeverReturns")] - public override async UniTask Run(CancellationToken token) - { - Logger.Log($"Enter {this.name}.Run()"); - - var selectables = new Selectable[20]; - try - { - while (true) // Note: This agent is not terminate myself - { - var allSelectableCount = Selectable.allSelectableCount; - if (selectables.Length < allSelectableCount) - { - selectables = new Selectable[allSelectableCount]; - } - - Selectable.AllSelectablesNoAlloc(selectables); - for (var i = 0; i < allSelectableCount; i++) - { - if (selectables[i].TryGetComponent(out var emergencyExit)) - { - ClickEmergencyExitButton(emergencyExit); - } - } - - await UniTask.NextFrame(token); - } - } - finally - { - Logger.Log($"Exit {this.name}.Run()"); - } - } - - [SuppressMessage("ReSharper", "SuggestBaseTypeForParameter")] - private void ClickEmergencyExitButton(EmergencyExitAnnotation emergencyExitAnnotation) - { - Logger.Log($"Click emergency exit button: {emergencyExitAnnotation.name}"); - - var gameObject = emergencyExitAnnotation.gameObject; - var button = gameObject.GetComponent