Skip to content

Commit

Permalink
Screenshot feature
Browse files Browse the repository at this point in the history
  • Loading branch information
Kuniwak committed Nov 8, 2023
1 parent cd0170e commit 50dc5e4
Show file tree
Hide file tree
Showing 3 changed files with 287 additions and 1 deletion.
66 changes: 66 additions & 0 deletions Editor/Localization/ja.po
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,72 @@ msgstr "最小文字列長"
msgid "Maximum Length"
msgstr "最大文字列長"

# screenshot options
msgid "Screenshot Options"
msgstr "スクリーンショット設定"

# screenshot options enabled
msgid "Enabled"
msgstr "有効"

# screenshot options enabled tooltip
msgid "Whether screenshot is enabled or not"
msgstr "スクリーンショットが有効かどうか"

# screenshot directory
msgid "Directory"
msgstr "ディレクトリ"

# screenshot directory path
msgid "Path"
msgstr "パス"

# screenshot directory path tooltip
msgid "Directory path to save screenshots"
msgstr "スクリーンショットの保存先ディレクトリのパス"

# screenshot directory use default
msgid "Use Default"
msgstr "デフォルト値を使用"

# screenshot directory use default tooltip
msgid "Whether using a default directory path to save screenshots or specifying it manually. Default value is Application.persistentDataPath + \"/TestHelper.Monkey/Screenshots/\""
msgstr "スクリーンショットの保存先のディレクトリ名にデフォルト値を使うかどうか。デフォルト値は Application.persistentDataPath + \"/TestHelper.Monkey/Screenshots/\""

# screenshot filename
msgid "Filename"
msgstr "ファイル名"

# screenshot filename prefix
msgid "Prefix"
msgstr "プレフィックス"

# screenshot filename prefix tooltip
msgid "Prefix of screenshots filename"
msgstr "スクリーンショットのファイル名のプレフィックス"

# screenshot filename prefix use default
msgid "Use Default"
msgstr "デフォルト値を使用"

# screenshot filename prefix use default tooltip
msgid "Whether using a default prefix of screenshots filename or specifying it manually. Default value is CurrentTest.Name if run in test-framework context. Otherwise, a caller method name"
msgstr "スクリーンショットのファイル名のプレフィックスにデフォルト値を使うかどうか。デフォルト値はもしテストフレームワークのからの実行であれば CurrentTest.Name、そうでなければ呼び出し元の関数名"

# screenshot super size
msgid "Super Size"
msgstr "拡大係数"

msgid "The factor to increase resolution with. Neither this nor Stereo Capture Mode can be specified"
msgstr "解像度をあげるための係数。ステレオキャプチャモードと同時には設定できません"

# screenshot stereo capture mode
msgid "Stereo Capture Mode"
msgstr "ステレオキャプチャモード"

msgid "The eye texture to capture when stereo rendering is enabled. Neither this nor Resolution Factor can be specified"
msgstr "ステレオレンダリングが有効な場合は指定した眼のテクスチャ。拡大係数と同時には設定できません"

#: Editor/UI/Agents/UGUIPlaybackAgentEditor.cs

# recordedJson
Expand Down
184 changes: 184 additions & 0 deletions Editor/UI/Agents/UGUIMonkeyAgentEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,66 @@ public class UGUIMonkeyAgentEditor : UnityEditor.Editor
private GUIContent _randomStringParamsEntryMinLengthGUIContent;
private GUIContent _randomStringParamsEntryMaxLengthGUIContent;

private static readonly string s_screenshotOptions = L10n.Tr("Screenshot Options");
private static readonly string s_screenshotEnabled = L10n.Tr("Enabled");
private static readonly string s_screenshotEnabledTooltip = L10n.Tr("Whether screenshot is enabled or not");
private SerializedProperty _screenshotEnabledProp;
private GUIContent _screenshotEnabledGUIContent;

private static readonly string s_screenshotDirectory = L10n.Tr("Directory");
private static readonly string s_screenshotDefaultDirectory = L10n.Tr("Use Default");

private static readonly string s_screenshotDefaultDirectoryTooltip = L10n.Tr(
@"Whether using a default directory path to save screenshots or specifying it manually. Default value is Application.persistentDataPath + ""/TestHelper.Monkey/Screenshots/"""
);

private static readonly string s_screenshotDirectoryPath = L10n.Tr("Path");
private static readonly string s_screenshotDirectoryPathTooltip = L10n.Tr("Directory path to save screenshots");
private SerializedProperty _screenshotDefaultDirectoryProp;
private GUIContent _screenshotDefaultDirectoryGUIContent;
private SerializedProperty _screenshotDirectoryProp;
private GUIContent _screenshotDirectoryGUIContent;

private static readonly string s_screenshotFilename = L10n.Tr("Filename");
private static readonly string s_screenshotDefaultFilenamePrefix = L10n.Tr("Use Default");

private static readonly string s_screenshotDefaultFilenamePrefixTooltip = L10n.Tr(
"Whether using a default prefix of screenshots filename or specifying it manually. Default value is CurrentTest.Name if run in test-framework context. Otherwise, a caller method name"
);

private static readonly string s_screenshotFilenamePrefix = L10n.Tr("Prefix");
private static readonly string s_screenshotFilenamePrefixTooltip = L10n.Tr("Prefix of screenshots filename");
private SerializedProperty _screenshotDefaultFilenamePrefixProp;
private GUIContent _screenshotDefaultFilenamePrefixGUIContent;
private SerializedProperty _screenshotFilenamePrefixProp;
private GUIContent _screenshotFilenamePrefixGUIContent;

private static readonly string s_screenshotSuperSize = L10n.Tr("Super Size");

private static readonly string s_screenshotSuperSizeTooltip = L10n.Tr(
"The factor to increase resolution with. Neither this nor Stereo Capture Mode can be specified"
);

private SerializedProperty _screenshotSuperSizeProp;
private GUIContent _screenshotSuperSizeGUIContent;
private GUIContent _screenshotSuperSizeGUIContentDisabled;

private static readonly string s_screenshotStereoCaptureMode = L10n.Tr("Stereo Capture Mode");

private static readonly string s_screenshotStereoCaptureModeTooltip =
L10n.Tr(
"The eye texture to capture when stereo rendering is enabled. Neither this nor Resolution Factor can be specified"
);

private SerializedProperty _screenshotStereoCaptureModeProp;
private GUIContent _screenshotStereoCaptureModeGUIContent;
private GUIContent _screenshotStereoCaptureModeGUIContentDisabled;

private const int DefaultSuperSize = 1;

private const ScreenCapture.StereoScreenCaptureMode DefaultStereoScreenCaptureMode =
ScreenCapture.StereoScreenCaptureMode.LeftEye;


private void OnEnable()
{
Expand Down Expand Up @@ -162,6 +222,49 @@ private void Initialize()
);
}
};

_screenshotEnabledProp = serializedObject.FindProperty(nameof(UGUIMonkeyAgent.screenshotEnabled));
_screenshotEnabledGUIContent = new GUIContent(s_screenshotEnabled, s_screenshotEnabledTooltip);

_screenshotDefaultDirectoryProp =
serializedObject.FindProperty(nameof(UGUIMonkeyAgent.defaultScreenshotDirectory));
_screenshotDefaultDirectoryGUIContent = new GUIContent(
s_screenshotDefaultDirectory,
s_screenshotDefaultDirectoryTooltip
);
_screenshotDirectoryProp = serializedObject.FindProperty(nameof(UGUIMonkeyAgent.screenshotDirectory));
_screenshotDirectoryGUIContent = new GUIContent(
s_screenshotDirectoryPath,
s_screenshotDirectoryPathTooltip
);

_screenshotDefaultFilenamePrefixProp =
serializedObject.FindProperty(nameof(UGUIMonkeyAgent.defaultScreenshotFilenamePrefix));
_screenshotDefaultFilenamePrefixGUIContent = new GUIContent(
s_screenshotDefaultFilenamePrefix,
s_screenshotDefaultFilenamePrefixTooltip
);
_screenshotFilenamePrefixProp =
serializedObject.FindProperty(nameof(UGUIMonkeyAgent.screenshotFilenamePrefix));
_screenshotFilenamePrefixGUIContent = new GUIContent(
s_screenshotFilenamePrefix,
s_screenshotFilenamePrefixTooltip
);

_screenshotSuperSizeProp = serializedObject.FindProperty(nameof(UGUIMonkeyAgent.screenshotSuperSize));
_screenshotSuperSizeGUIContent = new GUIContent(s_screenshotSuperSize, s_screenshotSuperSizeTooltip);
_screenshotSuperSizeGUIContentDisabled = new GUIContent(DefaultSuperSize.ToString());

_screenshotStereoCaptureModeProp =
serializedObject.FindProperty(nameof(UGUIMonkeyAgent.screenshotStereoCaptureMode));
_screenshotStereoCaptureModeGUIContent = new GUIContent(
s_screenshotStereoCaptureMode,
s_screenshotStereoCaptureModeTooltip
);
_screenshotStereoCaptureModeGUIContentDisabled = new GUIContent(
DefaultStereoScreenCaptureMode.ToString(),
s_screenshotStereoCaptureModeTooltip
);
}


Expand All @@ -177,8 +280,89 @@ public override void OnInspectorGUI()
EditorGUILayout.PropertyField(_touchAndHoldDelayMillisProp, _touchAndHoldDelayMillisGUIContent);
EditorGUILayout.PropertyField(_gizmosProp, _gizmosGUIContent);
_randomStringParamsMapList.DoLayoutList();
EditorGUILayout.LabelField(s_screenshotOptions, EditorStyles.boldLabel);
using (new EditorGUI.IndentLevelScope())
{
EditorGUILayout.PropertyField(_screenshotEnabledProp, _screenshotEnabledGUIContent);
if (_screenshotEnabledProp.boolValue)
{
EditorGUILayout.LabelField(s_screenshotDirectory, EditorStyles.boldLabel);
using (new EditorGUI.IndentLevelScope())
{
EditorGUILayout.PropertyField(
_screenshotDefaultDirectoryProp,
_screenshotDefaultDirectoryGUIContent
);
if (!_screenshotDefaultDirectoryProp.boolValue)
{
EditorGUILayout.PropertyField(_screenshotDirectoryProp, _screenshotDirectoryGUIContent);
}
}

EditorGUILayout.LabelField(s_screenshotFilename, EditorStyles.boldLabel);
using (new EditorGUI.IndentLevelScope())
{
EditorGUILayout.PropertyField(
_screenshotDefaultFilenamePrefixProp,
_screenshotDefaultFilenamePrefixGUIContent
);
if (!_screenshotDefaultFilenamePrefixProp.boolValue)
{
EditorGUILayout.PropertyField(
_screenshotFilenamePrefixProp,
_screenshotFilenamePrefixGUIContent
);
}
}

var screenCaptureMode =
(ScreenCapture.StereoScreenCaptureMode)_screenshotStereoCaptureModeProp.enumValueIndex;
if (screenCaptureMode == DefaultStereoScreenCaptureMode)
{
_screenshotSuperSizeProp.intValue = EditorGUILayout.IntSlider(
_screenshotSuperSizeGUIContent,
_screenshotSuperSizeProp.intValue,
1,
100
);
}
else
{
EditorGUILayout.LabelField(
_screenshotSuperSizeGUIContent,
_screenshotSuperSizeGUIContentDisabled
);
}

if (_screenshotSuperSizeProp.intValue == DefaultSuperSize)
{
var screenshotStereoCaptureMode =
(ScreenCapture.StereoScreenCaptureMode)EditorGUILayout.EnumPopup(
_screenshotStereoCaptureModeGUIContent,
(ScreenCapture.StereoScreenCaptureMode)_screenshotStereoCaptureModeProp
.enumValueIndex
);
_screenshotStereoCaptureModeProp.enumValueIndex = Clamp(
(int)screenshotStereoCaptureMode,
1,
3
);
}
else
{
EditorGUILayout.LabelField(
_screenshotStereoCaptureModeGUIContent,
_screenshotStereoCaptureModeGUIContentDisabled
);
}
}
}

serializedObject.ApplyModifiedProperties();
}


// XXX: Fallback for Unity 2019.x
private static int Clamp(int value, int min, int max) => value < min ? min : max < value ? max : value;
}
}
38 changes: 37 additions & 1 deletion Runtime/Agents/UGUIMonkeyAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,33 @@ public class UGUIMonkeyAgent : AbstractAgent
public List<RandomStringParametersEntry> randomStringParametersMap =
new List<RandomStringParametersEntry>();

/// <summary>
/// Whether screenshot is enabled
/// </summary>
public bool screenshotEnabled;

/// <summary>
/// Whether using a default directory or specifying manually
/// </summary>
public bool defaultScreenshotDirectory = true;

/// <inheritdoc cref="ScreenshotOptions.Directory" />
public string screenshotDirectory;

/// <summary>
/// Whether using a default file name prefix or specifying manually
/// </summary>
public bool defaultScreenshotFilenamePrefix = true;

/// <inheritdoc cref="ScreenshotOptions.FilenamePrefix" />
public string screenshotFilenamePrefix;

/// <inheritdoc cref="ScreenshotOptions.SuperSize" />
public int screenshotSuperSize = 1;

/// <inheritdoc cref="ScreenshotOptions.StereoCaptureMode" />
public ScreenCapture.StereoScreenCaptureMode screenshotStereoCaptureMode =
ScreenCapture.StereoScreenCaptureMode.LeftEye;

/// <inheritdoc />
public override async UniTask Run(CancellationToken token)
Expand All @@ -72,7 +99,16 @@ public override async UniTask Run(CancellationToken token)
RandomStringParametersStrategy = GetRandomStringParameters,
SecondsToErrorForNoInteractiveComponent = secondsToErrorForNoInteractiveComponent,
TouchAndHoldDelayMillis = touchAndHoldDelayMillis,
Gizmos = gizmos
Gizmos = gizmos,
Screenshots = screenshotEnabled
? new ScreenshotOptions
{
Directory = defaultScreenshotDirectory ? null : screenshotDirectory,
FilenamePrefix = defaultScreenshotFilenamePrefix ? null : screenshotFilenamePrefix,
SuperSize = screenshotSuperSize,
StereoCaptureMode = screenshotStereoCaptureMode
}
: null
};
await Monkey.Run(config, token);

Expand Down

0 comments on commit 50dc5e4

Please sign in to comment.