-
Notifications
You must be signed in to change notification settings - Fork 461
Expand file tree
/
Copy pathCommandLineOptions.cs
More file actions
62 lines (59 loc) · 2.13 KB
/
CommandLineOptions.cs
File metadata and controls
62 lines (59 loc) · 2.13 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
using System;
using System.Collections.Generic;
using UnityEngine;
namespace Unity.Netcode
{
/// <summary>
/// This class contains a list of the application instance domain's command line arguments that
/// are used when entering PlayMode or the build is executed.
/// </summary>
public class CommandLineOptions
{
/// <summary>
/// Command-line options singleton
/// </summary>
public static CommandLineOptions Instance
{
get
{
if (s_Instance == null)
{
s_Instance = new CommandLineOptions();
}
return s_Instance;
}
private set
{
s_Instance = value;
}
}
private static CommandLineOptions s_Instance;
// Contains the current application instance domain's command line arguments
private static List<string> s_CommandLineArguments = new List<string>(Environment.GetCommandLineArgs());
#if UNITY_EDITOR
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
private static void ResetStaticsOnLoad()
{
Instance = new CommandLineOptions();
s_Instance = new CommandLineOptions();
// Get all the command line arguments to be parsed later and/or modified
// prior to being parsed (for testing purposes).
s_CommandLineArguments = new List<string>(Environment.GetCommandLineArgs());
}
#endif
/// <summary>
/// Returns the value of an argument or null if the argument is not present
/// </summary>
/// <param name="arg">The name of the argument</param>
/// <returns><see cref="string"/>Value of the command line argument passed in.</returns>
public string GetArg(string arg)
{
var argIndex = s_CommandLineArguments.IndexOf(arg);
if (argIndex >= 0 && argIndex < s_CommandLineArguments.Count - 1)
{
return s_CommandLineArguments[argIndex + 1];
}
return null;
}
}
}