Unity 에디터에서 머티리얼 프로퍼티가 인스펙터 창에 표시되는 방식을 제어할 수 있습니다. 가장 쉬운 방법은 MaterialPropertyDrawer를 사용하는 것입니다.
더 복잡한 요구 사항의 경우 MaterialEditor, MaterialProperty 및 ShaderGUI 클래스를 사용할 수 있습니다.
커스텀 에디터를 사용하여 Unity가 기본 머티리얼 인스펙터를 사용해서는 표시할 수 없는 데이터 유형을 표시하거나, 커스텀 컨트롤 또는 데이터 확인을 정의할 수 있습니다.
ShaderLab에서 모든 렌더 파이프라인에 커스텀 에디터를 할당할 수 있습니다. 이렇게 하려면 Shader 블록 안에 CustomEditor 블록을 배치할 수 있습니다. 스크립터블 렌더 파이프라인에 따라 Shader 블록 안에 CustomEditorForRenderPipeline 블록을 배치하여 렌더 파이프라인에 대해 다른 커스텀 에디터를 할당할 수도 있습니다. 코드에 CustomEditor 블록과 CustomEditorForRenderPipeline 블록이 모두 포함된 경우 렌더 파이프라인의 특정 블록이 CustomEditor 블록을 오버라이드합니다.
특정 셰이더 오브젝트를 나타내는 셰이더 에셋의 커스텀 에디터를 정의하려면 ShaderGUI 클래스에서 상속하는 스크립트를 생성하십시오. 스크립트를 Assets 폴더 안의 Editor 폴더에 넣습니다.
스크립트는 다음 포맷을 준수해야 합니다.
using UnityEditor;
public class ExampleShaderGUI : ShaderGUI
{
public override void OnGUI (MaterialEditor materialEditor, MaterialProperty[] properties)
{
// Custom code that controls the appearance of the Inspector goes here
base.OnGUI (materialEditor, properties);
}
}
이 예시 코드는 CustomEditor 블록을 사용하는 셰이더 에셋에 기본 커스텀 에디터를 지정한 다음, CustomEditorForRenderPipeline 블록을 사용하는 특정 렌더 파이프라인 에셋에 추가 커스텀 에디터를 두 개 지정하는 구문을 나타냅니다.
Shader "Examples/UsesCustomEditor"
{
// The Unity Editor uses the class ExampleCustomEditor to configure the Inspector for this shader asset
CustomEditor "ExampleShaderGUI"
CustomEditorForRenderPipeline "ExampleRenderPipelineShaderGUI" "ExampleRenderPipelineAsset"
CustomEditorForRenderPipeline "OtherExampleRenderPipelineShaderGUI" "OtherExampleRenderPipelineAsset"
SubShader
{
// Code that defines the SubShader goes here.
Pass
{
// Code that defines the Pass goes here.
}
}
}