Exemple #1
0
        protected override void Awake()
        {
            base.Awake();

            // Create room client connection
            roomServerConnection = Mst.Create.ClientSocket();

            // Listen toconnection statuses
            roomServerConnection.AddConnectionListener(OnClientConnectedToRoomServer, false);
            roomServerConnection.AddDisconnectionListener(OnClientDisconnectedFromRoomServer, false);

            // If master IP is provided via cmd arguments
            if (Mst.Args.IsProvided(Mst.Args.Names.MasterIp))
            {
                masterIp = Mst.Args.MasterIp;
            }

            // If master port is provided via cmd arguments
            if (Mst.Args.IsProvided(Mst.Args.Names.MasterPort))
            {
                masterPort = Mst.Args.MasterPort;
            }

            // Set the scene that player will be sent to is disconnected from server
            if (Mst.Options.Has(MstDictKeys.roomOfflineSceneName))
            {
                offlineScene = Mst.Options.AsString(MstDictKeys.roomOfflineSceneName);
            }
        }
    protected virtual void Start()
    {
        Logger.LogLevel = LogLevel;
        SpawnerController.Logger.LogLevel = SpawnControllerLogLevel;

        _connection = GetConnection();

        // Subscribe to connection event
        _connection.AddConnectionListener(OnConnectedToMaster, true);
    }
    private void Awake()
    {
        Logs.Logger.LogLevel = GlobalLogsLevel;
        Logger.LogLevel      = BootstrapperLogLevel;

        _connection = Msf.Connection;

        // Subscribe to connection event
        _connection.AddConnectionListener(OnConnectedToMaster, true);

        if (EnableSceneLoading && // If scene loading is enabled
            !OnlyAfterConnected && // and not just after connecting
            Msf.Args.IsProvided(Msf.Args.Names.LoadScene) && // and argument is provided
            SceneManager.GetActiveScene().name != Msf.Args.LoadScene)    // and current scene is not the one we need
        {
            SceneManager.LoadScene(Msf.Args.LoadScene);
        }
    }
        /// <summary>
        /// Changes the connection object, and sets all of the message handlers of this object
        /// to new connection.
        /// </summary>
        /// <param name="socket"></param>
        public void ChangeConnection(IClientSocket socket)
        {
            // Clear just connection but not handlers
            ClearConnection(false);

            // Change connections
            Connection = socket;

            // Override packet handlers
            foreach (var packetHandler in handlers.Values)
            {
                socket.SetHandler(packetHandler);
            }

            Connection.OnStatusChangedEvent += OnConnectionStatusChanged;
            OnConnectionSocketChanged(Connection);
            Connection.AddConnectionListener(OnClientConnectedToServer, false);
            Connection.AddDisconnectionListener(OnClientDisconnectedFromServer, false);
        }