public bool HasOutlineOverride() { var tilemapsRoot = RoomTemplateUtilsGrid2D.GetTilemapsRoot(gameObject); var outlineOverride = tilemapsRoot.transform.Find(GeneratorConstantsGrid2D.OutlineOverrideLayerName); return(outlineOverride != null); }
public void RemoveOutlineOverride() { if (!HasOutlineOverride()) { return; } var tilemapsRoot = RoomTemplateUtilsGrid2D.GetTilemapsRoot(gameObject); var outlineOverride = tilemapsRoot.transform.Find(GeneratorConstantsGrid2D.OutlineOverrideLayerName).gameObject; PostProcessUtilsGrid2D.Destroy(outlineOverride); }
/// <summary> /// Sets a given material to all shared tilemap layers. /// </summary> /// <param name="level"></param> /// <param name="tilemapMaterial"></param> public static void SetTilemapsMaterial(GeneratedLevel level, Material tilemapMaterial) { if (tilemapMaterial == null) { return; } var tilemapsRoot = RoomTemplateUtilsGrid2D.GetTilemapsRoot(level.RootGameObject); foreach (var tilemapRenderer in tilemapsRoot.GetComponentsInChildren <TilemapRenderer>()) { tilemapRenderer.material = tilemapMaterial; } }
/// <summary> /// Initializes shared tilemaps of a given level. /// </summary> /// <param name="level">Generated level.</param> /// <param name="mode">Tilemap layers mode.</param> /// <param name="defaultTilemapLayersHandler">Default tilemap layers handler. Used for the Default mode.</param> /// <param name="customTilemapLayersHandler">Custom tilemap layers handler. Used for the Custom mode.</param> /// <param name="example">Example game object for tilemaps structure. Used for the FromExample mode.</param> public static void InitializeSharedTilemaps(GeneratedLevel level, TilemapLayersStructureModeGrid2D mode, ITilemapLayersHandlerGrid2D defaultTilemapLayersHandler, ITilemapLayersHandlerGrid2D customTilemapLayersHandler, GameObject example) { GameObject tilemapsRoot; if (mode == TilemapLayersStructureModeGrid2D.FromExample) { if (example == null) { throw new ConfigurationException($"When {nameof(PostProcessingConfigGrid2D.TilemapLayersStructure)} is set to {nameof(TilemapLayersStructureModeGrid2D.FromExample)}, {nameof(PostProcessingConfigGrid2D.TilemapLayersExample)} must not be null. Please set the field in the Dungeon Generator component."); } var tilemapsSource = example; var tilemapsSourceRoot = RoomTemplateUtilsGrid2D.GetTilemapsRoot(tilemapsSource); if (tilemapsSourceRoot == tilemapsSource) { throw new ConfigurationException($"Given {nameof(PostProcessingConfigGrid2D.TilemapLayersExample)} is not valid as it does not contain a game object called {GeneratorConstantsGrid2D.TilemapsRootName} that holds individual tilemap layers."); } tilemapsRoot = Object.Instantiate(tilemapsSourceRoot, level.RootGameObject.transform); tilemapsRoot.name = GeneratorConstantsGrid2D.TilemapsRootName; foreach (var tilemap in tilemapsRoot.GetComponentsInChildren <Tilemap>()) { tilemap.ClearAllTiles(); } } else { // Initialize GameObject that will hold tilemaps tilemapsRoot = new GameObject(GeneratorConstantsGrid2D.TilemapsRootName); tilemapsRoot.transform.parent = level.RootGameObject.transform; if (mode == TilemapLayersStructureModeGrid2D.Default) { defaultTilemapLayersHandler.InitializeTilemaps(tilemapsRoot); } else if (mode == TilemapLayersStructureModeGrid2D.Custom) { if (customTilemapLayersHandler == null) { throw new ConfigurationException($"When {nameof(PostProcessingConfigGrid2D.TilemapLayersStructure)} is set to {nameof(TilemapLayersStructureModeGrid2D.Custom)}, {nameof(PostProcessingConfigGrid2D.TilemapLayersHandler)} must not be null. Please set the field in the Dungeon Generator component."); } customTilemapLayersHandler.InitializeTilemaps(tilemapsRoot); } } }
public void AddOutlineOverride() { if (HasOutlineOverride()) { return; } var tilemapsRoot = RoomTemplateUtilsGrid2D.GetTilemapsRoot(gameObject); var outlineOverride = new GameObject(GeneratorConstantsGrid2D.OutlineOverrideLayerName); outlineOverride.transform.parent = tilemapsRoot.transform; outlineOverride.AddComponent <Tilemap>(); outlineOverride.AddComponent <TilemapRenderer>(); outlineOverride.AddComponent <OutlineOverrideGrid2D>(); outlineOverride.GetComponent <TilemapRenderer>().sortingOrder = 1000; }
/// <summary> /// Gets the GameObject that is the parent to all the tilemaps. /// </summary> /// <remarks> /// If there is no child named GeneratorConstants.TilemapsRootName, the room template GameObject /// itself is returned to provide backwards compatibility. /// </remarks> /// <param name="roomTemplate">GameObject representing the room template.</param> /// <returns></returns> public static GameObject GetTilemapsRoot(GameObject roomTemplate) { return(RoomTemplateUtilsGrid2D.GetTilemapsRoot(roomTemplate)); }