quakeball/Assets/Scripts/Net/CanvasInput.cs
2020-08-05 04:21:04 +03:00

41 lines
1.1 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using NeonTea.Quakeball.Net.Peers;
namespace NeonTea.Quakeball.Net {
public class CanvasInput : MonoBehaviour, PeerMessageListener {
public Button Host;
public Button Join;
public Button Stop;
public InputField HostAddr;
public InputField Port;
public Text TextField;
private static List<string> Stuff = new List<string>();
void Start() {
Host.onClick.AddListener(() => {
Net.Singleton.StartServer("0.0.0.0", 8080, this);
});
Join.onClick.AddListener(() => {
Net.Singleton.StartClient("127.0.0.1", 8080, this);
});
Stop.onClick.AddListener(() => {
Net.Singleton.Stop();
});
}
void Update() {
TextField.text = string.Join("\n", Stuff.ToArray());
}
public void Message(string text) {
Stuff.Add(text);
Debug.Log(string.Join(", ", Stuff.ToArray()));
}
}
}