Skip to content

Commit

Permalink
Merge pull request #38 from nowsprinting/feature/screenshots
Browse files Browse the repository at this point in the history
Enable screenshots
  • Loading branch information
Kuniwak authored Apr 2, 2024
2 parents 7fbcdeb + 1fce741 commit 17dad43
Show file tree
Hide file tree
Showing 7 changed files with 323 additions and 5 deletions.
66 changes: 66 additions & 0 deletions Editor/Localization/ja.po
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,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 specified by command line argument \"-testHelperScreenshotDirectory\". If the command line argument is also omitted, Application.persistentDataPath + \"/TestHelper/Screenshots/\" is used."
msgstr "スクリーンショットの保存先のディレクトリ名にデフォルト値を使用します。デフォルト値はコマンドライン引数 \"-testHelperScreenshotDirectory\" で指定します。コマンドライン引数も省略した場合は、Application.persistentDataPath + \"/TestHelper/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 agent name"
msgstr "スクリーンショットのファイル名のプレフィックスにデフォルト値を使用します。デフォルト値はAgentの名前です"

# 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
186 changes: 185 additions & 1 deletion Editor/UI/Agents/UGUIMonkeyAgentEditor.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2023 DeNA Co., Ltd.
// Copyright (c) 2023-2024 DeNA Co., Ltd.
// This software is released under the MIT License.

using System.Diagnostics.CodeAnalysis;
Expand Down 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 specified by command line argument ""-testHelperScreenshotDirectory"". If the command line argument is also omitted, Application.persistentDataPath + ""/TestHelper/Screenshots/"" is used."
);

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 agent 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;
}
}
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ define test_arguments
-runTests \
-testCategory "!IgnoreCI" \
-testPlatform $(TEST_PLATFORM) \
-testResults $(LOG_DIR)/test_$(TEST_PLATFORM)_results.xml
-testResults $(LOG_DIR)/test_$(TEST_PLATFORM)_results.xml \
-testHelperScreenshotDirectory $(LOG_DIR)/Screenshots
endef

define test
Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,16 @@ An instance of this Agent (.asset file) can contain the following.
<dt>Enable Gizmos</dt><dd>Show Gizmos on GameView during running monkey test if true</dd>
</dl>

#### *Screenshot Options:*

<dl>
<dt>Enabled</dt><dd>Whether screenshot is enabled or not</dd>
<dt>Directory</dt><dd><b>Use Default: </b>Whether using a default directory path to save screenshots or specifying it manually. Default value is specified by command line argument "-testHelperScreenshotDirectory". If the command line argument is also omitted, Application.persistentDataPath + "/TestHelper/Screenshots/" is used.<br><b>Path: </b>Directory path to save screenshots</dd>
<dt>Filename</dt><dd><b>Use Default: </b>Whether using a default prefix of screenshots filename or specifying it manually. Default value is agent name<br><b>Prefix: </b>Prefix of screenshots filename</dd>
<dt>Super Size</dt><dd>The factor to increase resolution with. Neither this nor Stereo Capture Mode can be specified</dd>
<dt>Stereo Capture Mode</dt><dd>The eye texture to capture when stereo rendering is enabled. Neither this nor Resolution Factor can be specified</dd>
</dl>

If you have a `GameObject` that you want to avoid manipulation by the `UGUIMonkeyAgent`,
attach the `IgnoreAnnotation` component in the `TestHelper.Monkey.Annotations` assembly.
See **Anjin Annotations** below for more information.
Expand Down
10 changes: 10 additions & 0 deletions README_ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,16 @@ uGUIのコンポーネントをランダムに操作するAgentです。
<dt>Gizmo</dt><dd>もし有効ならモンキー操作中の GameView に Gizmo を表示します。もし無効なら GameView に Gizmo を表示しません</dd>
</dl>

#### *スクリーンショット設定:*

<dl>
<dt>有効</dt><dd>スクリーンショット撮影を有効にします</dd>
<dt>ディレクトリ</dt><dd><b>デフォルト値を使用: </b>スクリーンショットの保存先のディレクトリ名にデフォルト値を使用します。デフォルト値はコマンドライン引数 "-testHelperScreenshotDirectory" で指定します。コマンドライン引数も省略した場合は、Application.persistentDataPath + "/TestHelper/Screenshots/" が使用されます<br><b>パス: </b>スクリーンショットの保存先ディレクトリのパス</dd>
<dt>ファイル名</dt><dd><b>デフォルト値を使用: </b>スクリーンショットのファイル名のプレフィックスにデフォルト値を使用します。デフォルト値はAgentの名前です<br><b>プレフィックス: </b>スクリーンショットのファイル名のプレフィックスを指定します</dd>
<dt>拡大係数</dt><dd>解像度をあげるための係数。ステレオキャプチャモードと同時には設定できません</dd>
<dt>ステレオキャプチャモード</dt><dd>ステレオレンダリングが有効な場合にどちらのカメラを使用するかを指定できます。拡大係数と同時には設定できません</dd>
</dl>

`UGUIMonkeyAgent` によって操作されたくない `GameObject` がある場合、
`TestHelper.Monkey.Annotations` アセンブリに含まれる `IgnoreAnnotation` コンポーネントをアタッチしておくことで操作を回避できます。
詳しくは後述の**Anjin Annotations**を参照してください。
Expand Down
Loading

0 comments on commit 17dad43

Please sign in to comment.