using UnityEngine;
using System.Collections;
public class Test1 : MonoBehaviour {
int Port = 10000;
// Use this for initialization
void Start () { }
// Update is called once per frame
void Update () { }
void OnGUI(){
switch(Network.peerType){
case NetworkPeerType.Disconnected:
StartServer();
break;
case NetworkPeerType.Server:
OnServer();
break;
case NetworkPeerType.Client:
break;
case NetworkPeerType.Connecting:
break;
}
}
void StartServer(){
if(GUILayout.Button("create local server")){
NetworkConnectionError error = Network.InitializeServer(10,Port,false);
Debug.Log("state:"+error);
}
}
void OnServer(){
GUILayout.Label("create finish wait ro connection:");
int length = Network.connections.Length;
for(int i = 0;i<length;i++){
GUILayout.Label("ID:"+i);
GUILayout.Label("IP:"+Network.connections[i].ipAddress);
GUILayout.Label("port number"+Network.connections[i].port);
}
if(GUILayout.Button("disconnection"))
{
Network.Disconnect();
}
}
}
using UnityEngine;
using System.Collections;
public class Test2 : MonoBehaviour {
string IP = "127.0.0.1";
int Port = 10000;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnGUI(){
switch(Network.peerType){
case NetworkPeerType.Disconnected:
StartServer();
break;
case NetworkPeerType.Server:
//OnServer();
break;
case NetworkPeerType.Client:
break;
case NetworkPeerType.Connecting:
break;
}
}
void StartServer(){
if(GUILayout.Button("connection")){
NetworkConnectionError error = Network.Connect(IP,Port);
Debug.Log("state:"+error);
}
}
}
using UnityEngine;
using System.Collections;
public class Test3 : MonoBehaviour {
int Port = 10000;
string Message = "";
Vector2 scrollPosition;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnGUI(){
switch(Network.peerType){
case NetworkPeerType.Disconnected:
StartServer();
break;
case NetworkPeerType.Server:
OnServer();
break;
case NetworkPeerType.Client:
break;
case NetworkPeerType.Connecting:
break;
}
}
void StartServer(){
if(GUILayout.Button("connection")){
NetworkConnectionError error = Network.InitializeServer(10,Port,false);
Debug.Log("state:"+error);
}
}
void OnServer(){
GUILayout.Label("create finish wait ro connection:");
int length = Network.connections.Length;
for(int i = 0;i<length;i++){
GUILayout.Label("ID:"+i);
GUILayout.Label("IP:"+Network.connections[i].ipAddress);
GUILayout.Label("port number"+Network.connections[i].port);
}
if(GUILayout.Button("disconnection"))
{
Network.Disconnect();
Message = "";
}
scrollPosition = GUILayout.BeginScrollView(scrollPosition,GUILayout.Width(200),GUILayout.Height(500));
GUILayout.Box(Message);
GUILayout.EndScrollView();
}
[RPC]
void RequestMessage(string message,NetworkMessageInfo info){
Message += "\n" + info.sender+":"+message;
}
}
using UnityEngine;
using System.Collections;
public class Test4 : MonoBehaviour {
string IP = "127.0.0.1";
int Port = 10000;
string inputMessage = "input Message";
string Message = "";
Vector2 scrollPosition;
void OnGUI(){
switch(Network.peerType){
case NetworkPeerType.Disconnected:
StartServer();
break;
case NetworkPeerType.Server:
//OnServer();
break;
case NetworkPeerType.Client:
OnClient();
break;
case NetworkPeerType.Connecting:
break;
}
}
void StartServer(){
if(GUILayout.Button("connection")){
NetworkConnectionError error = Network.Connect(IP,Port);
Debug.Log("state:"+error);
}
}
void OnClient(){
scrollPosition = GUILayout.BeginScrollView(scrollPosition,
GUILayout.Width(200),
GUILayout.Height(500));
GUILayout.Box(Message);
GUILayout.BeginHorizontal();
inputMessage = GUILayout.TextArea(inputMessage);
if(GUILayout.Button("send Message")){
networkView.RPC("RequestMessage",RPCMode.All,inputMessage);
}
GUILayout.EndHorizontal();
if(GUILayout.Button("disconnection")){
Network.Disconnect();
Message= "";
}
GUILayout.EndScrollView();
}
[RPC]
void RequestMessage(string message,NetworkMessageInfo info){
Message +="\n"+"Sendor"+info.sender+":"+message;
}
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
}
using UnityEngine;
using System.Collections;
public class Test5 : MonoBehaviour {
int Port = 10000;
string Message = "";
string MoveInfo = "";
Vector2 scrollPosition;
void OnGUI(){
switch(Network.peerType){
case NetworkPeerType.Disconnected:
StartServer();
break;
case NetworkPeerType.Server:
OnServer();
break;
case NetworkPeerType.Client:
break;
case NetworkPeerType.Connecting:
break;
}
}
void StartServer(){
if(GUILayout.Button("create local server")){
NetworkConnectionError error = Network.InitializeServer(10,Port,false);
Debug.Log("state:"+error);
}
}
void OnServer(){
GUILayout.Label("create finish wait to connection:");
int length = Network.connections.Length;
for(int i = 0;i<length;i++){
GUILayout.Label("ID:"+i);
GUILayout.Label("IP:"+Network.connections[i].ipAddress);
GUILayout.Label("port number:"+Network.connections[i].port);
}
if(GUILayout.Button("disconnection"))
{
Network.Disconnect();
MoveInfo = "";
Message = "";
}
scrollPosition = GUILayout.BeginScrollView(scrollPosition,
GUILayout.Width(200),
GUILayout.Height(Screen.height));
GUILayout.Box(Message);
GUILayout.Box(MoveInfo);
GUILayout.EndScrollView();
}
[RPC]
void RequestMessage(string message,NetworkMessageInfo info){
Message +="\n" +"sendor"+info.sender+":"+message;
}
[RPC]
void RequestMove(string message,NetworkMessageInfo info){
MoveInfo += "\n"+"Mover"+info.sender+":action"+message+"move event";
}
// Use this for initialization
void Start () { }
// Update is called once per frame
void Update () { }
}
using UnityEngine;
using System.Collections;
public class Test6 : MonoBehaviour {
string IP = "127.0.0.1";
int Port = 10000;
string inputMessage = "input message";
string Message = "";
Vector2 scrollPosition;
float speed = 10.0f;
float rotationSpeed = 100.0f;
GameObject cube0 = null;
GameObject cube1 = null;
void OnGUI(){
switch(Network.peerType){
case NetworkPeerType.Disconnected:
StartServer();
break;
case NetworkPeerType.Server:
//OnServer();
break;
case NetworkPeerType.Client:
OnClient();
break;
case NetworkPeerType.Connecting:
break;
}
}
void FixedUpdate(){
if(Network.isClient){
float translation = Input.GetAxis("Vertical");
float rotation = Input.GetAxis("Horizontal");
if(translation==1){
networkView.RPC ("RequestMove",RPCMode.All,"up");
}
if(translation == -1){
networkView.RPC ("RequestMove",RPCMode.All,"down");
}
if(rotation == 1){
networkView.RPC ("RequestMove",RPCMode.All,"left");
}
if(rotation == -1){
networkView.RPC ("RequestMove",RPCMode.All,"right");
}
}
}
void StartServer(){
if(GUILayout.Button("connection")){
NetworkConnectionError error = Network.Connect(IP,Port);
Debug.Log("state:"+error);
}
}
void OnClient(){
scrollPosition = GUILayout.BeginScrollView(scrollPosition,
GUILayout.Width(200),
GUILayout.Height(500));
GUILayout.Box(Message);
GUILayout.BeginHorizontal();
inputMessage = GUILayout.TextArea(inputMessage);
if(GUILayout.Button("send")){
networkView.RPC("RequestMessage",RPCMode.All,inputMessage);
}
GUILayout.EndHorizontal();
if(GUILayout.Button("disconnection")){
Network.Disconnect();
Message = "";
}
GUILayout.EndScrollView();
}
[RPC]
void RequestMessage(string message,NetworkMessageInfo info){
Message += "\n"+"sender"+info.sender+":"+message;
}
[RPC]
void RequestMove(string message,NetworkMessageInfo info){
string sender = info.sender.ToString();
GameObject moveObject = null;
if(sender =="-1")
{
moveObject = cube0;
}else{
moveObject = cube1;
}
int vertical = 0;
int horizontal = 0;
if(message == "up"){
vertical = 1;
}
if(message == "down"){
vertical = -1;
}
if(message == "left"){
horizontal = 1;
}
if(message == "right"){
horizontal = -1;
}
float translation = vertical * speed * Time.deltaTime;
float rotation = horizontal * rotationSpeed * Time.deltaTime;
moveObject.gameObject.transform.Translate(0,0,translation);
moveObject.gameObject.transform.Rotate(0,rotation,0);
}
// Use this for initialization
void Start () {
cube0 = GameObject.Find("Cube0");
cube1 = GameObject.Find("Cube1");
}
// Update is called once per frame
void Update () {
}
}