Beispiel #1
0
        /// <summary>
        /// Creates a new Netcode.IO client, with a callback for when the client is created
        /// </summary>
        public static void CreateClient(NetcodeIOClientProtocol protocol, Action <NetcodeClient> clientCreatedCallback)
        {
#if USE_WEBGL_PLUGIN
            string protocolStr = "";
            switch (protocol)
            {
            case NetcodeIOClientProtocol.IPv4:
                protocolStr = "ipv4";
                break;

            case NetcodeIOClientProtocol.IPv6:
                protocolStr = "ipv6";
                break;
            }

            int newHandle = NetcodePluginWrapper.netcodeio_createClient(protocolStr, Instance.gameObject.name);
            pendingClientCreatedCallbacks.Add(newHandle, clientCreatedCallback);
#else
            NetcodeClient clientObj = new GameObject("__netcode_client_" + (clientHandle++)).AddComponent <NetcodeClient>();
            clientObj.transform.SetParent(Instance.transform);

            Client client = new Client();
            clientObj.internalClient = client;
            internal_clients.Add(client);

            clientCreatedCallback(clientObj);
#endif
        }
 private void Connect(NetcodeIOClientProtocol protocol)
 {
     UnityNetcode.CreateClient(protocol, client =>
     {
         _client          = client;
         var connectToken = generateToken();
         client.Connect(connectToken, OnConnectSuccess, OnConnectFailure);
     });
 }