-
Notifications
You must be signed in to change notification settings - Fork 2
/
MPBase.cs
101 lines (75 loc) · 2.8 KB
/
MPBase.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
using UnityEngine;
using System.Collections;
using System;
public class MPBase : MonoBehaviour {
public string connectToIp = "127.0.0.1";
public int connectPort = 25000;
public bool useNAT = false;
public string ipAddress = "";
public string port = "";
void OnGUI()
{
if (Network.peerType == NetworkPeerType.Disconnected)
{
if (GUILayout.Button("Connect"))
{
Network.Connect(connectToIp, connectPort);
}
if (GUILayout.Button("Start Server"))
{
Network.InitializeServer(32, connectPort, useNAT);
foreach (GameObject go in FindObjectsOfType(typeof(GameObject)))
{
go.SendMessage("OnNetworkLoadedLevel", SendMessageOptions.DontRequireReceiver);
}
}
connectToIp = GUILayout.TextField(connectToIp);
connectPort = Convert.ToInt32(GUILayout.TextField(connectPort.ToString()));
}
else
{
if(Network.peerType == NetworkPeerType.Connecting)
{
GUILayout.Label("Connect status: Connecting");
}else if(Network.peerType == NetworkPeerType.Client)
{
GUILayout.Label("Connect status: Client");
GUILayout.Label("Ping to server: " + Network.GetAveragePing(Network.connections[0]));
}else if(Network.peerType == NetworkPeerType.Server)
{
GUILayout.Label("Connect status: Server");
GUILayout.Label("Connections: " + Network.connections.Length);
if (Network.connections.Length >= 1)
{
GUILayout.Label("Ping to server: " + Network.GetAveragePing(Network.connections[0]));
}
}
if(GUILayout.Button("Disonnect"))
{
Network.Disconnect(200);
}
ipAddress = Network.player.ipAddress;
port = Network.player.port.ToString();
GUILayout.Label("IP Address: "+ ipAddress + " : " + port);
}
}
/*
void OnPlayerConnected(NetworkPlayer netPlayer)
{
networkView.RPC("initClientPlayers", netPlayer, Network.connections.Length);
}
[RPC]
void initClientPlayers(int connections)
{
//GameObject openNI = GameObject.Find("OpenNI");
//openNI.GetComponent<OpenNISplitScreenSkeletonController>().initClientPlayers(connections);
}
void OnConnectedToServer()
{
foreach (GameObject go in FindObjectsOfType(typeof(GameObject)))
{
go.SendMessage("OnNetworkLoadedLevel", SendMessageOptions.DontRequireReceiver);
}
}
*/
}