using System.Collections;
using System.Collections.Generic;
using EODE.Wonderland.SimpleNet;
using UnityEngine;
using UnityEngine.UI;
publicclassLanTest : MonoBehaviour {
publicbool IsClient = false;
asyncvoidStart() {
var ln = new LocalNetwork("LanTest", 9561/* broadcast port */, 9562/* msg port */);
if (IsClient) {
GetComponent<Text>().text = "Client: Searching for server...";
var address = await ln.GetServerAddress();
GetComponent<Text>().text = "Client: Server found at " + address.ToString();
}
else {
await ln.ShareServerAddress();
GetComponent<Text>().text = "Server " + (ln.Started ? "started" : "fail");
}
}
}
Nearby players
using System.Collections;
using System.Linq;
using EODE.Wonderland.SimpleNet;
using UnityEngine;
publicclassTestNearbyPlayers : MonoBehaviour {
public TMPro.TextMeshProUGUI NearbyList;
LocalNetwork _ln;
voidStart() {
_ln = new LocalNetwork("TestNearbyPlayers", 9561, 9562);
_ln.ShareNearbyPlayers(System.Environment.UserName);
StartCoroutine(NearbyCheckRoutine());
}
IEnumerator NearbyCheckRoutine() {
while (true) {
yield return new WaitForSeconds(3.5f);
GetNearbyPlayers();
}
}
asyncvoidGetNearbyPlayers() {
var nps = await _ln.GetNearbyPlayers();
if (nps.Count == 0) {
NearbyList.text = "No nearby players found";
}
else {
NearbyList.text = string.Join("\n", nps.Select(p => p.Name + " (" + p.Address + ")"));
}
}
}