Skip to content

Commit

Permalink
Merge pull request #34 from nowsprinting/feature/support_batchmode
Browse files Browse the repository at this point in the history
Support run on batchmode
  • Loading branch information
Kuniwak authored Mar 13, 2024
2 parents 4238b45 + cab2e15 commit af3e0e0
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 9 deletions.
14 changes: 14 additions & 0 deletions Editor/Commandline.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// This software is released under the MIT License.

using System.Diagnostics.CodeAnalysis;
using System.Reflection;
using DeNA.Anjin.Settings;
using UnityEditor;
using UnityEditor.SceneManagement;
Expand Down Expand Up @@ -49,6 +50,9 @@ private static void Bootstrap()
return;
}

// Show GameView window even in batchmode. It can bypass batchmode limitations. e.g., WaitForEndOfFrame.
FocusGameView();

// Set first open Scene
EditorSceneManager.playModeStartScene = myWantedStartScene;

Expand Down Expand Up @@ -84,5 +88,15 @@ private static string GetAutopilotSettingsFromArguments()

return args.AutopilotSettings.Value();
}

private static void FocusGameView()
{
var assembly = Assembly.Load("UnityEditor.dll");
var viewClass = Application.isBatchMode
? "UnityEditor.GameView"
: "UnityEditor.PlayModeView";
var gameView = assembly.GetType(viewClass);
EditorWindow.GetWindow(gameView, false, null, true);
}
}
}
18 changes: 14 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ It is **NOT** set to `DontDestroyOnLoad`.

#### Autopilot Run Settings

This item can also be overridden from the command line (see below).
This item can also be overridden from the commandline (see below).

<dl>
<dt>Lifespan</dt><dd>Specifies the execution time limit in seconds. Defaults to 300 seconds, 0 specifies unlimited operation</dd>
Expand Down Expand Up @@ -176,14 +176,15 @@ To execute from the commandline, specify the following arguments.
```bash
$(UNITY) \
-projectPath $(PROJECT_HOME) \
-batchmode \
-executeMethod DeNA.Anjin.Editor.Commandline.Bootstrap \
-AUTOPILOT_SETTINGS Assets/Path/To/AutopilotSettings.asset
```

- `UNITY` is the path to the Unity editor, and `PROJECT_HOME` is the root of the project to be autorun.
- `-AUTOPILOT_SETTINGS` is the path to the settings file (AutopilotSettings) you want to run.
- Do not specify `-quit` (it will exit without entering play mode).
- `-batchmode` will not work with the PlaybackAgent and MonkeyAgent in games that use uGUI.
- Do not specify `-nographics` (do not show GameView window).

In addition, some settings can be overridden by adding the following arguments.
For details on each argument, see the entry of the same name in the "Generate and configure the AutopilotSettings.asset file" mentioned above.
Expand Down Expand Up @@ -425,8 +426,17 @@ Run the command below:
git submodule add https://github.com/dena/Anjin.git Packages/com.dena.anjin
```

> **Note**
> Required install [Unity Test Framework](https://docs.unity3d.com/Packages/com.unity.test-framework@latest) package v1.3 or later for running tests.
> [!WARNING]
> Required install packages for running tests (when adding to the `testables` in package.json), as follows:
> - [Unity Test Framework](https://docs.unity3d.com/Packages/com.unity.test-framework@latest) package v1.3.4 or later
> - [Test Helper](https://github.com/nowsprinting/test-helper) package v0.4.2 or later
Generate a temporary project and run tests on each Unity version from the command line.

```bash
make create_project
UNITY_VERSION=2019.4.40f1 make -k test
```


## Release workflow
Expand Down
16 changes: 13 additions & 3 deletions README_ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ Slack通知に付与するメンションを設定します。
```bash
$(UNITY) \
-projectPath $(PROJECT_HOME) \
-batchmode \
-executeMethod DeNA.Anjin.Editor.Commandline.Bootstrap \
-AUTOPILOT_SETTINGS Assets/Path/To/AutopilotSettings.asset
```
Expand All @@ -184,7 +185,7 @@ $(UNITY) \
- `UNITY`にはUnityエディタへのパス、`PROJECT_HOME`には自動実行対象プロジェクトのルートを指定します
- `-AUTOPILOT_SETTINGS` には、実行したい設定ファイル(AutopilotSettings)のパスを指定します
- `-quit` は指定しないでください(Play modeに入らず終了してしまいます)
- `-batchmode` ではuGUIを使用しているゲームでは、PlaybackAgentおよびMonkeyAgentが動作しません
- `-nographics` は指定しないでください(GameViewウィンドウを表示できません)

また、以下の引数を追加することで一部の設定を上書きできます。
各引数の詳細は前述の「オートパイロット設定ファイル」の同名項目を参照してください。
Expand Down Expand Up @@ -429,8 +430,17 @@ Pull requestには `enhancement`, `bug`, `chore`, `documentation` といった
git submodule add https://github.com/dena/Anjin.git Packages/com.dena.anjin
```

> **Note**
> Anjinパッケージ内のテストを実行するために、[Unity Test Framework](https://docs.unity3d.com/Packages/com.unity.test-framework@latest) パッケージ v1.3以上が必要です。
> [!WARNING]
> Anjinパッケージ内のテストを実行するためには、次のパッケージのインストールが必要です。
> - [Unity Test Framework](https://docs.unity3d.com/Packages/com.unity.test-framework@latest) package v1.3.4 or later
> - [Test Helper](https://github.com/nowsprinting/test-helper) package v0.4.2 or later
テスト専用のUnityプロジェクトを生成し、Unityバージョンを指定してテストを実行するには、次のコマンドを実行します。

```bash
make create_project
UNITY_VERSION=2019.4.40f1 make -k test
```


## リリースワークフロー
Expand Down
2 changes: 1 addition & 1 deletion Runtime/Reporters/SlackMessageSender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public async UniTask Send(
return;
}

if (withScreenshot && !Application.isBatchMode)
if (withScreenshot)
{
var coroutineRunner = new GameObject().AddComponent<CoroutineRunner>();
await UniTask.WaitForEndOfFrame(coroutineRunner);
Expand Down
3 changes: 2 additions & 1 deletion Tests/Runtime/DeNA.Anjin.Tests.asmdef
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"DeNA.Anjin",
"DeNA.Anjin.Annotations",
"UniTask",
"DeNA.Anjin.Editor"
"DeNA.Anjin.Editor",
"TestHelper"
],
"includePlatforms": [],
"excludePlatforms": [],
Expand Down
2 changes: 2 additions & 0 deletions Tests/Runtime/Reporters/SlackMessageSenderTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Threading.Tasks;
using DeNA.Anjin.TestDoubles;
using NUnit.Framework;
using TestHelper.Attributes;

namespace DeNA.Anjin.Reporters
{
Expand Down Expand Up @@ -83,6 +84,7 @@ await sender.Send(
}

[Test]
[FocusGameView]
public async Task WithScreenshot()
{
var spySlackAPI = new SpySlackAPI();
Expand Down

0 comments on commit af3e0e0

Please sign in to comment.