Example #1
0
        public static void InitializeSharedTilemaps(GeneratedLevel level, ITilemapLayersHandler tilemapLayersHandler)
        {
            // Initialize GameObject that will hold tilemaps
            var tilemapsRoot = new GameObject(GeneratorConstants.TilemapsRootName);

            tilemapsRoot.transform.parent = level.RootGameObject.transform;

            // Create individual tilemaps
            tilemapLayersHandler.InitializeTilemaps(tilemapsRoot);
        }
Example #2
0
        public static void InitializeSharedTilemaps(GeneratedLevel level, TilemapLayersStructureMode mode, ITilemapLayersHandler defaultTilemapLayersHandler, ITilemapLayersHandler customTilemapLayersHandler, GameObject example, Material tilemapMaterial)
        {
            GameObject tilemapsRoot;

            if (/*mode == TilemapLayersStructureMode.Automatic || */ mode == TilemapLayersStructureMode.FromExample)
            {
                if (mode == TilemapLayersStructureMode.FromExample && example == null)
                {
                    throw new ConfigurationException($"When {nameof(PostProcessConfig.TilemapLayersStructure)} is set to {nameof(TilemapLayersStructureMode.FromExample)}, {nameof(PostProcessConfig.TilemapLayersExample)} must not be null. Please set the field in the Dungeon Generator component.");
                }

                //var tilemapsSource = mode == TilemapLayersStructureMode.Automatic
                //    ? level.GetRoomInstances().First().RoomTemplateInstance
                //    : example;
                var tilemapsSource     = example;
                var tilemapsSourceRoot = RoomTemplateUtils.GetTilemapsRoot(tilemapsSource);

                if (mode == TilemapLayersStructureMode.FromExample && tilemapsSourceRoot == tilemapsSource)
                {
                    throw new ConfigurationException($"Given {nameof(PostProcessConfig.TilemapLayersExample)} is not valid as it does not contain a game object called {GeneratorConstants.TilemapsRootName} that holds individual tilemap layers.");
                }

                tilemapsRoot      = Object.Instantiate(tilemapsSourceRoot, level.RootGameObject.transform);
                tilemapsRoot.name = GeneratorConstants.TilemapsRootName;

                foreach (var tilemap in tilemapsRoot.GetComponentsInChildren <Tilemap>())
                {
                    tilemap.ClearAllTiles();
                }
            }
            else
            {
                // Initialize GameObject that will hold tilemaps
                tilemapsRoot = new GameObject(GeneratorConstants.TilemapsRootName);
                tilemapsRoot.transform.parent = level.RootGameObject.transform;

                if (mode == TilemapLayersStructureMode.Default)
                {
                    defaultTilemapLayersHandler.InitializeTilemaps(tilemapsRoot);
                }
                else if (mode == TilemapLayersStructureMode.Custom)
                {
                    if (customTilemapLayersHandler == null)
                    {
                        throw new ConfigurationException($"When {nameof(PostProcessConfig.TilemapLayersStructure)} is set to {nameof(TilemapLayersStructureMode.Custom)}, {nameof(PostProcessConfig.TilemapLayersHandler)} must not be null. Please set the field in the Dungeon Generator component.");
                    }

                    customTilemapLayersHandler.InitializeTilemaps(tilemapsRoot);
                }
            }
        }
Example #3
0
        public static void InitializeSharedTilemaps(GeneratedLevel level, ITilemapLayersHandler tilemapLayersHandler, Material tilemapMaterial)
        {
            // Initialize GameObject that will hold tilemaps
            var tilemapsRoot = new GameObject(GeneratorConstants.TilemapsRootName);

            tilemapsRoot.transform.parent = level.RootGameObject.transform;

            // Create individual tilemaps
            tilemapLayersHandler.InitializeTilemaps(tilemapsRoot);

            // Set material
            if (tilemapMaterial != null)
            {
                foreach (var tilemapRenderer in tilemapsRoot.GetComponentsInChildren <TilemapRenderer>())
                {
                    tilemapRenderer.material = tilemapMaterial;
                }
            }
        }
Example #4
0
        protected void InitializeTilemaps(ITilemapLayersHandler tilemapLayersHandler)
        {
            // Add Doors component
            if (gameObject.GetComponent <Grid>() == null)
            {
                gameObject.AddComponent <Grid>();
            }

            // Remove all children game objects
            var children = new List <GameObject>();

            foreach (Transform child in transform)
            {
                children.Add(child.gameObject);
            }
            children.ForEach(DestroyImmediate);

            // Initialize tilemaps
            tilemapLayersHandler.InitializeTilemaps(gameObject);
        }