2017-05-08 00:59:50 +02:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* This class is used pretty much anywhere in order to make the "first step" of networking.
|
|
|
|
|
* It adds the proper components to World Root and tells them to start.
|
|
|
|
|
* */
|
|
|
|
|
public class NetworkEstablisher : MonoBehaviour {
|
|
|
|
|
|
|
|
|
|
[Tooltip("Required field only if StartClient() is used.")]
|
|
|
|
|
public InputField IPField;
|
|
|
|
|
[Tooltip("Required field only if StartClient() is used.")]
|
2017-05-08 02:59:42 +02:00
|
|
|
|
public InputField ClientPortField;
|
2017-05-08 00:59:50 +02:00
|
|
|
|
|
|
|
|
|
[Tooltip("Required field only if StartServer() is used.")]
|
2017-05-08 02:59:42 +02:00
|
|
|
|
public InputField ServerPortField;
|
2017-05-08 00:59:50 +02:00
|
|
|
|
|
2017-05-08 02:59:42 +02:00
|
|
|
|
public GameObject WorldRoot;
|
2017-05-08 00:59:50 +02:00
|
|
|
|
|
|
|
|
|
// Use this for initialization
|
|
|
|
|
void Start () {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Update is called once per frame
|
|
|
|
|
void Update () {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void StartClient() {
|
2017-05-08 02:59:42 +02:00
|
|
|
|
string IP = IPField.text;
|
|
|
|
|
if (IP.Length == 0) {
|
|
|
|
|
IP = "localhost";
|
2017-05-08 00:59:50 +02:00
|
|
|
|
}
|
2017-05-08 02:59:42 +02:00
|
|
|
|
string PortText = ClientPortField.text;
|
|
|
|
|
int Port = 3935;
|
|
|
|
|
if (PortText.Length > 0) {
|
|
|
|
|
Port = Int32.Parse(PortText);
|
2017-05-08 00:59:50 +02:00
|
|
|
|
}
|
2017-05-08 02:59:42 +02:00
|
|
|
|
StartClient(IP, Port);
|
2017-05-08 00:59:50 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void StartClient(string ip, int port) {
|
2017-05-08 02:59:42 +02:00
|
|
|
|
Client Client = WorldRoot.AddComponent<Client>();
|
|
|
|
|
Client.LaunchClient(ip, port);
|
2017-05-08 00:59:50 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void StartServer() {
|
2017-05-08 02:59:42 +02:00
|
|
|
|
string PortText = ServerPortField.text;
|
|
|
|
|
int Port = 3935;
|
|
|
|
|
if (PortText.Length > 0) {
|
|
|
|
|
Port = Int32.Parse(PortText);
|
2017-05-08 00:59:50 +02:00
|
|
|
|
}
|
2017-05-08 02:59:42 +02:00
|
|
|
|
StartServer(Port);
|
2017-05-08 00:59:50 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void StartServer(int port) {
|
2017-05-08 02:59:42 +02:00
|
|
|
|
Server Server = WorldRoot.AddComponent<Server>();
|
|
|
|
|
Server.LaunchServer(port);
|
2017-05-08 00:59:50 +02:00
|
|
|
|
}
|
|
|
|
|
}
|