Load scene specified in -game argument.

This commit is contained in:
Jean-Baptiste Perrier
2021-05-20 17:21:45 +02:00
parent d7f03d2c7d
commit 66c1201786
2 changed files with 23 additions and 2 deletions

View File

@@ -271,10 +271,14 @@ namespace FlaxEditor
module.OnEndInit();
}
internal void Init(bool isHeadless, bool skipCompile)
private Guid _startupSceneArgument;
internal void Init(bool isHeadless, bool skipCompile, Guid sceneId)
{
Debug.Log("sceneId string : " + JsonSerializer.GetStringID(sceneId));
EnsureState<LoadingState>();
_isHeadlessMode = isHeadless;
_startupSceneArgument = sceneId;
Log("Editor init");
if (isHeadless)
Log("Running in headless mode");
@@ -332,6 +336,17 @@ namespace FlaxEditor
}
// Load scene
// scene cmd line argument
var scene = ContentDatabase.Find(_startupSceneArgument);
if (scene is SceneItem)
{
Editor.Log("Loading scene specified in command line");
Scene.OpenScene(_startupSceneArgument);
return;
}
// if no scene cmd line argument is provided
var startupSceneMode = Options.Options.General.StartupSceneMode;
if (startupSceneMode == GeneralOptions.StartupSceneModes.LastOpened && !ProjectCache.HasCustomData(ProjectDataLastScene))
{

View File

@@ -210,7 +210,7 @@ ManagedEditor::~ManagedEditor()
void ManagedEditor::Init()
{
// Note: editor modules should perform quite fast init, any longer things should be done in async during 'editor splash screen time
void* args[2];
void* args[3];
MClass* mclass = GetClass();
if (mclass == nullptr)
{
@@ -231,6 +231,12 @@ void ManagedEditor::Init()
bool skipCompile = CommandLine::Options.SkipCompile.IsTrue();
args[0] = &isHeadless;
args[1] = &skipCompile;
Guid sceneId;
if (Guid::Parse(CommandLine::Options.Game.GetValue(), sceneId))
{
sceneId = Guid::Empty;
}
args[2] = CommandLine::Options.Game.HasValue() ? &sceneId : nullptr;
initMethod->Invoke(instance, args, &exception);
if (exception)
{