Beispiel #1
0
        protected void Awake()
        {
#if USE_WEBGL_PLUGIN
            // initialize the plugin wrapper
            NetcodePluginWrapper.netcodeio_init();
#endif
        }
Beispiel #2
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
        }
Beispiel #3
0
 protected IEnumerator doQuerySupport(System.Action <NetcodeIOSupportStatus> callback)
 {
     NetcodePluginWrapper.netcodeio_query_support(Instance.gameObject.name);
     while (status == NetcodeIOSupportStatus.Unknown)
     {
         yield return(null);
     }
     callback(status);
 }
Beispiel #4
0
        // called when a netcode.io client is created
        protected void OnNetcodeIOClientCreated(int handle)
        {
            // create the NetcodeClient object
            NetcodeClient client = new GameObject("__netcode_client_" + handle).AddComponent <NetcodeClient>();

            client.transform.SetParent(transform);

            // assign handle and store client
            client.Handle = handle;
            clients.Add(handle, client);

            // add callback
            NetcodePluginWrapper.netcodeio_clientAddListener(handle, handleClientMessage);

            // pass new client object to callback
            pendingClientCreatedCallbacks[handle](client);
            pendingClientCreatedCallbacks.Remove(handle);
        }