quakeball/Assets/Scripts/Net/CanvasInput.cs

41 lines
1.1 KiB
C#
Raw Normal View History

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
2020-08-02 20:32:30 +02:00
using NeonTea.Quakeball.Net.Peers;
namespace NeonTea.Quakeball.Net {
2020-08-05 03:21:04 +02:00
public class CanvasInput : MonoBehaviour, PeerMessageListener {
public Button Host;
public Button Join;
2020-08-05 03:21:04 +02:00
public Button Stop;
public InputField HostAddr;
public InputField Port;
2020-08-05 03:21:04 +02:00
public Text TextField;
private static List<string> Stuff = new List<string>();
void Start() {
Host.onClick.AddListener(() => {
2020-08-05 03:21:04 +02:00
Net.Singleton.StartServer("0.0.0.0", 8080, this);
});
Join.onClick.AddListener(() => {
2020-08-05 03:21:04 +02:00
Net.Singleton.StartClient("127.0.0.1", 8080, this);
});
2020-08-05 03:21:04 +02:00
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()));
}
}
}