zoukankan      html  css  js  c++  java
  • Unity NetWork

    using UnityEngine;
    using System.Collections;
    
    public class NetworkTest : MonoBehaviour {
    
        int myPort = 10000;//端口号
        string serverIP = "172.16.19.30";//服务器ip
        string yourState = "";
        // Use this for initialization
        void Start () {
        
        }
        
        // Update is called once per frame
        void Update () {
        
        }
    
        void OnGUI() {
            if (GUILayout.Button("Creat Server")) {
                /*创建一个服务器
                 * 3个参数
                 * 1、允许的入站连接或玩家数量
                 * 2、监听的端口
                 * 3、设置穿透功能
                 */
                Network.InitializeServer(32, myPort,false);
            }
            if (GUILayout.Button("Connect Server")) {
                /*客户端连接服务器*/
                Network.Connect(serverIP, myPort);
            }
            GUILayout.TextArea(yourState);
            switch (Network.peerType) { 
                case NetworkPeerType.Server:
                    yourState = "You are Server, The server has Created!";
                    GUILayout.TextField("Had "+Network.connections.Length.ToString()+" Connected");
                    break;
                case NetworkPeerType.Client:
                    yourState = "You are Client";
                    break;
                case NetworkPeerType.Connecting:
                    yourState = "Connecting...";
                    break;
                case NetworkPeerType.Disconnected:
                    yourState = "You had not connected the server";
                    break;
            }
        }
    }
  • 相关阅读:
    iLearning D3.js 2.0 released
    A better way to learn D3 js
    数据中台解析Hive SQL过程
    go语言刷leetcode
    go语言刷leetcode
    普通方法多态,属性,私有方法和静态方法不多态
    Kafka spring 集成
    Scala Sublime text 3 Build 编译
    tornado settings想到的
    linux 线程回顾
  • 原文地址:https://www.cnblogs.com/xiaolongchase/p/3368585.html
Copyright © 2011-2022 走看看