2d-extras
2d-extras copied to clipboard
Need to be able to change ACTIVE TILEMAP and ACTIVE TOOL from script
we need the ability to set the ACTIVE TILEMAP and ACTIVE TOOL in the tile pallet from code. Since we only have access to individual tool callbacks we have very limited ability to extend tools from GridBrushBase and GridBrushEditorBase. For instance selecting a brush should allow us to start with a default tool.
currently if your brush only supports one tool, that brush is useless unless the user knows what brush to select.
Similarly, often a brush will want to paint on only one active tilemap making it simple for the user of a tool to use your brush without knowing what layer to paint on. allowing us to change active tilemap will greatly simplify many use cases we are running into.
👍 Seconded, would be nice for custom tooling.
For now we've been using reflection to do this, and it works pretty well. We have functions to
- Set / Get the Active Tilemap Target
- Set / Get the current Brush
- Set / Get the current Palette
It might have unintended side effects like pinging the tilemap you select, but for us that's been fine if not desired. Here's our class, use it at your own risk, I'm not going to be able to provide support but it's worked so far: https://gist.github.com/edwardrowe/d1995ab0870320a5b50d7488071f02db
Here's a shameless plug but also a nice demo of the setup we've got, just layering our own tools on top of Unity's native tools. Maybe also a nice example of a use case.
oh man. that looks great! I see you have done what I've been avoiding. completing throwing out using GridbrushBase and GridbrushEditor. I fear I'm going to have to do the same. Tilemap is just so close to being extendable for our needs but not quite there :(.
Took me a sec to figure out why you are not drawing directly on the map. I think you are delegating areas for types so you can swap out room maps?
Yeah, I think that pretty much sums it up with regards to the extensibility of the existing tiles and brushes.
For the tile generation in the gif - yeah the initial thought was the markup tiles (the height + surface tiles in the area above the room) would be generic so that we could reuse them for other biomes. But in practice we are finding the rooms for different biomes need to explore different design spaces so they aren't that reusable. That said, it's still useful for generating the walls, floors, and surfaces quickly. It's a pretty crazy setup, really.
We will expose these functions so that you do not need to use reflection to access them.
If you have any other wishes for improving the Tile Palette, please do comment here as well!
wow thanks! This is amazing! Mostly we just need the ability to change things in the tilemap editor. Active tilemap being the most important. though active brush and pallet would be really nice. Great work by the way ChuanXin! If we are critical it's because we LOVE this thing! -nic
Hi is this feature available yet? I too could benefit greatly from this.
Currently, the APIs are available in the Tilemap Editor package in 2019.2 beta. They can be accessed with the following properties:
Active Target: GridPaintingState.scenePaintTarget Current Palette: GridPaintingState.palette Current Brush: GridPaintingState.gridBrush
Current Tool: TilemapEditorTool.SetActiveEditorTool(typeof(TilemapEditorTool))
Awesome thanks!!
This is great, thank you!
Additionally: Can we have a way to detect which editor tool is currently selected? I'd like to have some editor behavior that happens when the erase tool is selected but not otherwise.
Yes, you should be able to do that with the Tilemap Editor package in 2019.2. You can check the active tool type with EditorTools.activeToolType
.
Example:
using UnityEditor.EditorTools;
using UnityEditor.Tilemaps;
public class EditorToolsHelper
{
public static bool IsEraseToolActive()
{
return EditorTools.activeToolType == typeof(EraseTool);
}
[MenuItem("Editor Tools/Is Erase Tool Active")]
public static void LogIsEraseToolActive()
{
Debug.Log(IsEraseToolActive());
}
}
Perfect! That’s just the ticket. Thank you so much!