Base class to derive custom material property drawers from.
Shader "Custom/Example" { Properties { _MainTex ("Base (RGB)", 2D) = "white" {} // Display a popup with None,Add,Multiply choices, // and setup corresponding shader keywords. [KeywordEnum(None, Add, Multiply)] _Overlay ("Overlay mode", Float) = 0 _OverlayTex ("Overlay", 2D) = "black" {} // Display as a toggle. [Toggle] _Invert ("Invert color?", Float) = 0 } // rest of shader code... }
// The property drawer class should be placed in an editor script, inside a folder called Editor.// Use with "[MyToggle]" before a float shader property class MyToggleDrawer extends MaterialPropertyDrawer { // Draw the property inside the given rect function OnGUI (position : Rect, prop : MaterialProperty, label : String, editor : MaterialEditor) { // Setup EditorGUI.BeginChangeCheck (); var value : boolean = prop.floatValue != 0.0f; EditorGUI.showMixedValue = prop.hasMixedValue; // Show the toggle control value = EditorGUI.Toggle (position, label, value); EditorGUI.showMixedValue = false; if (EditorGUI.EndChangeCheck ()) { // Set the new value if it has changed prop.floatValue = value ? 1.0f : 0.0f; } } }
no example available in C#
no example available in Boo
// Will set "_INVERT_ON" shader keyword when set [Toggle] _Invert ("Invert?", Float) = 0// Will set "ENABLE_FANCY" shader keyword when set [Toggle(ENABLE_FANCY)] _Fancy ("Fancy?", Float) = 0
// Blend mode values [Enum(UnityEngine.Rendering.BlendMode)] _Blend ("Blend mode", Float) = 1// A subset of blend mode values, just "One" (value 1) and "SrcAlpha" (value 5) [Enum(One,1,SrcAlpha,5] _Blend2 ("Blend mode subset", Float) = 1
// Display a popup with None,Add,Multiply choices. // Each option will set _OVERLAY_NONE, _OVERLAY_ADD, _OVERLAY_MULTIPLY shader keywords. [KeywordEnum(None, Add, Multiply)] _Overlay ("Overlay mode", Float) = 0// ...later on in CGPROGRAM code: #pragma multi_compile _OVERLAY_NONE, _OVERLAY_ADD, _OVERLAY_MULTIPLY // ...
// A slider with 3.0 response curve [PowerSlider(3.0)] _Shininess ("Shininess", Range (0.01, 1)) = 0.08
Apply | Apply extra initial values to the material. |
---|---|
GetPropertyHeight | Override this method to specify how tall the GUI for this property is in pixels. |
OnGUI | Override this method to make your own GUI for the property. |