mirror of
https://github.com/Leahnaya/TheKingsRace.git
synced 2026-03-22 01:34:22 -05:00
- 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
50 lines
1.5 KiB
C#
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;
|
|
}
|
|
}
|