This repository has been archived by the owner on Mar 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIMGUIMenuDemo.cs
executable file
·93 lines (76 loc) · 2.44 KB
/
IMGUIMenuDemo.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
using System;
using System.Collections;
using System.Collections.Generic;
using Mirror;
using Scripts.CustomServer;
using Scripts.Matchmaker;
using UnityEngine;
[RequireComponent(typeof(Client))]
public class IMGUIMenuDemo : MonoBehaviour, IMatchmaker
{
private List<string> ServerList = new();
public static bool CreatePublic;
private string connectText;
private void Start()
{
IMatchmaker.listClient = gameObject.GetComponent<Client>();
}
private void Refresh()
{
IMatchmaker.Connect();
var x = IMatchmaker.GetAllLobbyIdsByAttribute("public", "True");
foreach (var y in x)
{
ServerList.Add(IMatchmaker.GetLobbyAttribute(y, "_auto_ip"));
}
IMatchmaker.Disconnect();
}
private void OnGUI()
{
GUI.Box(new Rect(10, 10, 200, 500), "Connection Manager");
connectText = GUI.TextField(new Rect(30, 30, 160, 20), connectText);
if (GUI.Button(new Rect(30, 60, 160, 20), "Connect"))
{
// Check if it is an IP
NetworkManager.singleton.networkAddress = connectText;
NetworkManager.singleton.StartClient();
// Otherwise
IMatchmaker.Connect();
var uuidLobby = IMatchmaker.GetLobbyIdByUuid(connectText);
var address = "";
if (uuidLobby > 0)
{
NetworkManager.singleton.networkAddress = IMatchmaker.GetLobbyAttribute(uuidLobby, "_auto_uuid");
IMatchmaker.Disconnect();
NetworkManager.singleton.StartClient();
}
else
{
IMatchmaker.Disconnect();
}
}
if (GUI.Button(new Rect(30, 100, 160, 20), "Start Host (Public)"))
{
CreatePublic = true;
NetworkManager.singleton.StartHost();
}
if (GUI.Button(new Rect(30, 130, 160, 20), "Start Host (Private)"))
{
CreatePublic = false;
NetworkManager.singleton.StartHost();
}
if (GUI.Button(new Rect(30, 170, 160, 20), "Refresh"))
{
Refresh();
}
int yPos = 200;
foreach (var x in ServerList)
{
if(GUI.Button(new Rect(30, yPos+=30, 160, 20), x))
{
NetworkManager.singleton.networkAddress = x;
NetworkManager.singleton.StartClient();
}
}
}
}