Added MainMenu, Bootstrap and Factory scenes
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
using UnityEngine;
|
||||
|
||||
public sealed class FriendslopMainMenu : MonoBehaviour
|
||||
{
|
||||
private string address = "127.0.0.1";
|
||||
private string portText = "7777";
|
||||
|
||||
private void OnGUI()
|
||||
{
|
||||
var session = FriendslopSession.Instance;
|
||||
GUI.Box(new Rect(24, 24, 380, 285), string.Empty);
|
||||
GUILayout.BeginArea(new Rect(44, 44, 340, 245));
|
||||
GUILayout.Label("FRIENDSLOP // MOUNTAIN FACTORY");
|
||||
GUILayout.Space(10);
|
||||
if (session == null) { GUILayout.Label("Bootstrap is unavailable."); GUILayout.EndArea(); return; }
|
||||
if (session.IsOnline) { GUILayout.Label(session.Status); GUILayout.EndArea(); return; }
|
||||
GUILayout.Label("Host LAN IP");
|
||||
address = GUILayout.TextField(address);
|
||||
GUILayout.Label("Port");
|
||||
portText = GUILayout.TextField(portText);
|
||||
GUILayout.Space(12);
|
||||
if (GUILayout.Button("Start Host", GUILayout.Height(36))) StartHost(session);
|
||||
if (GUILayout.Button("Join Factory", GUILayout.Height(36))) StartClient(session);
|
||||
GUILayout.FlexibleSpace();
|
||||
GUILayout.Label(session.Status);
|
||||
GUILayout.EndArea();
|
||||
}
|
||||
|
||||
private void StartHost(FriendslopSession session)
|
||||
{
|
||||
if (TryReadPort(out ushort port)) session.StartHost(port);
|
||||
else Debug.LogWarning("Friendslop: invalid port.");
|
||||
}
|
||||
|
||||
private void StartClient(FriendslopSession session)
|
||||
{
|
||||
if (TryReadPort(out ushort port) && !string.IsNullOrWhiteSpace(address)) session.StartClient(address, port);
|
||||
else Debug.LogWarning("Friendslop: enter a valid IP and port.");
|
||||
}
|
||||
|
||||
private bool TryReadPort(out ushort port) => ushort.TryParse(portText, out port) && port > 0;
|
||||
}
|
||||
Reference in New Issue
Block a user