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;
|
2020-08-07 20:20:13 +02:00
|
|
|
|
using NeonTea.Quakeball.Networking.Packets;
|
2020-08-05 18:50:28 +02:00
|
|
|
|
using System;
|
2020-08-02 02:50:01 +02:00
|
|
|
|
|
2020-08-07 20:20:13 +02:00
|
|
|
|
namespace NeonTea.Quakeball.Networking {
|
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);
|
2020-08-08 19:14:34 +02:00
|
|
|
|
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;
|
2020-08-08 19:14:34 +02:00
|
|
|
|
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(() => {
|
2020-08-07 03:46:09 +02:00
|
|
|
|
Net.Quit();
|
2020-08-05 03:21:04 +02:00
|
|
|
|
});
|
2020-08-05 18:50:28 +02:00
|
|
|
|
Send.onClick.AddListener(() => {
|
2020-08-07 03:46:09 +02:00
|
|
|
|
if (Net.Singleton.Instance.Peer != null) {
|
|
|
|
|
foreach (ulong uid in Net.Singleton.Instance.Connections) {
|
2020-08-05 19:39:52 +02:00
|
|
|
|
HelloPckt pckt = new HelloPckt();
|
|
|
|
|
pckt.Text = MessageField.text;
|
2020-08-07 03:46:09 +02:00
|
|
|
|
Net.Singleton.Instance.Peer.SendReliableLater(uid, pckt);
|
|
|
|
|
Net.Singleton.Instance.Peer.SendReliable(uid, pckt);
|
2020-08-05 19:39:52 +02:00
|
|
|
|
}
|
2020-08-05 18:50:28 +02:00
|
|
|
|
}
|
|
|
|
|
});
|
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
|
|
|
|
}
|
|
|
|
|
|
2020-08-05 21:54:53 +02:00
|
|
|
|
public void Err(string text) {
|
|
|
|
|
Debug.Log(text);
|
|
|
|
|
}
|
2020-08-02 02:50:01 +02:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|