• Network_01


    var remoteIP = "127.0.0.1";
    var remotePort = 25000;
    var ListenPort = 25000;
    var useNAT = false ;
    var yourIP = "";
    var yourPort = "";

    function OnGUI()
    {
      if(Network.peerType == NetworkPeerType.Disconnected)
      {
        if(GUI.Button(Rect(10,10,100,30),"connect"))
        {
          Network.useNat = useNAT;
          Network.Connect(remoteIP,remotePort);
        }
       
        if(GUI.Button(Rect(10,50,100,30),"Start server"))
        {
          Network.useNat = useNAT;
          Network.InitializeServer(4,ListenPort);
         
          for(var go:GameObject in FindObjectsOfType(GameObject))
          {
            go.SendMessage("OnNetworkLoadedLevel",SendMessageOptions.DontRequireReceiver);
           
          }
        }
       
        remoteIP = GUI.TextField(Rect(120,10,100,20),remoteIP);
        remotePort = parseInt(GUI.TextField(Rect(230,10,40,20),remotePort.ToString()));
      }
      else
      {
        var ipaddress = Network.player.ipAddress;
        var port = Network.player.port.ToString();
       
        GUI.Label(Rect(140,20,250,40),"ip address:"+ipaddress+":"+port);
       
        if(GUI.Button(Rect(10,10,100,50),"Disconnect"))
        {
          Network.Disconnect(200);
        }
      }
    }

    function OnConnectedToServer()
    {
      for(var go:GameObject in FindObjectsOfType(GameObject))
      {
        go.SendMessage("OnNetworkLoadedLevel",SendMessageOptions.DontRequireReceiver);
      }
    }

  • 相关阅读:
    菜单导航组件
    flask+nginx+uwsgi在服务器搭建项目
    安装Anaconda
    vscode上eslink包失效
    js滚动事件
    打字游戏
    js更高文档的样式
    js事件
    Dom对象更改文档结构.html
    js重点
  • 原文地址:https://www.cnblogs.com/softimagewht/p/2132305.html
Copyright © 2020-2023  润新知