-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSceneSelector.cs
More file actions
66 lines (54 loc) · 1.82 KB
/
SceneSelector.cs
File metadata and controls
66 lines (54 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Copyright 2025 U.S. Federal Government (in countries where recognized)
// Copyright 2025 Dakota Crouchelli dakota.h.crouchelli.civ@us.navy.mil
using System;
using System.Collections;
using UnityEngine;
using UnityEngine.SceneManagement;
namespace CREATIVE.Utility
{
/**
A script used to load different scenes.
If LoadSceneImmediately is checked on the Awake call, the script checks
for a --scene flag on the command line (followed by the name of a scene)
and loads it.
If LoadSceneImmediately is checked, but a --scene flag is not found,
The scene with the name stored in DefaultScene is loaded.
If LoadSceneImmediately is not checked, nothing will happen on Awake,
and the script will wait for LoadScene to be called.
*/
public class SceneSelector : MonoBehaviour
{
[field: SerializeField]
private bool LoadSceneImmediately = false;
/**
The name of the scene to open if no scene is specified.
*/
[field: SerializeField]
private string DefaultScene;
void Awake()
{
if (LoadSceneImmediately)
{
string[] args = System.Environment.GetCommandLineArgs();
bool loaded = false;
for (int i=0; i<args.Length; i++)
{
if (args[i].Equals("--scene"))
{
if ((i+1)==args.Length || args[i+1].StartsWith("-"))
throw new InvalidOperationException
("\"scene\" flag was provided on the command line, but no scene was specified.");
loaded = true;
if (args[i+1].Equals(SceneManager.GetActiveScene().name))
SceneManager.LoadScene(DefaultScene);
else
SceneManager.LoadScene(args[i+1]);
}
}
if (loaded == false)
SceneManager.LoadScene(DefaultScene);
}
}
public void LoadScene(string sceneName) => SceneManager.LoadScene(sceneName);
}
}