Community Made Tools

Have you made any useful utilities with Odin?

Login and submit your creations here

Shader Property ID Attribute

Authored by Maciej
Shared 05-01-2022

Set of ttributes for Odin Inspector for drawing string as dropdown with shader properties from Shader, Material and Renderer.

https://github.com/My-Key/ShaderPropertyIDAttribute

Usage

Basic

// Reference to renderer
[SerializeField] private Renderer m_renderer;

// No parameters
[SerializeField, RendererPropertyID] private string m_id; 

// Point to m_renderer
[SerializeField, RendererPropertyID(nameof(m_renderer))] private string m_id2; 

// Limit property type
[SerializeField, RendererPropertyID(type: ShaderPropertyIDAttributeBase.Type.Color)] private string m_idColor;

(This is the same as seen on image)

RendererPropertyIDAttribute, MaterialsPropertyIDAttribute and ShaderPropertyIDAttribute work the same way, except reference type they require.

If reference is not set, set to null or *empty string, first reference of proper type found in siblings will be used. As seen in example m_id don't have any parameter set, so it will use m_renderer as reference.

Reference string is evaluated just like typical Odin Inspector expresions.

Type can be set to limit which properties should be listed in dropdown.

Code and more examples on https://github.com/My-Key/ShaderPropertyIDAttribute