コード例 #1
0
        public GameScene(int playerSpriteIndex)
        {
            this.playerSpriteIndex = playerSpriteIndex;

            this.networkService = WaveServices.GetService<NetworkService>();
            //Register the scene to use the synchronization components. This scene sync the entities in the scenes with the same sceneId in other clients.
            this.networkManager = this.networkService.RegisterScene(this, GameSceneIdentifier);
        }
コード例 #2
0
 /// <summary>
 /// Registers the scene.
 /// </summary>
 /// <param name="sceneId">The scene identifier.</param>
 /// <param name="manager">The manager.</param>
 /// <exception cref="System.InvalidOperationException">The specified sceneId has been already registered.</exception>
 private static void RegisterScene(string sceneId, NetworkManager manager)
 {
     WeakReference<NetworkManager> managerReference;
     if (registeredScenes.TryGetValue(sceneId, out managerReference))
     {
         NetworkManager registeredManager;
         if (managerReference.TryGetTarget(out registeredManager))
         {
             throw new InvalidOperationException(string.Format("The specified sceneId '{0}' has been already registered.", sceneId));
         }
         else
         {
             managerReference.SetTarget(manager);
         }
     }
     else
     {
         registeredScenes.Add(sceneId, new WeakReference<NetworkManager>(manager));
     }
 }
コード例 #3
0
        /// <summary>
        /// Registers the scene and return its manager.
        /// </summary>
        /// <param name="scene">The scene.</param>
        /// <param name="sceneId">The scene identifier.</param>
        /// <returns>The NetworkManager associated with the scene.</returns>
        public NetworkManager RegisterScene(Scene scene, string sceneId)
        {
            var networkManager = new NetworkManager(scene, this);
            scene.Closed += (e, args) =>
            {
                networkManager.Dispose();
            };

            networkManager.RegisterScene(sceneId);
            return networkManager;
        }