11using System ;
22using System . Collections . Generic ;
3- using UnityEngine ;
43
54namespace Unity . Netcode
65{
@@ -13,22 +12,33 @@ public class CommandLineOptions
1312 /// <summary>
1413 /// Command-line options singleton
1514 /// </summary>
16- public static CommandLineOptions Instance { get ; private set ; }
15+ [ Obsolete ( "Not used anymore replaced by TryGetArg" ) ]
16+ public static CommandLineOptions Instance
17+ {
18+ get
19+ {
20+ if ( s_Instance == null )
21+ {
22+ s_Instance = new CommandLineOptions ( ) ;
23+ }
24+ return s_Instance ;
25+ }
26+ private set
27+ {
28+ s_Instance = value ;
29+ }
30+ }
31+ private static CommandLineOptions s_Instance ;
1732
1833 // Contains the current application instance domain's command line arguments
1934 private static readonly List < string > k_CommandLineArguments = new List < string > ( Environment . GetCommandLineArgs ( ) ) ;
2035
21- [ RuntimeInitializeOnLoadMethod ( RuntimeInitializeLoadType . SubsystemRegistration ) ]
22- private static void InitializeOnLoad ( )
23- {
24- Instance = new CommandLineOptions ( ) ;
25- }
26-
2736 /// <summary>
2837 /// Returns the value of an argument or null if the argument is not present
2938 /// </summary>
3039 /// <param name="arg">The name of the argument</param>
3140 /// <returns><see cref="string"/>Value of the command line argument passed in.</returns>
41+ [ Obsolete ( "Not used anymore replaced by TryGetArg" ) ]
3242 public string GetArg ( string arg )
3343 {
3444 var argIndex = k_CommandLineArguments . IndexOf ( arg ) ;
@@ -38,5 +48,23 @@ public string GetArg(string arg)
3848 }
3949 return null ;
4050 }
51+
52+ /// <summary>
53+ /// Returns true if the argument was found.
54+ /// </summary>
55+ /// <param name="arg">The name of the argument to look up.</param>
56+ /// <param name="argValue">The argument's value, or <see langword="null"/> if not found.</param>
57+ /// <returns><c>true</c> if the argument was found; otherwise <c>false</c>.</returns>
58+ public static bool TryGetArg ( string arg , out string argValue )
59+ {
60+ var argIndex = k_CommandLineArguments . IndexOf ( arg ) ;
61+ if ( argIndex >= 0 && argIndex < k_CommandLineArguments . Count - 1 )
62+ {
63+ argValue = k_CommandLineArguments [ argIndex + 1 ] ;
64+ return true ;
65+ }
66+ argValue = null ;
67+ return false ;
68+ }
4169 }
4270}
0 commit comments