Esempio n. 1
0
        public override void OnStartServer()
        {
            // Register the spawnable prefabs on server
            Matter.RegisterSpawnablePrefabs();

            // Register message handlers
            NetworkServer.RegisterHandler <ConnectionRequestMessage>(this.OnConnectionRequestMessage, false);

            // Register server events
            GameManager.OnLevelLoaded += GameManager_OnLevelLoaded_Server;

            // Load the first level if no level is currently loaded (e.g. when launching from the Unity Editor while having a level scene open)
            if (GameManager.CurrentLevel == null)
            {
                GameManager.Instance.LoadLevel(1);
            }
        }
Esempio n. 2
0
        public override void OnStartClient()
        {
            // Register the spawnable prefabs on client (if not registered already because we are running a server)
            if (!NetworkServer.active)
            {
                Matter.RegisterSpawnablePrefabs();
            }

            // Register message handlers
            NetworkClient.RegisterHandler <ServerStateMessage>(this.OnServerStateMessage, false);

            // Register client events
            GameManager.OnLevelLoaded += GameManager_OnLevelLoaded_Client;

            // Unload the currently loaded level if there is one (e.g. when launching from the Unity Editor while having a level scene open)
            // and we are not running a server.
            // The client should always load the level that is currently running on the server
            if (!NetworkServer.active)
            {
                GameManager.Instance.UnloadCurrentLevel();
            }
        }