Last active
June 12, 2023 14:33
-
-
Save jbvrtx/bd1cc0a376a0346f2ba5cfda19d4cdd8 to your computer and use it in GitHub Desktop.
Read Commandline Arguments and Select Certain Scenes With Them in Unity Editor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class StartupArguments | |
{ | |
// Constants | |
public const string ArgumentVR = "-vr"; | |
// Properties | |
public static bool ContainVRMode => Arguments.Contains(ArgumentVR); | |
public static StartupScene[] ContainedScenes | |
=> StartupScenes.Where(scene => Arguments.Contains(scene.StartupParameterName)).ToArray(); | |
// Properties | |
private static readonly string[] Arguments = Environment.GetCommandLineArgs(); | |
// Cached Properties | |
#region Cached Properties | |
private static StartupScene[] _startupScenes; | |
public static StartupScene[] StartupScenes | |
{ | |
get | |
{ | |
if (_startupScenes == null) | |
{ | |
_startupScenes = Resources.LoadAll<StartupScene>("StartupScenes/"); | |
} | |
return _startupScenes; | |
} | |
} | |
#endregion | |
// Methods | |
public static bool ContainsString(string startupArgument) | |
{ | |
return Arguments.Contains(startupArgument); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
[System.Serializable] | |
[CreateAssetMenu(fileName = "StartupScene", menuName = "ScriptableObjects/StartupScene", order = 1)] | |
public class StartupScene : ScriptableObject | |
{ | |
[SerializeField] | |
private string _sceneName; | |
[SerializeField] | |
private string _startupParameterName; | |
[SerializeField] | |
private Transform _startPosition; | |
public string SceneName => _sceneName; | |
public string StartupParameterName => _startupParameterName; | |
public Transform StartPose => _startPosition; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment