2020-08-05 18:50:28 +02:00
|
|
|
|
using System.Collections.Generic;
|
2020-08-02 02:50:01 +02:00
|
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEngine.UI;
|
2020-08-05 18:50:28 +02:00
|
|
|
|
using NeonTea.Quakeball.TeaNet.Peers;
|
|
|
|
|
using NeonTea.Quakeball.Net.Packets;
|
|
|
|
|
using System;
|
2020-08-02 02:50:01 +02:00
|
|
|
|
|
|
|
|
|
namespace NeonTea.Quakeball.Net {
|
2020-08-05 03:21:04 +02:00
|
|
|
|
public class CanvasInput : MonoBehaviour, PeerMessageListener {
|
2020-08-02 02:50:01 +02:00
|
|
|
|
public Button Host;
|
|
|
|
|
public Button Join;
|
2020-08-05 03:21:04 +02:00
|
|
|
|
public Button Stop;
|
2020-08-05 18:50:28 +02:00
|
|
|
|
public Button Send;
|
2020-08-02 02:50:01 +02:00
|
|
|
|
public InputField HostAddr;
|
|
|
|
|
public InputField Port;
|
2020-08-05 18:50:28 +02:00
|
|
|
|
public InputField MessageField;
|
2020-08-05 03:21:04 +02:00
|
|
|
|
public Text TextField;
|
|
|
|
|
|
|
|
|
|
private static List<string> Stuff = new List<string>();
|
2020-08-02 02:50:01 +02:00
|
|
|
|
|
|
|
|
|
void Start() {
|
|
|
|
|
Host.onClick.AddListener(() => {
|
2020-08-05 18:50:28 +02:00
|
|
|
|
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);
|
2020-08-02 02:50:01 +02:00
|
|
|
|
});
|
|
|
|
|
Join.onClick.AddListener(() => {
|
2020-08-05 18:50:28 +02:00
|
|
|
|
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);
|
2020-08-02 02:50:01 +02:00
|
|
|
|
});
|
2020-08-05 03:21:04 +02:00
|
|
|
|
Stop.onClick.AddListener(() => {
|
|
|
|
|
Net.Singleton.Stop();
|
|
|
|
|
});
|
2020-08-05 18:50:28 +02:00
|
|
|
|
Send.onClick.AddListener(() => {
|
|
|
|
|
if (Net.Singleton.Peer != null && Net.Singleton.Connections.Count > 0) {
|
|
|
|
|
HelloPckt pckt = new HelloPckt();
|
|
|
|
|
pckt.Text = MessageField.text;
|
|
|
|
|
Net.Singleton.Peer.SendReliable(Net.Singleton.Connections[0], pckt);
|
|
|
|
|
}
|
|
|
|
|
});
|
2020-08-05 03:21:04 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Update() {
|
|
|
|
|
TextField.text = string.Join("\n", Stuff.ToArray());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Message(string text) {
|
|
|
|
|
Stuff.Add(text);
|
2020-08-05 18:50:28 +02:00
|
|
|
|
Debug.Log(text);
|
2020-08-02 02:50:01 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|