# RangeProperty

> Draw a range slider for a range shader property.

## Definition

* **Type:** Method
* **Namespace:** [UnityEditor](/engine/6000.7/script-reference/unityeditor.md)
* **Assembly:** UnityEditor.CoreModule

## RangeProperty(MaterialProperty, string)

Draw a range slider for a range shader property.

```csharp
public float RangeProperty(MaterialProperty prop, string label)
```

### Parameters

**** (\[MaterialProperty]\(/engine/6000.7/script-reference/unityeditor/materialproperty)): The property to edit.**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): Label for the property.

### Returns

| Type                                                          | Description |
| ------------------------------------------------------------- | ----------- |
| [float](https://learn.microsoft.com/dotnet/api/system.single) |             |

### Remarks

To create a custom material editor, first you need to create the custom editor class and save it in the Assets/Editor folder, then reference the class name in your shader. For example:

```csharp
CustomEditor "MaterialRangePropertyExample"
```

Here is an example showing a Range slider, affecting the shader's Glossiness property:

```csharp
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( );
    }
}
```

Here is a similar example, using the Rect parameter to position and size the slider control within the custom material editor pane:

```csharp
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( );
    }
}
```

This is what the example editor pane looks like:

![MaterialEditorRangeProperty (RangeProperty)](/api/media?file=/engine/6000.7/media/images/MaterialEditorRangeProperty.png)

*Example material editor in Inspector.*

## RangeProperty(Rect, MaterialProperty, string)

Draw a range slider for a range shader property.

```csharp
public float RangeProperty(Rect position, MaterialProperty prop, string label)
```

### Parameters

**** (\[Rect]\(/engine/6000.7/script-reference/unityengine/rect)): Position and size of the range slider control.**** (\[MaterialProperty]\(/engine/6000.7/script-reference/unityeditor/materialproperty)): The property to edit.**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): Label for the property.

### Returns

| Type                                                          | Description |
| ------------------------------------------------------------- | ----------- |
| [float](https://learn.microsoft.com/dotnet/api/system.single) |             |

### Remarks

To create a custom material editor, first you need to create the custom editor class and save it in the Assets/Editor folder, then reference the class name in your shader. For example:

```csharp
CustomEditor "MaterialRangePropertyExample"
```

Here is an example showing a Range slider, affecting the shader's Glossiness property:

```csharp
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( );
    }
}
```

Here is a similar example, using the Rect parameter to position and size the slider control within the custom material editor pane:

```csharp
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( );
    }
}
```

This is what the example editor pane looks like:

![MaterialEditorRangeProperty (RangeProperty)](/api/media?file=/engine/6000.7/media/images/MaterialEditorRangeProperty.png)

*Example material editor in Inspector.*

## RangeProperty(string, string, float, float)

Draw a range slider for a range shader property.

> **Warning:**
>
> **Deprecated.** Use RangeProperty with MaterialProperty instead.

```csharp
public float RangeProperty(string propertyName, string label, float v2, float v3)
```

### Parameters

**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): **** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): Label for the property.**** (\[float]\(https\://learn.microsoft.com/dotnet/api/system.single)): **** (\[float]\(https\://learn.microsoft.com/dotnet/api/system.single)):&#x20;

### Returns

| Type                                                          | Description |
| ------------------------------------------------------------- | ----------- |
| [float](https://learn.microsoft.com/dotnet/api/system.single) |             |

### Remarks

To create a custom material editor, first you need to create the custom editor class and save it in the Assets/Editor folder, then reference the class name in your shader. For example:

```csharp
CustomEditor "MaterialRangePropertyExample"
```

Here is an example showing a Range slider, affecting the shader's Glossiness property:

```csharp
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( );
    }
}
```

Here is a similar example, using the Rect parameter to position and size the slider control within the custom material editor pane:

```csharp
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( );
    }
}
```

This is what the example editor pane looks like:

![MaterialEditorRangeProperty (RangeProperty)](/api/media?file=/engine/6000.7/media/images/MaterialEditorRangeProperty.png)

*Example material editor in Inspector.*
