using UnityEngine;
using UnityEditor;
public class AhzkwidToonInspector : ShaderGUI
{
public enum _RM
{
Opaque, Cutout, Transparent
}
public enum _BM
{
None, ext, Body, Hair, Cloth
}
public enum _CM
{
Back, None, Front
}
public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] properties)
{
MaterialProperty _RenderMode
, _BlendMode
, _MainTex
, _ColorTex
, _Color
, _EmissionTex
, _EmissionColor
, _Hue
, _Sat
, _Val
, _Contrast
, _outline_width
, _OutlineTex
, _OutlineMask
, _OutlineColor
, _Metallic
, _ColorRamp
, _CullingMode
, _OutlineSat;
_RenderMode = FindProperty("_RenderMode", properties);
_BlendMode = FindProperty("_BlendMode", properties);
_MainTex = FindProperty("_MainTex", properties);
_ColorTex = FindProperty("_ColorTex", properties);
_Color = FindProperty("_Color", properties);
_EmissionTex = FindProperty("_EmissionTex", properties);
_EmissionColor = FindProperty("_EmissionColor", properties);
_Hue = FindProperty("_Hue", properties);
_Sat = FindProperty("_Sat", properties);
_Val = FindProperty("_Val", properties);
_Contrast = FindProperty("_Contrast", properties);
_outline_width = FindProperty("_outline_width", properties);
_OutlineTex = FindProperty("_OutlineTex", properties);
_OutlineMask = FindProperty("_OutlineMask", properties);
_OutlineColor = FindProperty("_OutlineColor", properties);
_Metallic = FindProperty("_Metallic", properties);
_ColorRamp = FindProperty("_ColorRamp", properties);
_CullingMode = FindProperty("_CullingMode", properties);
_OutlineSat = FindProperty("_OutlineSat", properties);
// render the default gui
Material targetMat = materialEditor.target as Material;
// see if redify is set, and show a checkbox
EditorGUI.BeginChangeCheck();
{
EditorGUIUtility.labelWidth = 0f;//컬러위치
targetMat.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
targetMat.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
//targetMat.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero);
materialEditor.ShaderProperty(_RenderMode, new GUIContent("Render Mode"));
//materialEditor.ShaderProperty(_BlendMode, new GUIContent("Blend Mode", "Blend Mode"));
GUILayout.Label("Main Maps", EditorStyles.boldLabel);
materialEditor.TexturePropertySingleLine(new GUIContent("Main Texture", "Blend Color Texture"), _MainTex, _BlendMode);
EditorGUI.indentLevel = 1; //얼마나 오른쪽으로 이동시킬지
switch ((_BM)_BlendMode.floatValue)
{
case _BM.None:
break;
case _BM.ext:
materialEditor.TexturePropertySingleLine(new GUIContent("Blend Color", "Blend Color Texture"), _ColorTex, _Color);
materialEditor.TexturePropertySingleLine(new GUIContent("Emission Color", "Emission Color Texture"), _EmissionTex, _EmissionColor);
break;
case _BM.Body:
break;
case _BM.Hair:
break;
case _BM.Cloth:
break;
default:
break;
}
switch ((_BM)_BlendMode.floatValue)
{
case _BM.None:
break;
default:
materialEditor.ShaderProperty(_Hue, new GUIContent("Hue"));
materialEditor.ShaderProperty(_Sat, new GUIContent("Sat"));
materialEditor.ShaderProperty(_Val, new GUIContent("Val"));
break;
}
switch ((_BM)_BlendMode.floatValue)
{
case _BM.None:
break;
case _BM.ext:
materialEditor.ShaderProperty(_Contrast, new GUIContent("Contrast"));
materialEditor.ShaderProperty(_Metallic, new GUIContent("Metallic"));
materialEditor.ShaderProperty(_ColorRamp, new GUIContent("ColorRamp"));
break;
case _BM.Body:
break;
case _BM.Hair:
break;
case _BM.Cloth:
break;
default:
break;
}
EditorGUI.indentLevel = 0;
EditorGUILayout.Space();
GUILayout.Label("Outline", EditorStyles.boldLabel);
materialEditor.ShaderProperty(_outline_width, new GUIContent("Outline Width"));
if(_outline_width.floatValue>0)
{
EditorGUI.indentLevel = 1; //얼마나 오른쪽으로 이동시킬지
//materialEditor.TexturePropertySingleLine(new GUIContent("Outline Color", "Outline Color Texture"), _OutlineTex, _OutlineColor);
//materialEditor.TexturePropertySingleLine(new GUIContent("Outline Color", "Outline Color Texture"), _OutlineColor);
materialEditor.TexturePropertySingleLine(new GUIContent("Outline Mask", "Outline Mask Texture"), _OutlineMask);
materialEditor.ShaderProperty(_OutlineSat, new GUIContent("Outline Sat"));
EditorGUI.indentLevel = 0; //얼마나 오른쪽으로 이동시킬지
}
switch ((_BM)_BlendMode.floatValue)
{
case _BM.None:
break;
case _BM.ext:
break;
case _BM.Body:
break;
case _BM.Hair:
break;
case _BM.Cloth:
break;
default:
break;
}
switch ((_RM)_RenderMode.floatValue)
{
case _RM.Opaque:
break;
case _RM.Cutout:
break;
case _RM.Transparent:
break;
default:
break;
}
materialEditor.ShaderProperty(_CullingMode,new GUIContent("Culling Mode", "Outline Mask Texture"));
switch ((_CM)_CullingMode.floatValue)
{
case _CM.Back:
break;
case _CM.None:
break;
case _CM.Front:
break;
default:
break;
}
EditorGUILayout.Space();
//materialEditor.RenderQueueField();
//materialEditor.EnableInstancingField();
//materialEditor.DoubleSidedGIField();
//base.OnGUI(materialEditor, properties);
}
}
}
AhzkwidToonShader에 포함된 예제
public enum _RM
{
Default, Overlay
}
public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] properties)
{
//쉐이더 프로퍼티들을 불러옴
MaterialProperty _RenderMode = FindProperty(nameof(_RenderMode), properties);
MaterialProperty _MainTex = FindProperty(nameof(_MainTex), properties);
//인스펙터 변경사항이 있는지 체크하는거, 필수는 아님
EditorGUI.BeginChangeCheck();
{
//해당 변수의 값을 읽어옴
switch ((_RM)_RenderMode.floatValue)
{
case _RM.Default:
//행동1
break;
case _RM.Overlay:
//행동2
break;
default:
break;
}
//일반 인스펙터 (참조변수가 앞에 있는게 특징이다)
materialEditor.ShaderProperty(_RenderRange, "Render Range");
//텍스처 인스펙터 (GuIContent를 써서 설명도 같이 넣고 있다. 그냥 문자열로 넣어도 됨)
materialEditor.TexturePropertySingleLine(new GUIContent("Main Texture", "Default Texture"), _MainTex);
}
}
들여쓰기
EditorGUI.indentLevel = 1; //얼마나 오른쪽으로 이동시킬지
{
var guiContent=new GUIContent("Main Texture(변수명)", "Default Texture(설명)");
materialEditor.TexturePropertySingleLine(guiContent, _MainTex);
}
EditorGUI.indentLevel = 0; //얼마나 오른쪽으로 이동시킬지
헤더+들여쓰기
//헤더
GUILayout.Label("헤더", EditorStyles.boldLabel);
{
//들여쓰기
EditorGUI.indentLevel = 1; //얼마나 오른쪽으로 이동시킬지
{
materialEditor.ShaderProperty(_Value1, "인스펙터1");
materialEditor.ShaderProperty(_Value2, "인스펙터2");
materialEditor.ShaderProperty(_Value3, "인스펙터3");
materialEditor.ShaderProperty(_Value4, "인스펙터4");
}
EditorGUI.indentLevel = 0;
}
렌더큐옵션
EditorGUILayout.Space();
EditorGUILayout.Space();
materialEditor.RenderQueueField();
어스밴스 옵션
EditorGUILayout.Space();
EditorGUILayout.Space();
GUILayout.Label("Advanced Oprions", EditorStyles.boldLabel);
{
materialEditor.EnableInstancingField();
materialEditor.DoubleSidedGIField();
}
쉐이더 코드에 다음과같이 넣어줘야 작동한다
FallBack은 필수는 아니고 쉐이더 미싱일때 작동하는거
SubShader
{
FallBack "Diffuse" //기본마테리얼
CustomEditor "AhzkwidToonInspector" //커스텀인스펙터
}
'Unity > shader' 카테고리의 다른 글
모션블러 종류 (1) | 2021.03.02 |
---|---|
스텐실 (0) | 2021.01.20 |
자주쓰는 유니티 쉐이더 코드모음 (0) | 2020.11.04 |