using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using NeonTea.Quakeball.TeaNet.Peers; using NeonTea.Quakeball.Net.Packets; using System; namespace NeonTea.Quakeball.Net { public class CanvasInput : MonoBehaviour, PeerMessageListener { public Button Host; public Button Join; public Button Stop; public Button Send; public InputField HostAddr; public InputField Port; public InputField MessageField; public Text TextField; private static List Stuff = new List(); void Start() { Host.onClick.AddListener(() => { string addr = String.IsNullOrWhiteSpace(HostAddr.text) ? "0.0.0.0" : HostAddr.text; string port = String.IsNullOrWhiteSpace(Port.text) ? "8080" : Port.text; Debug.Log(addr); Net.Singleton.StartServer(addr, Int32.Parse(port), this); }); Join.onClick.AddListener(() => { string addr = String.IsNullOrWhiteSpace(HostAddr.text) ? "127.0.0.1" : HostAddr.text; string port = String.IsNullOrWhiteSpace(Port.text) ? "8080" : Port.text; Net.Singleton.StartClient(addr, Int32.Parse(port), this); }); Stop.onClick.AddListener(() => { Net.Singleton.Stop(); }); Send.onClick.AddListener(() => { if (Net.Singleton.Peer != null) { foreach (ulong uid in Net.Singleton.Connections) { HelloPckt pckt = new HelloPckt(); pckt.Text = MessageField.text; Net.Singleton.Peer.SendReliableLater(uid, pckt); Net.Singleton.Peer.SendReliable(uid, pckt); } } }); } void Update() { TextField.text = string.Join("\n", Stuff.ToArray()); } public void Message(string text) { Stuff.Add(text); Debug.Log(text); } } }