TheKingsRace/Assets/Scripts/Network/Preloader.cs
Julia Butenhoff db5b10ef47 Rewrote Networking and Base Lobby Created
- Rewrote networking based on tutorials from MLAPI Demo Project and
  Dapper Dino
- Created Lobby UI based on the turorial from Dapper Dino
- Linked Existing UI into using the new networking
- Modified Lobby Settings to only allow 3 players
- Added Field for players to enter their player name
2021-10-15 16:01:18 -05:00

50 lines
1.5 KiB
C#

using System.Collections.Generic;
using MLAPI;
using MLAPI.SceneManagement;
using UnityEngine;
using UnityEngine.SceneManagement;
public class Preloader : MonoBehaviour {
void Start() {
if (Application.isEditor) {
// Swap to Title Screen (as client) while in the editor
SceneManager.LoadScene(1);
}
var args = GetCommandlineArgs();
// Check for the dedicated server command flags
if (args.TryGetValue("-mlapi", out string mlapiValue)) {
if (mlapiValue == "server") {
// Start the server
NetworkManager.Singleton.StartServer();
// Swap to the lobby scene to await players
NetworkSceneManager.SwitchScene("Lobby");
}
} else {
// If not command line arguments
// Swap to Title Screen (as client)
SceneManager.LoadScene(1);
}
}
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;
}
}