mirror of
https://github.com/Leahnaya/TheKingsRace.git
synced 2026-03-22 17:54:26 -05:00
- Fixed game launching with command line into Lobby - Game launches into Title screen otherwise - Depreciated two networking scripts
48 lines
1.3 KiB
C#
48 lines
1.3 KiB
C#
using System.Collections.Generic;
|
|
using MLAPI;
|
|
using UnityEngine;
|
|
|
|
public class NetworkCommandLine : MonoBehaviour {
|
|
private NetworkManager netManager;
|
|
|
|
void Start() {
|
|
netManager = GetComponentInParent<NetworkManager>();
|
|
|
|
if (Application.isEditor) return;
|
|
|
|
var args = GetCommandlineArgs();
|
|
|
|
if (args.TryGetValue("-mlapi", out string mlapiValue)) {
|
|
switch (mlapiValue) {
|
|
case "server":
|
|
netManager.StartServer();
|
|
break;
|
|
case "host":
|
|
netManager.StartHost();
|
|
break;
|
|
case "client":
|
|
|
|
netManager.StartClient();
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
private Dictionary<string, string> GetCommandlineArgs() {
|
|
Dictionary<string, string> argDictionary = new Dictionary<string, string>();
|
|
|
|
var args = System.Environment.GetCommandLineArgs();
|
|
|
|
for (int i = 0; i < args.Length; ++i) {
|
|
var arg = args[i].ToLower();
|
|
if (arg.StartsWith("-")) {
|
|
var value = i < args.Length - 1 ? args[i + 1].ToLower() : null;
|
|
value = (value?.StartsWith("-") ?? false) ? null : value;
|
|
|
|
argDictionary.Add(arg, value);
|
|
}
|
|
}
|
|
return argDictionary;
|
|
}
|
|
}
|