Documentation

Unity Engine

Unity Engine

RangeProperty

Draws a slider for a range shader property, using automatic layout.
Read time 2 minutesLast updated 21 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

The material property to edit.

label

The label to show for the property.

Returns

Type

Description

floatThe 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
Editor
inside the
Assets
folder, then reference the class name in the shader. For example:
CustomEditor "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:
MaterialEditorRangeProperty (RangeProperty)
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

position

The position and size of the control.

The material property to edit.

label

The label to show for the property.

Returns

Type

Description

floatThe 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
position
. To use automatic layout, use the overload without a Rect.
The following example uses the
position
parameter to set the position and size of the slider in the custom material editor:

Examples

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.
Warning
Deprecated. Use RangeProperty with MaterialProperty instead.
public float RangeProperty(string propertyName, string label, float v2, float v3)

Parameters

propertyName

The name of the shader property.

label

Label for the property.

This parameter isn't used.

This parameter isn't used.

Returns

Type

Description

floatThe 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.