Version: 5.5 (switch to 5.6b)
LanguageEnglish
  • C#
  • JS

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

MaterialEditor.RangeProperty

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

public function RangeProperty(prop: MaterialProperty, label: string): float;
public float RangeProperty(MaterialProperty prop, string label);
public function RangeProperty(position: Rect, prop: MaterialProperty, label: string): float;
public float RangeProperty(Rect position, MaterialProperty prop, string label);

Parameters

label Label for the property.
prop The property to edit.
position Position and size of the range slider control.

Description

Draw a range slider for a range shader property.

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:

no example available in JavaScript
	CustomEditor "MaterialRangePropertyExample"

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

#pragma strict
public class MaterialRangePropertyExample extends MaterialEditor {
	public override function OnInspectorGUI() {
		serializedObject.Update();
		var matShader: SerializedProperty = serializedObject.FindProperty("m_Shader");
		if (!isVisible)return ;
		var mat: Material = target as Material;
		var Glossiness: MaterialProperty = GetMaterialProperty([mat], "_Glossiness");
		if (Glossiness == null)return ;
		EditorGUI.BeginChangeCheck();
		RangeProperty(Glossiness, "Glossiness");
		if (EditorGUI.EndChangeCheck())
			PropertiesChanged();
	}
}
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:

#pragma strict
public class MaterialRangePropertyWithRectExample extends MaterialEditor {
	public override function OnInspectorGUI() {
		serializedObject.Update();
		var matShader: SerializedProperty = serializedObject.FindProperty("m_Shader");
		if (!isVisible)return ;
		var mat: Material = target as Material;
		var Glossiness: MaterialProperty = GetMaterialProperty([mat], "_Glossiness");
		if (Glossiness == null)return ;
		EditorGUI.BeginChangeCheck();
		RangeProperty(new Rect(20, 60, 300, 20), Glossiness, "Glossiness");
		if (EditorGUI.EndChangeCheck())
			PropertiesChanged();
	}
}
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:


Example material editor in Inspector.