示例#1
0
        public Scene LoadScene(string sceneId)
        {
            if (string.IsNullOrWhiteSpace(sceneId))
            {
                throw new ArgumentException("The scene ID must be specified.", nameof(sceneId));
            }

            var sceneDef = _sceneDefinitions.FirstOrDefault(s => s.SceneId == sceneId);

            if (sceneDef == null)
            {
                return(null);
            }

            ISceneDelegate sceneDelegate = CreateSceneDelegate(sceneDef.SceneDelegateClassName?.Trim());
            TileMap        tileMap       = null;

            if (!string.IsNullOrWhiteSpace(sceneDef.TileMapPath?.Trim()))
            {
                tileMap = _contentManager.Load <TileMap>(sceneDef.TileMapPath?.Trim());
                tileMap.LoadTileSets(_contentManager);
            }

            Scene scene = new Scene(_contentManager, _gameServices, sceneDef.SceneId, sceneDef.Name, _entityManager, sceneDelegate, tileMap);

            CurrentScene = scene;

            CurrentScene?.Initialize();

            return(scene);
        }
示例#2
0
        public Scene(ContentManager content, GameServiceContainer gameServices, string id, string name, EntityManager entityManager, ISceneDelegate sceneDelegate, TileMap tileMap = null)
        {
            _sceneDelegate = sceneDelegate;
            Id             = id;
            Name           = name;
            EntityManager  = entityManager;
            TileMap        = tileMap;
            _gameServices  = gameServices;

            _tileMapEntitiyFactory = new TileMapEntityFactory(gameServices, content);

            _debugTexture = content.Load <Texture2D>("Textures/white_pixel");
        }
示例#3
0
        private ISceneDelegate CreateSceneDelegate(string sceneDelegateClassName)
        {
            if (string.IsNullOrWhiteSpace(sceneDelegateClassName))
            {
                return(null);
            }

            ISceneDelegate sceneDelegate = null;

            try
            {
                Type sceneDelType = Type.GetType(sceneDelegateClassName);

                sceneDelegate = Activator.CreateInstance(sceneDelType) as ISceneDelegate;
            }
            catch (Exception ex)
            {
                throw new SceneDelegateException($"Could not create instance of the specified SceneDelegate '{sceneDelegateClassName}'", ex);
            }

            return(sceneDelegate);
        }