44 lines
1.6 KiB
C#
44 lines
1.6 KiB
C#
using System;
|
|
using System.Collections;
|
|
using UnityEngine;
|
|
|
|
public class canvasChooser : MonoBehaviour
|
|
{
|
|
public GameObject serverStartCanvas;
|
|
public GameObject clientStartCanvas;
|
|
public GameObject mainCamera;
|
|
|
|
private IEnumerator Start()
|
|
{
|
|
string[] args = Environment.GetCommandLineArgs();
|
|
bool server = Array.IndexOf(args, "--server") >= 0;
|
|
serverStartCanvas.SetActive(server);
|
|
clientStartCanvas.SetActive(!server);
|
|
mainCamera.SetActive(!server);
|
|
|
|
// Let the scene finish starting before UNet activates its scene objects.
|
|
yield return null;
|
|
if (server)
|
|
{
|
|
serverStartMenu menu = serverStartCanvas.GetComponent<serverStartMenu>();
|
|
string trafficUrl = Argument(args, "--traffic-url");
|
|
string eventUrl = Argument(args, "--event-url");
|
|
if (trafficUrl != null) menu.trafficAddress.text = trafficUrl.TrimEnd('/');
|
|
if (eventUrl != null) menu.eventAddress.text = eventUrl.TrimEnd('/');
|
|
menu.createServer();
|
|
Debug.Log("Simulation server started on port " + menu.network.networkPort);
|
|
}
|
|
else
|
|
{
|
|
string address = Argument(args, "--connect");
|
|
if (address != null)
|
|
clientStartCanvas.GetComponent<clientMenu>().joinServer(address);
|
|
}
|
|
}
|
|
|
|
private static string Argument(string[] args, string name)
|
|
{
|
|
int index = Array.IndexOf(args, name);
|
|
return index >= 0 && index + 1 < args.Length ? args[index + 1] : null;
|
|
}
|
|
}
|