RangeProperty
Draws a slider for a range shader property, using automatic layout.
Read time 2 minutesLast updated 20 days ago
Definition
- Type: Method
- Namespace: UnityEditor
- Assembly: UnityEditor.CoreModule
RangeProperty(MaterialProperty, string)
Draws a slider for a range shader property, using automatic layout.
public float RangeProperty(MaterialProperty prop, string label)
Parameters
Returns
Type | Description |
|---|---|
| float | The value of the property, which might have changed if the user interacted with the control. |
Remarks
Use this method in a custom material editor to draw a slider for a range shader property. This overload uses automatic layout. To set the position and size of the control, use the overload that takes a Rect.
To use a custom material editor, create the editor class in a folder named inside the folder, then reference the class name in the shader. For example:
EditorAssetsCustomEditor "MaterialRangePropertyExample"
The following example draws a range slider for the Glossiness property of the shader:
using UnityEngine;using UnityEditor;public class MaterialRangePropertyExample : MaterialEditor{ public override void OnInspectorGUI( ) { serializedObject.Update( ); SerializedProperty matShader = serializedObject.FindProperty( "m_Shader" ); if( !isVisible ) return; Material mat = target as Material; MaterialProperty Glossiness = GetMaterialProperty( new Object[] { mat }, "_Glossiness" ); if( Glossiness == null ) return; EditorGUI.BeginChangeCheck( ); RangeProperty( Glossiness, "Glossiness" ); if( EditorGUI.EndChangeCheck( ) ) PropertiesChanged( ); }}
The following image shows the example material editor:

Example material editor in the Inspector window.
RangeProperty(Rect, MaterialProperty, string)
Draws a slider for a range shader property at a specified position.
public float RangeProperty(Rect position, MaterialProperty prop, string label)
Parameters
The position and size of the control.
The material property to edit.
The label to show for the property.
Returns
Type | Description |
|---|---|
| float | The value of the property, which might have changed if the user interacted with the control. |
Remarks
Use this method in a custom material editor to draw a slider for a range shader property. This overload draws the control at . To use automatic layout, use the overload without a Rect.
positionThe following example uses the parameter to set the position and size of the slider in the custom material editor:
positionExamples
using UnityEngine;using UnityEditor;public class MaterialRangePropertyWithRectExample : MaterialEditor{ public override void OnInspectorGUI( ) { serializedObject.Update( ); SerializedProperty matShader = serializedObject.FindProperty( "m_Shader" ); if( !isVisible ) return; Material mat = target as Material; MaterialProperty Glossiness = GetMaterialProperty( new Object[] { mat }, "_Glossiness" ); if( Glossiness == null ) return; EditorGUI.BeginChangeCheck( ); RangeProperty( new Rect( 20, 60, 300, 20 ), Glossiness, "Glossiness" ); if( EditorGUI.EndChangeCheck( ) ) PropertiesChanged( ); }}
RangeProperty(string, string, float, float)
Draw a range slider for a range shader property, specified by name.
public float RangeProperty(string propertyName, string label, float v2, float v3)
Parameters
Returns
Type | Description |
|---|---|
| float | The value of the property, which might have been changed by the user interacting with the control. |
Remarks
This overload is obsolete. Use MaterialEditor.RangeProperty(MaterialProperty, string) instead.