TilePlus Script Attributes
If you’ve done any Unity coding then you’re probably familiar with Attributes by now, such as those having to do with serialization, or those affecting inspectors. The normal Unity Tile Selection inspector only displays the fields of the Tile class and no others. But we’d like to be able to view and modify fields and properties from TilePlusBase-derived tiles.
The Tile+Brush and Tile+Painter Inspectors and underlying library functions control what you see when using the Selection and Brush inspectors. It’s a fair amount of IMGUI code. But normal humans should not have to struggle with that. So here in TilePlus land, we have several new Attributes which can be added to your code to display fields, properties, and even invoke methods or provide custom IMGUI code for functionality that the inspectors can’t handle.
The Selection Inspector and the Brush Inspector (and their associated equivalents in Tile+Painter) use these attributes to display simple fields and properties. Fields can be modified, and the changes are saved in the Scene. Like any other change made to a scene, you need to save the scene to persist the changes. Normally, the Configuration Editor sets “Autosave” on and the save is done automatically for every change you make.
Your original TPT tile in your Project folder will never be altered. Note that field, property, and method declarations need to be public or protected to work with these attributes.
Attribute | Affected | Description |
---|---|---|
[TptShowField] | Selection Inspector | The types of fields that you can use this on are bool, int, float, string, Color, Vector2, Vector3, Vector2Int, and Vector3Int. Ints and floats can optionally use range sliders. |
[TptShowEnum] | Selection Inspector | Show Enums in a pop-up. |
[TptShowObjectField] | Selection Inspector | Objects such as GameObjects can be referenced with this attribute. |
[TptShowAsLabelSelectionInspector] | Selection Inspector | For a field or property, the value returned is displayed with ToString, so whatever you mark with this attribute must have a ToString() method or return a string. |
[TptShowAsLabelBrushInspector] | Brush Inspector | Same as above. |
[TptShowMethodAsButton] | Selection Inspector | Invoke a method, see below. |
[TptShowCustomGui] | Selection Inspector | Create your own IMGUI function |
[Tooltip] | Selection Inspector, Brush Inspector | This is a normal Unity attribute that you can find in the scripting reference. Note: Fields only. |
[Note] | Selection Inspector | Add a note to a field or method. Note can be a static string or be provided by a property. |
If a tooltip is provided as part of any attribute, then any normal [Tooltip] attribute will be ignored.
Display Order
The display formatter organizes the various attributes in the same order as the class hierarchy for the tile. For example, a TpFlexAnimatedTile tile shows information from TpFlexAnimatedTile followed by TilePlusBase.
In each section, Attributes are processed in the following order:
- Properties with TptShowAsLabelSelectionInspector or TptShowAsLabelBrushInspector.
- Methods with TptShowCustomGui
- Methods with TptShowMethodAsButton
- Simple fields with TptShowField
- Enum fields with TptShowEnum
- Object fields with TptShowObject field