UnityShaderGUI notes
ShaderGUI notes
0. Effect
Foldable and expandable, customizable layout
1. First make a Shader. Handwriting, SG, or ASE will all work. Node names must be standardized!
Open the Shader code and add at the end
CustomEditor "这里是你创建的C#脚本的名字(类名)"
//这样就可以关联在一起了 位置随意 不用填写路径 注意:要放在大括号里面
2. Create a C# script
Inherited from ShaderGUI class
// 自定义类名 Shader 关联用的就是这个名字
public class ShaderGUI01 : ShaderGUI
{
}
3. Canvas drawing
//重写 OnGUI类
public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] properties)
{
//这里放UI的代码
}
4. Commonly used APIs
Layout class (used in OnGUI class)
//创建一个矩形方框作为画布 读取自定义的宽高、标题、样式
GUI.Box(rect, title, style);
//创建一个矩形 可自定义位置 偏移值 长宽
var ToggleRect = new Rect(rect.x + 4f, rect.y + 4f, 20f, 20f);
//垂直布局 这里的参数可以按需选择
EditorGUILayout.BeginVertical(EditorStyles.helpBox);
//垂直布局结束
EditorGUILayout.EndVertical();
//相当于 花括号 { }
//必须成对使用
//可以套娃
//水平布局