34 lines
1.1 KiB
C#
34 lines
1.1 KiB
C#
using UnityEngine;
|
|
using UnityEditor;
|
|
public class FlowToggleShaderGui : ShaderGUI
|
|
{
|
|
public const string flowKeyword = "UseFlowColor";
|
|
|
|
public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] properties)
|
|
{
|
|
// render the default gui
|
|
base.OnGUI(materialEditor, properties);
|
|
var targetMat = (Material)materialEditor.target;
|
|
FlowProcess(targetMat);
|
|
}
|
|
|
|
public static void FlowProcess(Material targetMat)
|
|
{
|
|
CreateGuiToggle("使用流光", flowKeyword, targetMat);
|
|
}
|
|
|
|
public static void CreateGuiToggle(string label, string keyword, Material targetMat)
|
|
{
|
|
var hasKeyword = System.Array.IndexOf(targetMat.shaderKeywords, keyword) >= 0;
|
|
EditorGUI.BeginChangeCheck();
|
|
hasKeyword = EditorGUILayout.Toggle(label, hasKeyword);
|
|
if (EditorGUI.EndChangeCheck())
|
|
{
|
|
// enable or disable the keyword based on checkbox
|
|
if (hasKeyword)
|
|
targetMat.EnableKeyword(keyword);
|
|
else
|
|
targetMat.DisableKeyword(keyword);
|
|
}
|
|
}
|
|
} |