Skip to content

Commit

Permalink
Add GameView resolution command line arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
nowsprinting committed Nov 25, 2024
1 parent b9439ae commit ae84f0d
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 15 deletions.
23 changes: 11 additions & 12 deletions Editor/Commandline.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright (c) 2023 DeNA Co., Ltd.
// Copyright (c) 2023-2024 DeNA Co., Ltd.
// This software is released under the MIT License.

using System.Reflection;
using DeNA.Anjin.Settings;
using TestHelper.RuntimeInternals;
using UnityEditor;
using UnityEditor.SceneManagement;
using UnityEngine;
Expand Down Expand Up @@ -49,12 +49,12 @@ 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;

// GameView resolution set and show window even in batchmode. It can bypass batchmode limitations. e.g., WaitForEndOfFrame.
SetGameViewResolution();

// Activate autopilot and enter play mode
var state = AutopilotState.Instance;
state.launchFrom = LaunchType.Commandline;
Expand Down Expand Up @@ -85,14 +85,13 @@ private static string GetAutopilotSettingsFromArguments()
return args.AutopilotSettings.Value();
}

private static void FocusGameView()
private static void SetGameViewResolution()
{
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);
var args = new Arguments();
var width = (uint)args.GameViewWidth.Value();
var height = (uint)args.GameViewHeight.Value();
var name = $"{width}x{height}";
GameViewControlHelper.SetResolution(width, height, name);
}
}
}
6 changes: 3 additions & 3 deletions Editor/DeNA.Anjin.Editor.asmdef
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"references": [
"UniTask",
"DeNA.Anjin",
"TestHelper.Monkey.Annotations",
"TestHelper.Monkey"
"TestHelper.RuntimeInternals",
"TestHelper.Monkey.Annotations"
],
"includePlatforms": [
"Editor"
Expand All @@ -18,4 +18,4 @@
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}
}
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ For details on each argument, see the entry of the same name in the "Generate an
<dt>TIME_SCALE</dt><dd>Specifies the Time.timeScale. Default is 1.0</dd>
<dt>OUTPUT_ROOT_DIRECTORY_PATH</dt><dd>Output files root directory path used by Agents, Loggers, and Reporters.</dd>
<dt>SCREENSHOTS_DIRECTORY_PATH</dt><dd>Screenshots output directory path used by Agents.</dd>
<dt>GAME_VIEW_WIDTH</dt><dd>Set GameView width. This argument is only used to launch in editor from command line. Default is 640.</dd>
<dt>GAME_VIEW_HEIGHT</dt><dd>Set GameView height. This argument is only used to launch in editor from command line. Default is 480.</dd>
</dl>

In both cases, the key should be prefixed with `-` and specified as `-LIFESPAN_SEC 60`.
Expand Down
2 changes: 2 additions & 0 deletions README_ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ $(UNITY) \
<dt>TIME_SCALE</dt><dd>Time.timeScaleを指定します。デフォルトは1.0</dd>
<dt>OUTPUT_ROOT_DIRECTORY_PATH</dt><dd>Agent、Logger、および Reporter が出力するファイルのルートディレクトリパスを指定します</dd>
<dt>SCREENSHOTS_DIRECTORY_PATH</dt><dd>Agent が撮影するスクリーンショットの出力ディレクトリパスを指定します</dd>
<dt>GAME_VIEW_WIDTH</dt><dd>GameView の幅を設定します。この引数は、コマンド ラインからエディターを起動する場合にのみ使用されます。デフォルト値は 640 です</dd>
<dt>GAME_VIEW_HEIGHT</dt><dd>GameView の高さを設定します。この引数は、コマンド ラインからエディターを起動する場合にのみ使用されます。デフォルト値は 480 です</dd>
</dl>

いずれも、キーの先頭に`-`を付けて`-LIFESPAN_SEC 60`のように指定してください。
Expand Down
12 changes: 12 additions & 0 deletions Runtime/Settings/Arguments.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,5 +104,17 @@ public class Arguments
/// <see href="https://api.slack.com/web"/>
/// </summary>
public virtual IArgument<string> SlackChannels => new Argument<string>("SLACK_CHANNELS");

/// <summary>
/// <c>GameView</c> width.
/// This argument is only used to launch in editor from command line.
/// </summary>
public virtual IArgument<int> GameViewWidth => new Argument<int>("GAME_VIEW_WIDTH", 640);

/// <summary>
/// <c>GameView</c> height.
/// This argument is only used to launch in editor from command line.
/// </summary>
public virtual IArgument<int> GameViewHeight => new Argument<int>("GAME_VIEW_HEIGHT", 480);
}
}

0 comments on commit ae84f0d

Please sign in to comment.