void Start () {
        RegisterHandlers();

        UnityNetcode.QuerySupport((supportStatus) =>
        {
            if (supportStatus == NetcodeIOSupportStatus.Available)
            {
                Debug.LogError("Netcode.IO available and ready!");

                UnityNetcode.CreateClient(NetcodeIOClientProtocol.IPv4, (client) =>
                {
                    this.client = client;
                    client.SetTickrate(60);
                    //StartCoroutine(connectToServer());

                });
            }
            else if (supportStatus == NetcodeIOSupportStatus.Unavailable)
            {
                Debug.LogError("Netcode.IO not available");
            }
            else if (supportStatus == NetcodeIOSupportStatus.HelperNotInstalled)
            {
                Debug.LogError("Netcode.IO is available, but native helper is not installed");
            }
        });
	}
示例#2
0
        // Start is called before the first frame update
        void Start()
        {
            try
            {
                _server = UnityNetcode.CreateServer(
                    _ip,         // string public IP clients will connect to
                    _port,       // port clients will connect to
                    protocolID,  // ulong number used to identify this application. must be the same as the token server generating connect tokens.
                    maxClients,  // maximum number of clients who can connect
                    privateKey); // byte[32] private encryption key shared between token server and game server

                // Called when a client connects to the server
                _server.ClientConnectedEvent.AddListener(ClientConnected); // void( RemoteClient client );

                // Called when a client disconnects from the server
                _server.ClientDisconnectedEvent.AddListener(ClientDisconnected); // void( RemoteClient client );

                // Called when a client sends a payload to the server
                // Note that byte[] payload will be returned to a pool after the callback, so don't keep a reference to it.
                _server.ClientMessageEvent.AddListener(ClientMessageEvent); // void( RemoteClient sender, ByteBuffer payload );

                _server.StartServer();                                      // start listening for clients
            }
            catch (Exception e)
            {
                Application.Quit();
            }
        }
    private void Start()
    {
        logLine("Checking for Netcode.IO support...");

        UnityNetcode.QuerySupport((supportStatus) =>
        {
            if (supportStatus == NetcodeIOSupportStatus.Available)
            {
                logLine("Netcode.IO available and ready!");

                UnityNetcode.CreateClient(NetcodeIOClientProtocol.IPv4, (client) =>
                {
                    this.client = client;
                    StartCoroutine(connectToServer());
                });
            }
            else if (supportStatus == NetcodeIOSupportStatus.Unavailable)
            {
                logLine("Netcode.IO not available");
            }
            else if (supportStatus == NetcodeIOSupportStatus.HelperNotInstalled)
            {
                logLine("Netcode.IO is available, but native helper is not installed");
            }
        });
    }
 private void OnDestroy()
 {
     if (client != null)
     {
         UnityNetcode.DestroyClient(client);
     }
 }
 private void Connect(NetcodeIOClientProtocol protocol)
 {
     UnityNetcode.CreateClient(protocol, client =>
     {
         _client          = client;
         var connectToken = generateToken();
         client.Connect(connectToken, OnConnectSuccess, OnConnectFailure);
     });
 }
 // Start is called before the first frame update
 void Start()
 {
     // check for Netcode.IO extension
     // Will provide NetcodeIOSupportStatus enum, either:
     // Available, if Netcode.IO is available and the standalone helper is installed (or if in standalone),
     // Unavailable, if Netcode.IO is unsupported (direct user to install extension)
     // HelperNotInstalled, if Netcode.IO is available but the standalone helper is not installed (direct user to install the standalone helper)
     UnityNetcode.QuerySupport((supportStatus) =>
     {
         UnityNetcode.CreateClient(NetcodeIOClientProtocol.IPv4, ClientConnect);
     });
 }
    private void Start()
    {
        server = UnityNetcode.CreateServer(PublicIP, Port, 0x1122334455667788L, MaxClients, privateKey);

        server.ClientConnectedEvent.AddListener(Server_OnClientConnected);
        server.ClientDisconnectedEvent.AddListener(Server_OnClientDisconnected);
        server.ClientMessageEvent.AddListener(Server_OnClientMessage);

        server.StartServer();

        logLine("Server started");
    }
    private void Start()
    {
        RegisterPackets();

        server = UnityNetcode.CreateServer(PublicIP, Port, ProtocolID, MaxClients, privateKey);
        server.internalServer.LogLevel = NetcodeLogLevel.Debug;

        server.ClientConnectedEvent.AddListener(Server_OnClientConnected);
        server.ClientDisconnectedEvent.AddListener(Server_OnClientDisconnected);
        server.ClientMessageEvent.AddListener(Server_OnClientMessage);

        server.internalServer.Tickrate = 60;
        server.StartServer();

        logLine("Server started");
    }
        // Use this for initialization
        void Start()
        {
            UnityNetcode.QuerySupport(supportStatus =>
            {
                switch (supportStatus)
                {
                case NetcodeIOSupportStatus.HelperNotInstalled:
                case NetcodeIOSupportStatus.Unavailable:
                    return;

                case NetcodeIOSupportStatus.Available:
                    Connect(NetcodeIOClientProtocol.IPv4);
                    break;

                case NetcodeIOSupportStatus.Unknown:
                    break;

                default:
                    Connect(NetcodeIOClientProtocol.IPv4);
                    break;
                }
            });
        }
示例#10
0
 private void OnDestroy()
 {
     UnityNetcode.DestroyClient(_client);
 }
 void OnApplicationQuit()
 {
     if (client != null)
         UnityNetcode.DestroyClient(client);
 }