Ejemplo n.º 1
0
 void Awake()
 {
     Started.AddListener(OnRoomStartServer);
     Stopped.AddListener(OnRoomStopServer);
     Connected.AddListener(OnRoomServerConnected);
     Authenticated.AddListener(OnRoomServerAuthenticated);
     Disconnected.AddListener(OnRoomServerDisConnected);
     OnStartHost.AddListener(OnRoomStartHost);
     OnStopHost.AddListener(OnRoomStopHost);
 }
Ejemplo n.º 2
0
        /// <summary>
        /// This starts a network "host" - a server and client in the same application.
        /// <para>The client returned from StartHost() is a special "local" client that communicates to the in-process server using a message queue instead of the real network. But in almost all other cases, it can be treated as a normal client.</para>
        /// </summary>
        public UniTask StartHost(NetworkClient client)
        {
            if (client != null)
            {
                throw new InvalidOperationException("NetworkClient not assigned. Unable to StartHost()");
            }

            // start listening to network connections
            UniTask task = ListenAsync();

            Active = true;

            client.ConnectHost(this);

            // call OnStartHost AFTER SetupServer. this way we can use
            // NetworkServer.Spawn etc. in there too. just like OnStartServer
            // is called after the server is actually properly started.
            OnStartHost?.Invoke();

            logger.Log("NetworkServer StartHost");
            return(task);
        }