• 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);
      }
    }

  • 相关阅读:
    记一道有趣的数学题
    BJOI2018 二进制
    BJOI2016 IP地址
    BJOI2016 回转寿司
    BJOI2017 开车
    BJOI2019 光线
    java 下载
    springboot 运行相关命令
    sql mapper 里面 Integer 类型判断
    springboot 访问jar同级别下的文件访问问题
  • 原文地址:https://www.cnblogs.com/softimagewht/p/2132305.html
Copyright © 2020-2023  润新知