-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #108 from nowsprinting/feature/emergency_exit_agent
Rename and enhancement UGUIEmergencyExitAgent
- Loading branch information
Showing
13 changed files
with
269 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
{ | ||
/// <summary> | ||
/// Editor GUI for UGUIEmergencyExitAgent | ||
/// </summary> | ||
[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); | ||
} | ||
|
||
/// <inheritdoc/> | ||
public override void OnInspectorGUI() | ||
{ | ||
serializedObject.Update(); | ||
|
||
EditorGUILayout.PropertyField(_descriptionProp, _descriptionLabel); | ||
GUILayout.Space(SpacerPixels); | ||
|
||
EditorGUILayout.PropertyField(_intervalMillisProp, _intervalMillisLabel); | ||
EditorGUILayout.PropertyField(_screenshotProp, _screenshotLabel); | ||
|
||
serializedObject.ApplyModifiedProperties(); | ||
} | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
// Copyright (c) 2023-2024 DeNA Co., Ltd. | ||
// This software is released under the MIT License. | ||
|
||
using System.Text; | ||
using System.Threading; | ||
using Cysharp.Threading.Tasks; | ||
using DeNA.Anjin.Annotations; | ||
using DeNA.Anjin.Strategies; | ||
using TestHelper.Monkey.Operators; | ||
using TestHelper.Monkey.ScreenshotFilenameStrategies; | ||
using TestHelper.RuntimeInternals; | ||
using UnityEngine; | ||
using UnityEngine.UI; | ||
|
||
namespace DeNA.Anjin.Agents | ||
{ | ||
/// <summary> | ||
/// Wait for the <c>EmergencyExitAnnotation</c> component to appear and click attached <c>UnityEngine.UI.Button</c>. | ||
/// This Agent will not be terminated and will continue to be observed. | ||
/// </summary> | ||
[CreateAssetMenu(fileName = "New UGUIEmergencyExitAgent", menuName = "Anjin/uGUI Emergency Exit Agent", order = 51)] | ||
public class UGUIEmergencyExitAgent : AbstractAgent | ||
{ | ||
/// <summary> | ||
/// Interval in milliseconds to check for the appearance of the <c>EmergencyExitAnnotation</c> component. | ||
/// </summary> | ||
public int intervalMillis = 1000; | ||
|
||
/// <summary> | ||
/// Take a screenshot when click the EmergencyExit button. | ||
/// </summary> | ||
public bool screenshot; | ||
|
||
private static IClickOperator ClickOperator => new UGUIClickOperator(); | ||
private IScreenshotFilenameStrategy _filenameStrategy; | ||
|
||
/// <inheritdoc /> | ||
public override async UniTask Run(CancellationToken token) | ||
{ | ||
Logger.Log($"Enter {this.name}.Run()"); | ||
this._filenameStrategy = new TwoTieredCounterStrategy(this.name); | ||
|
||
try | ||
{ | ||
var selectables = new Selectable[20]; | ||
|
||
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<EmergencyExitAnnotation>(out var emergencyExit)) | ||
{ | ||
await ClickEmergencyExitButton(emergencyExit, token); | ||
} | ||
} | ||
|
||
await UniTask.Delay(intervalMillis, ignoreTimeScale: true, cancellationToken: token); | ||
} | ||
} | ||
finally | ||
{ | ||
Logger.Log($"Exit {this.name}.Run()"); | ||
} | ||
} | ||
|
||
private async UniTask ClickEmergencyExitButton(EmergencyExitAnnotation emergencyExit, | ||
CancellationToken cancellationToken = default) | ||
{ | ||
var button = emergencyExit.gameObject.GetComponent<Button>(); | ||
if (!ClickOperator.CanOperate(button)) | ||
{ | ||
return; | ||
} | ||
|
||
var message = new StringBuilder($"Click emergency exit button: {button.gameObject.name}"); | ||
if (screenshot) | ||
{ | ||
var filename = _filenameStrategy.GetFilename(); | ||
await ScreenshotHelper.TakeScreenshot(filename: filename).ToUniTask(button); | ||
message.Append($" ({filename})"); | ||
} | ||
|
||
Logger.Log(message.ToString()); | ||
|
||
await ClickOperator.OperateAsync(button, cancellationToken); | ||
} | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.