Version: 2021.1
언어: 한국어
public float RangeProperty (MaterialProperty prop, string label);
public float RangeProperty (Rect position, MaterialProperty prop, string label);

파라미터

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

설명

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:

 CustomEditor "MaterialRangePropertyExample"

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

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:

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.

Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961