前言:写shader的时候,一旦参数多起来,就感觉一大串超级长超级难看,所以在此学习一下别的大佬些的GUI。
    1:模仿目标是熊猫的shaderGUI
    image.png
    看了一下GUI文件,5000多行。。超级长,加上不是特别熟练,很多都看不太懂,看来是不能一下子全部实现,,,没办法,先定个小目标,只实现基础设置这一个模块。
    image.png
    第一段,自定义下拉菜单的形状属性

    1. //自定义下拉菜单的形状属性
    2. static bool Foldout(bool display, string title)
    3. {
    4. var style = new GUIStyle("ShurikenModuleTitle");
    5. style.font = new GUIStyle(EditorStyles.boldLabel).font;
    6. style.border = new RectOffset(15, 7, 4, 4);
    7. style.fixedHeight = 22;
    8. style.contentOffset = new Vector2(20f, -2f);
    9. style.fontSize = 11;
    10. style.normal.textColor = new Color(0.7f, 0.8f, 0.9f);
    11. var rect = GUILayoutUtility.GetRect(16f, 25f, style);
    12. GUI.Box(rect, title, style);
    13. var e = Event.current;
    14. var toggleRect = new Rect(rect.x + 4f, rect.y + 2f, 13f, 13f);
    15. if (e.type == EventType.Repaint)
    16. {
    17. EditorStyles.foldout.Draw(toggleRect, false, false, display, false);
    18. }
    19. if (e.type == EventType.MouseDown && rect.Contains(e.mousePosition))
    20. {
    21. display = !display;
    22. e.Use();
    23. }
    24. return display;
    25. }

    好了,一开始就遇到不懂的问题了(不愧是我)
    看到第一行定义了style,这里有一个GUIStyle不是很清楚是干嘛的,看起来像是新建一个什么东东。这时候就到百度上场了!

    1. var style = new GUIStyle("ShurikenModuleTitle");

    上链接!
    https://blog.csdn.net/u011428080/article/details/106676213
    GUIStyle可以new一个全新的实例,这样,需要自己处理所有自己需要的效果。
    GUIStyle还可以基于已经存在的实例new一个新的实例,这样,只需对原有的效果中不符合自己需求的进行修改(省事省力,这类情况是我们最常用的),譬如:

    1. GUIStyle btnStyle = new GUIStyle("Command");
    2. btnStyle.fontSize = 12;
    3. btnStyle.alignment = TextAnchor.MiddleCenter;
    4. btnStyle.imagePosition = ImagePosition.ImageAbove;
    5. btnStyle.fontStyle = FontStyle.Normal;
    6. btnStyle.fixedWidth = 60;
    7. //等同于:
    8. GUIStyle btnStyle_1 = new GUIStyle("Command")
    9. {
    10. fontSize = 12,
    11. alignment = TextAnchor.MiddleCenter,
    12. imagePosition = ImagePosition.ImageAbove,
    13. fontStyle = FontStyle.Normal,
    14. fixedWidth = 60
    15. };

    那么到底怎么从内置的GUIStyle中找到自己想要的呢?

    AssetStore里曾经有一个名为“Edior Style Viewer”的插件可以预览内置的所有GUIStyle,但是该插件已经下架。其实我们可以自己写一个脚本去查看,因为遍历 GUI.skin.customStyles 可以取到所有的内置GUIStyle,先上效果图:
    image.png
    (名字这一列是可以被选中复制的)
    话不多说,Editor下的代码如下:

    1. using UnityEngine;
    2. using UnityEditor;
    3. public class GUIStyleViewer : EditorWindow {
    4. Vector2 scrollPosition = new Vector2(0,0);
    5. string search = "";
    6. GUIStyle textStyle;
    7. private static GUIStyleViewer window;
    8. [MenuItem("Tool/GUIStyleViewer", false, 10)]
    9. private static void OpenStyleViewer()
    10. {
    11. window = GetWindow<GUIStyleViewer>(false, "内置GUIStyle");
    12. }
    13. void OnGUI()
    14. {
    15. if (textStyle == null)
    16. {
    17. textStyle = new GUIStyle("HeaderLabel");
    18. textStyle.fontSize = 25;
    19. }
    20. GUILayout.BeginHorizontal("HelpBox");
    21. GUILayout.Label("结果如下:", textStyle);
    22. GUILayout.FlexibleSpace();
    23. GUILayout.Label("Search:");
    24. search = EditorGUILayout.TextField(search);
    25. GUILayout.EndHorizontal();
    26. GUILayout.BeginHorizontal("PopupCurveSwatchBackground");
    27. GUILayout.Label("样式展示", textStyle, GUILayout.Width(300));
    28. GUILayout.Label("名字", textStyle, GUILayout.Width(300));
    29. GUILayout.EndHorizontal();
    30. scrollPosition = GUILayout.BeginScrollView(scrollPosition);
    31. foreach (var style in GUI.skin.customStyles)
    32. {
    33. if (style.name.ToLower().Contains(search.ToLower()))
    34. {
    35. GUILayout.Space(15);
    36. GUILayout.BeginHorizontal("PopupCurveSwatchBackground");
    37. if (GUILayout.Button(style.name, style, GUILayout.Width(300)))
    38. {
    39. EditorGUIUtility.systemCopyBuffer = style.name ;
    40. Debug.LogError(style.name);
    41. }
    42. EditorGUILayout.SelectableLabel(style.name, GUILayout.Width(300));
    43. GUILayout.EndHorizontal();
    44. }
    45. }
    46. GUILayout.EndScrollView();
    47. }
    48. }

    感觉这也算是一个标准的GUI文件了,可以参考这个格式。

    1. using System.Collections.Generic;
    2. using UnityEngine;
    3. using UnityEditor;
    4. using System.Linq;
    5. public class CustomShaderGUI : ShaderGUI
    6. {
    7. override public void OnGUI(MaterialEditor materialEditor, MaterialProperty[] properties)
    8. {
    9. // 使用默认GUI渲染着色器属性
    10. base.OnGUI(materialEditor, properties);
    11. // 从材料中获取当前的关键字
    12. Material targetMat = materialEditor.target as Material;
    13. string[] keyWords = targetMat.shaderKeywords;
    14. // 查看是否设置了重新设置,然后显示一个复选框
    15. bool redify = keyWords.Contains("REDIFY_ON");
    16. EditorGUI.BeginChangeCheck();
    17. redify = EditorGUILayout.Toggle("Redify material", redify);
    18. if (EditorGUI.EndChangeCheck())
    19. {
    20. // 如果复选框更改,请重置着色器关键字
    21. var keywords = new List<string> { redify ? "REDIFY_ON" : "REDIFY_OFF" };
    22. targetMat.shaderKeywords = keywords.ToArray();
    23. EditorUtility.SetDirty(targetMat);
    24. }
    25. }
    26. }

    在官网翻到ShaderGUI的介绍,感觉这个才是常规操作?
    image.png
    直接套用,在shader面板上多了Redify material,看来这个是可以使用的,但是使用方法还需要研究一下。
    现在还是先回到熊猫的GUI上面来。
    直接在官方API可以查到GUIStyle这个函数的作用。
    image.png
    好!现在局势明朗起来了!实现之后可以尝试diy一下这些属性~
    image.png
    有一段感觉是比较重要的
    image.png
    EventType.Repaint
    UnityGui输入和处理事件的类型。
    用它来判断GUI中发生了哪种类型的事件。事件的类型包括鼠标单击,鼠标拖动,按钮按下,鼠标进入或退出窗口以及滚动轮以及下面提到的其他事件。
    下面是官方给出的代码,看起来是根据我们鼠标的点击,输出不同的结果

    1. //将此脚本附加到游戏对象
    2. //该脚本是一些可用的事件类型的基本概述。它根据当前事件类型输出消息。
    3. using UnityEngine;
    4. public class Example : MonoBehaviour
    5. {
    6. void OnGUI()
    7. {
    8. Event m_Event = Event.current;
    9. if (m_Event.type == EventType.MouseDown)
    10. {
    11. Debug.Log("Mouse Down.");
    12. }
    13. if (m_Event.type == EventType.MouseDrag)
    14. {
    15. Debug.Log("Mouse Dragged.");
    16. }
    17. if (m_Event.type == EventType.MouseUp)
    18. {
    19. Debug.Log("Mouse Up.");
    20. }
    21. }
    22. }

    在熊猫GUI的里还有2个下拉菜单的形状属性,这里就不贴出来了。
    image.png
    下一步、跳过跳过~跳了几百行代码…因为我们只实现“基础设置下拉菜单”,所以跳过了非常多的代码~
    然后基本到最后阶段了,在脚本里加上这个方法之后,就可以在shader面板里面看到我们想要的结果了。接下来就是详细的解析一遍这些代码。image.png
    image.pngSnipaste_2022-06-06_10-36-20.png
    这一步之后基本就是重复的结构了。
    有个小问题:
    不知道为什么熊猫的shader里面,他的主帖图会有Tilling和Offset
    image.png
    其实就是少了这一句,芜湖~
    image.png

    贴一下复刻的最终效果
    image.png

    1. Shader "Songao/FlowMaskGUITest"
    2. {
    3. Properties
    4. {
    5. [Enum(UnityEngine.Rendering.CullMode)]_Cullmode("Cullmode", Float) = 0
    6. [Enum(UnityEngine.Rendering.CompareFunction)]_Ztest("Ztest", Float) = 4
    7. [Enum(UnityEngine.Rendering.BlendMode)]_Scr("Scr", Float) = 5
    8. [Enum(UnityEngine.Rendering.BlendMode)]_Dst("Dst", Float) = 10
    9. _Zwrite("Zwrite", Float) = 0
    10. _MainTex("_MainTex" , 2D)= "white"{}//主贴图
    11. [HideInInspector]_MainTex_ST("MainTex_ST", Vector) = (1,1,0,0)
    12. [HDR]_TintColor("_TintColor",Color) = (1,1,1,1)//主颜色
    13. _Intensity( "_Intensity", Range(0,10) ) = 1//颜色强度
    14. _MainFlowX("_MainFlowX",float) = 0//主贴图x轴流动
    15. _MainFlowY("_MainFlowY",float) = 0//主贴图y轴流动
    16. _NoiseTex("_NoiseTex",2D) = "white" {}//噪音贴图
    17. _NoiseScaleX( "_NoiseScaleX", float ) = 2//噪音贴图x轴缩放
    18. _NoiseScaleY( "_NoiseScaleY", float ) = 2//噪音贴图y轴缩放
    19. _NoiseFlowX( "_NoiseFlowX", float ) = 2//噪音贴图x轴流动
    20. _NoiseFlowY( "_NoiseFlowY", float ) = 2//噪音贴图x轴流动
    21. [Toggle(ADD_NO_ISECTRL)]_AddNoiseCtrl("_AddNoiseCtrl",float) = 0
    22. _NoiseCtrl("_NoiseCtrl",2D) = "Gray" {}//噪声边缘贴图
    23. _NoiseCtrlIntensity( "_NoiseCtrlIntensity", float ) = 1//噪声边缘强度
    24. _LineWidth("_LineWidth",Range(0.0,0.2)) = 0.1//边缘宽度
    25. _LineRange("_LineRange",Range(0.0,0.2)) = 0.05//边缘范围
    26. _LineChange("_LineChange",float) = 30//边缘变化
    27. _Amount("_Amount",Range(0.0,2.0)) = 0.0//边缘量
    28. _DissolveFade( "_DissolveFade", float ) = 20//溶解消失
    29. [HDR]_DissolveColor1("_DissolveColor1",Color) = (1,0,0,1)//溶解颜色1
    30. [HDR]_DissolveColor2("_DissolveColor2",Color) = (1,0,0,1)//溶解颜色2
    31. //_Smooth("Smooth" , Range(0,4)) = 2
    32. //_FloorY("FloorY" , float ) = 0
    33. }
    34. SubShader
    35. {
    36. LOD 300
    37. Tags
    38. {
    39. "Queue" = "Transparent"
    40. "IgnoreProjector" = "True"
    41. }
    42. Pass
    43. {
    44. Cull [_Cullmode]
    45. ZWrite [_Zwrite]
    46. ZTest [_Ztest]
    47. Lighting Off
    48. Fog {Mode Off}
    49. Blend [_Scr] [_Dst]
    50. CGPROGRAM
    51. //#pragma shader_feature _AddNoiseCtrl_ON
    52. #pragma multi_compile __ ADD_NO_ISECTRL
    53. #pragma vertex vert
    54. #pragma fragment frag
    55. #pragma multi_compile_fog
    56. #pragma fragmentoption APB_precision_hint_faster
    57. #include "UnityCG.cginc"
    58. sampler2D _MainTex;
    59. half4 _MainTex_ST;
    60. sampler2D _NoiseTex;
    61. sampler2D _NoiseCtrl;
    62. half _NoiseCtrlIntensity;
    63. half4 _NoiseTex_ST;
    64. fixed _Amount;
    65. fixed4 _DissolveColor1;
    66. fixed4 _DissolveColor2;
    67. fixed _LineWidth;
    68. half _NoiseScaleX,_NoiseScaleY;
    69. half _Intensity;
    70. half4 _TintColor;
    71. half _LineRange;
    72. half _LineChange;
    73. half _NoiseFlowX,_NoiseFlowY;
    74. half _MainFlowX,_MainFlowY;
    75. half _DissolveFade;
    76. struct v2f
    77. {
    78. float4 pos : POSITION;
    79. half2 uv : TEXCOORD0;
    80. half4 color : COLOR;
    81. float4 customData1:TEXCOORD1;
    82. half4 dissolveUV:TEXCOORD2;
    83. float3 worldPos : TEXCOORD3;
    84. };
    85. v2f vert(appdata_full v)
    86. {
    87. v2f o;
    88. o.pos = UnityObjectToClipPos(v.vertex);
    89. o.uv = v.texcoord.xy * _MainTex_ST.xy + _MainTex_ST.zw;
    90. o.uv += half2(_MainFlowX,_MainFlowY) * _Time.y;
    91. o.color = v.color;
    92. o.customData1 = v.texcoord1;
    93. o.dissolveUV.xy = v.texcoord.xy * half2(_NoiseScaleX,_NoiseScaleY) + ( half2(_NoiseFlowX,_NoiseFlowY) + half2(o.customData1.y, 0) ) * _Time.y + _NoiseTex_ST.zw;
    94. o.dissolveUV.zw = v.texcoord.xy;
    95. o.worldPos = mul(unity_ObjectToWorld , v.vertex);
    96. return o;
    97. };
    98. fixed4 frag(v2f i):COLOR
    99. {
    100. fixed3 dissolve = tex2D(_NoiseTex,i.dissolveUV.xy).rgb;
    101. fixed3 dissolveCtrl = tex2D(_NoiseCtrl,i.dissolveUV.zw).rgb * 2 - 1;
    102. float vertexAlpha = 1.5 - i.customData1.x * 2;
    103. //选择是否添加额外noise
    104. #ifdef ADD_NO_ISECTRL
    105. vertexAlpha -= dissolveCtrl.g * _NoiseCtrlIntensity;
    106. #endif
    107. clip( dissolve.g - vertexAlpha);
    108. half2 customUV = i.uv + i.customData1.zw;
    109. half4 color = tex2D(_MainTex,customUV);
    110. //return color;
    111. color.rgb *= _Intensity * _TintColor.rgb * i.color.rgb;
    112. fixed t = 1 - smoothstep(0.0,_LineWidth,dissolve.r - _Amount);
    113. fixed3 dissolveColor = lerp(_DissolveColor1,_DissolveColor2,t);
    114. dissolveColor = pow(dissolveColor,5);
    115. half t2 = saturate( ( dissolve.g - vertexAlpha - _LineRange ) * _LineChange );
    116. color.rgb = lerp( dissolveColor, color.rgb, t2 );
    117. half fade = smoothstep( 0, 1 , saturate( ( dissolve.g - vertexAlpha ) * _DissolveFade ) );
    118. color.a *= _TintColor.a * i.color.a * fade;
    119. return color;
    120. //float worldY = i.worldPos.y;
    121. //_FloorY = _GlobalFloorHeight + _FloorY;
    122. //float ramp = smoothstep(_FloorY - _Smooth , _FloorY + _Smooth , worldY) ;
    123. //color.a *= _TintColor.a * i.color.a * fade ;
    124. //return color;
    125. };
    126. ENDCG
    127. }
    128. }
    129. CustomEditor "FlowMaskGUITest"
    130. }
    1. using UnityEngine;
    2. using UnityEditor;
    3. using System;
    4. public class FlowMaskGUITest : ShaderGUI
    5. {
    6. //自定义一个小按钮
    7. public GUILayoutOption[] shortButtonStyle = new GUILayoutOption[] { GUILayout.Width(100) };
    8. //自定义字体
    9. public GUIStyle style = new GUIStyle();
    10. //自定义下拉菜单的形状属性
    11. static bool Foldout(bool display, string title)
    12. {
    13. //GUIStyle可以new一个全新的实例,这样,需要自己处理所有自己需要的效果。
    14. //还可以基于已经存在的实例new一个新的实例,这样,只需对原有的效果中不符合自己需求的进行修改(省事省力,这类情况是我们最常用的)
    15. var style = new GUIStyle("ShurikenModuleTitle");
    16. //用于渲染的字体。如果为 null,则使用当前 GUISkin 的默认字体。
    17. style.font = new GUIStyle(EditorStyles.boldLabel).font;
    18. //要使用的字体大小(用于动态字体)。
    19. style.fontSize = 11;
    20. //背景图像边框
    21. style.border = new RectOffset(15, 7, 4, 4);
    22. //如果非 0,则使用此样式呈现的任何 GUI 元素都将具有此处指定的高度。
    23. style.fixedHeight = 22;
    24. //应用于此 GUIstyle 内容的像素偏移。
    25. style.contentOffset = new Vector2(20f, -2f);
    26. //组件正常显示时的渲染设置。
    27. style.normal.textColor = new Color(0.7f, 0.8f, 0.9f);
    28. //为矩形保留布局空间,用于显示具有特定样式的一些内容。
    29. var rect = GUILayoutUtility.GetRect(16f, 25f, style);
    30. //在 GUI 层上创建一个框。
    31. GUI.Box(rect, title, style);
    32. //当前正在处理的当前事件。
    33. var e = Event.current;
    34. //Rect由 X 和 Y 位置、宽度和高度定义的 2D 矩形。
    35. var toggleRect = new Rect(rect.x + 4f, rect.y + 2f, 13f, 13f);
    36. //EventType是UnityGUI 输入和处理事件的类型。
    37. //绘制下拉窗口
    38. if (e.type == EventType.Repaint)
    39. {
    40. EditorStyles.foldout.Draw(toggleRect, false, false, display, false);
    41. }
    42. if (e.type == EventType.MouseDown && rect.Contains(e.mousePosition))
    43. {
    44. display = !display;
    45. e.Use();
    46. }
    47. return display;
    48. }
    49. //自定义下拉菜单2的形状属性
    50. static bool Foldout2(bool display, string title)
    51. {
    52. var style = new GUIStyle("ShurikenModuleTitle");
    53. style.font = new GUIStyle(EditorStyles.boldLabel).font;
    54. style.border = new RectOffset(15, 7, 4, 4);
    55. style.fixedHeight = 22;
    56. style.contentOffset = new Vector2(20f, -2f);
    57. style.fontSize = 11;
    58. style.normal.textColor = new Color(0.65f, 0.55f, 0.55f);
    59. var rect = GUILayoutUtility.GetRect(16f, 25f, style);
    60. GUI.Box(rect, title, style);
    61. var e = Event.current;
    62. var toggleRect = new Rect(rect.x + 4f, rect.y + 2f, 13f, 13f);
    63. if (e.type == EventType.Repaint)
    64. {
    65. EditorStyles.foldout.Draw(toggleRect, false, false, display, false);
    66. }
    67. if (e.type == EventType.MouseDown && rect.Contains(e.mousePosition))
    68. {
    69. display = !display;
    70. e.Use();
    71. }
    72. return display;
    73. }
    74. //自定义变量
    75. static bool _Base_Foldout = true;//基础设置下拉菜单,下拉列表判断
    76. static bool _Maintextures_Foldout = true;//主贴图窗口下拉菜单
    77. static bool _Disslovetextures_Foldout = true;//溶解窗口下拉菜单
    78. static bool _NoiseTexAdd = false;//额外的溶解图开关
    79. MaterialEditor m_MaterialEditor;
    80. //shader属性
    81. MaterialProperty mainTex = null;
    82. MaterialProperty NoiseTex = null;
    83. MaterialProperty NoiseCtrl = null;
    84. MaterialProperty NoiseCtrlIntensity = null;
    85. MaterialProperty Amount = null;
    86. MaterialProperty DissolveColor1 = null;
    87. MaterialProperty DissolveColor2 = null;
    88. MaterialProperty NoiseScaleX = null;
    89. MaterialProperty NoiseScaleY = null;
    90. MaterialProperty Intensity = null;
    91. MaterialProperty TintColor = null;
    92. MaterialProperty LineWidth = null;
    93. MaterialProperty LineRange = null;
    94. MaterialProperty LineChange = null;
    95. MaterialProperty NoiseFlowX = null;
    96. MaterialProperty NoiseFlowY = null;
    97. MaterialProperty MainFlowX = null;
    98. MaterialProperty MainFlowY = null;
    99. MaterialProperty DissolveFade = null;
    100. MaterialProperty AddNoiseCtrl = null;
    101. //将自定义的需要显示的属性指向shader里的相应变量
    102. public void FindProperties(MaterialProperty[] props)
    103. {
    104. //主帖图属性指向
    105. mainTex = FindProperty("_MainTex", props);
    106. NoiseTex = FindProperty("_NoiseTex", props);
    107. NoiseCtrl = FindProperty("_NoiseCtrl", props);
    108. NoiseCtrlIntensity = FindProperty("_NoiseCtrlIntensity", props);
    109. Amount = FindProperty("_Amount", props);
    110. DissolveColor1 = FindProperty("_DissolveColor1", props);
    111. DissolveColor2 = FindProperty("_DissolveColor2", props);
    112. NoiseScaleX = FindProperty("_NoiseScaleX", props);
    113. NoiseScaleY = FindProperty("_NoiseScaleY", props);
    114. Intensity = FindProperty("_Intensity", props);
    115. TintColor = FindProperty("_TintColor", props);
    116. LineWidth = FindProperty("_LineWidth", props);
    117. LineChange = FindProperty("_LineChange", props);
    118. LineRange = FindProperty("_LineRange", props);
    119. NoiseFlowX = FindProperty("_NoiseFlowX", props);
    120. NoiseFlowY = FindProperty("_NoiseFlowY", props);
    121. MainFlowX = FindProperty("_MainFlowX", props);
    122. MainFlowY = FindProperty("_MainFlowY", props);
    123. DissolveFade = FindProperty("_DissolveFade", props);
    124. AddNoiseCtrl = FindProperty("_AddNoiseCtrl", props);
    125. }
    126. //将上面定义的属性显示在面板上
    127. public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] props)
    128. {
    129. FindProperties(props);
    130. m_MaterialEditor = materialEditor;
    131. Material material = materialEditor.target as Material;
    132. //基础设置下拉菜单
    133. EditorGUILayout.BeginVertical(EditorStyles.helpBox);
    134. _Base_Foldout = Foldout(_Base_Foldout, "基础设置(BasicSettings)");
    135. if (_Base_Foldout)
    136. {
    137. EditorGUI.indentLevel++;
    138. GUI_Base(material);
    139. EditorGUI.indentLevel--;
    140. }
    141. EditorGUILayout.EndVertical();
    142. //主帖图下拉菜单
    143. if (mainTex.textureValue != null)
    144. {
    145. EditorGUILayout.BeginVertical(EditorStyles.helpBox);
    146. _Maintextures_Foldout = Foldout(_Maintextures_Foldout, "主贴图(MainTexture)");
    147. if (_Maintextures_Foldout)
    148. {
    149. EditorGUI.indentLevel++;
    150. GUI_Maintextures(material);
    151. EditorGUI.indentLevel--;
    152. }
    153. EditorGUILayout.EndVertical();
    154. }
    155. //溶解下拉菜单
    156. if (mainTex.textureValue != null)
    157. {
    158. EditorGUILayout.BeginVertical(EditorStyles.helpBox);
    159. _Disslovetextures_Foldout = Foldout(_Disslovetextures_Foldout, "溶解(Dissolve)");
    160. if (_Disslovetextures_Foldout)
    161. {
    162. EditorGUI.indentLevel++;
    163. GUI_Dissolve(material);
    164. EditorGUI.indentLevel--;
    165. }
    166. EditorGUILayout.EndVertical();
    167. }
    168. }
    169. //主帖图具体显示内容
    170. void GUI_Maintextures(Material material)
    171. {
    172. EditorGUILayout.BeginVertical(EditorStyles.helpBox);
    173. EditorGUILayout.BeginVertical(EditorStyles.helpBox);
    174. m_MaterialEditor.TexturePropertySingleLine(new GUIContent("主贴图"), mainTex, TintColor);
    175. m_MaterialEditor.TextureScaleOffsetProperty(mainTex);
    176. EditorGUILayout.EndVertical();
    177. EditorGUILayout.BeginVertical(EditorStyles.helpBox);
    178. m_MaterialEditor.ShaderProperty(Intensity, "颜色强度");
    179. GUILayout.Space(5);
    180. m_MaterialEditor.ShaderProperty(MainFlowX, "X轴流动");
    181. GUILayout.Space(5);
    182. m_MaterialEditor.ShaderProperty(MainFlowY, "Y轴流动");
    183. GUILayout.Space(5);
    184. EditorGUILayout.EndVertical();
    185. EditorGUILayout.EndVertical();
    186. }
    187. void GUI_Dissolve(Material material)
    188. {
    189. EditorGUILayout.BeginVertical(EditorStyles.helpBox);
    190. //划分一个框包裹
    191. EditorGUILayout.BeginVertical(EditorStyles.helpBox);
    192. m_MaterialEditor.TexturePropertySingleLine(new GUIContent("溶解贴图"), NoiseTex);
    193. GUILayout.Space(5);
    194. m_MaterialEditor.TextureScaleOffsetProperty(NoiseTex);
    195. EditorGUILayout.EndVertical();
    196. EditorGUILayout.BeginVertical(EditorStyles.helpBox);
    197. m_MaterialEditor.ShaderProperty(DissolveFade, "溶解消失");
    198. GUILayout.Space(5);
    199. m_MaterialEditor.ShaderProperty(DissolveColor1, "溶解颜色1");
    200. GUILayout.Space(5);
    201. m_MaterialEditor.ShaderProperty(DissolveColor2, "溶解颜色2");
    202. GUILayout.Space(5);
    203. m_MaterialEditor.ShaderProperty(NoiseScaleX, "X轴缩放");
    204. GUILayout.Space(5);
    205. m_MaterialEditor.ShaderProperty(NoiseScaleY, "Y轴缩放");
    206. GUILayout.Space(5);
    207. m_MaterialEditor.ShaderProperty(NoiseFlowX, "X轴流动");
    208. GUILayout.Space(5);
    209. m_MaterialEditor.ShaderProperty(NoiseFlowY, "Y轴流动");
    210. GUILayout.Space(5);
    211. EditorGUILayout.EndVertical();
    212. //开关判断
    213. EditorGUILayout.BeginVertical(EditorStyles.helpBox);
    214. EditorGUILayout.BeginHorizontal();
    215. EditorGUILayout.PrefixLabel("开启额外溶解图");
    216. //_NoiseTexAdd = Foldout(_NoiseTexAdd, "额外溶解图");
    217. if (material.GetFloat("_AddNoiseCtrl") == 0)
    218. {
    219. if (GUILayout.Button("已关闭", shortButtonStyle))
    220. {
    221. material.SetFloat("_AddNoiseCtrl", 1);
    222. }
    223. }
    224. else
    225. {
    226. if (GUILayout.Button("已开启", shortButtonStyle))
    227. {
    228. material.SetFloat("_AddNoiseCtrl", 0);
    229. }
    230. }
    231. EditorGUILayout.EndHorizontal();
    232. if (material.GetFloat("_AddNoiseCtrl") == 1)
    233. {
    234. m_MaterialEditor.TexturePropertySingleLine(new GUIContent("溶解边缘贴图"), NoiseCtrl);
    235. m_MaterialEditor.TextureScaleOffsetProperty(NoiseCtrl);
    236. if (NoiseCtrl.textureValue )
    237. {
    238. m_MaterialEditor.ShaderProperty(NoiseCtrlIntensity, "边缘强度");
    239. GUILayout.Space(5);
    240. m_MaterialEditor.ShaderProperty(LineWidth, "边缘宽度");
    241. GUILayout.Space(5);
    242. m_MaterialEditor.ShaderProperty(LineRange, "边缘范围");
    243. GUILayout.Space(5);
    244. m_MaterialEditor.ShaderProperty(LineChange, "边缘变化");
    245. GUILayout.Space(5);
    246. m_MaterialEditor.ShaderProperty(Amount, "边缘量");
    247. GUILayout.Space(5);
    248. }
    249. }
    250. EditorGUILayout.EndVertical();
    251. //if (_NoiseTexAdd)
    252. //{
    253. // EditorGUI.indentLevel++;
    254. // EditorGUILayout.BeginVertical(EditorStyles.helpBox);
    255. // m_MaterialEditor.TexturePropertySingleLine(new GUIContent("溶解边缘贴图"), NoiseCtrl);
    256. // m_MaterialEditor.TextureScaleOffsetProperty(NoiseCtrl);
    257. // GUILayout.Space(5);
    258. // m_MaterialEditor.ShaderProperty(NoiseCtrlIntensity, "边缘强度");
    259. // GUILayout.Space(5);
    260. // m_MaterialEditor.ShaderProperty(LineWidth, "边缘宽度");
    261. // GUILayout.Space(5);
    262. // m_MaterialEditor.ShaderProperty(LineRange, "边缘范围");
    263. // GUILayout.Space(5);
    264. // EditorGUI.indentLevel--;
    265. // EditorGUILayout.EndVertical();
    266. //}
    267. EditorGUILayout.EndVertical();
    268. }
    269. //基础设置内容显示
    270. void GUI_Base(Material material)
    271. {
    272. EditorGUILayout.BeginVertical(EditorStyles.helpBox);
    273. EditorGUILayout.BeginHorizontal();
    274. EditorGUILayout.PrefixLabel("混合模式");
    275. //shader里面的一个控制开关
    276. if (material.GetFloat("_Scr") == 1)
    277. {
    278. //Button一个按钮
    279. //shortButtonStyle、GUI布局选项尺寸
    280. if (GUILayout.Button("Add", shortButtonStyle))
    281. {
    282. //如果按下这个按钮,shader里面的参数数值则会变成我们现在所设定的样子
    283. material.SetFloat("_Scr", 5);
    284. material.SetFloat("_Dst", 10);
    285. material.SetFloat("_AlphaAdd", 0);
    286. }
    287. }
    288. else
    289. {
    290. if (GUILayout.Button("Alpha", shortButtonStyle))
    291. {
    292. material.SetFloat("_Scr", 1);
    293. material.SetFloat("_Dst", 1);
    294. material.SetFloat("_AlphaAdd", 1);
    295. }
    296. }
    297. EditorGUILayout.EndHorizontal();
    298. //在当前布局组中插入一个空间。
    299. GUILayout.Space(5);
    300. //需要搭配EditorGUILayout.EndHorizontal();
    301. //意思差不多就是在里面一段UI中加上边框背景
    302. EditorGUILayout.BeginHorizontal();
    303. EditorGUILayout.PrefixLabel("剔除模式");
    304. if (material.GetFloat("_Cullmode") == 0)
    305. {
    306. if (GUILayout.Button("双面显示", shortButtonStyle))
    307. {
    308. material.SetFloat("_Cullmode", 1);
    309. }
    310. }
    311. else
    312. {
    313. if (material.GetFloat("_Cullmode") == 1)
    314. {
    315. if (GUILayout.Button("显示背面", shortButtonStyle))
    316. {
    317. material.SetFloat("_Cullmode", 2);
    318. }
    319. }
    320. else
    321. {
    322. if (GUILayout.Button("显示正面", shortButtonStyle))
    323. {
    324. material.SetFloat("_Cullmode", 0);
    325. }
    326. }
    327. }
    328. EditorGUILayout.EndHorizontal();
    329. //if (_tips == true)
    330. //{
    331. // EditorGUILayout.BeginVertical(EditorStyles.helpBox);
    332. // style.fontSize = 10;
    333. // style.normal.textColor = new Color(0.5f, 0.5f, 0.5f);
    334. // GUILayout.Label("*包含显示正面,显示背面,双面显示三种模式", style);
    335. // EditorGUILayout.EndVertical();
    336. //}
    337. GUILayout.Space(5);
    338. EditorGUILayout.BeginHorizontal();
    339. EditorGUILayout.PrefixLabel("显示在最前层");
    340. if (material.GetFloat("_Ztest") == 4)
    341. {
    342. if (GUILayout.Button("否", shortButtonStyle))
    343. {
    344. material.SetFloat("_Ztest", 8);
    345. }
    346. }
    347. else
    348. {
    349. if (GUILayout.Button("是", shortButtonStyle))
    350. {
    351. material.SetFloat("_Ztest", 4);
    352. }
    353. }
    354. EditorGUILayout.EndHorizontal();
    355. //if (_tips == true)
    356. //{
    357. // EditorGUILayout.BeginVertical(EditorStyles.helpBox);
    358. // style.fontSize = 10;
    359. // style.normal.textColor = new Color(0.5f, 0.5f, 0.5f);
    360. // GUILayout.Label("*开启后深度测试ZTest设置为always,可以让特效显示在角色之前,避免穿模", style);
    361. // EditorGUILayout.EndVertical();
    362. //}
    363. GUILayout.Space(5);
    364. EditorGUILayout.BeginHorizontal();
    365. EditorGUILayout.PrefixLabel("写入深度");
    366. if (material.GetFloat("_Zwrite") == 0)
    367. {
    368. if (GUILayout.Button("否", shortButtonStyle))
    369. {
    370. material.SetFloat("_Zwrite", 1);
    371. }
    372. }
    373. else
    374. {
    375. if (GUILayout.Button("是", shortButtonStyle))
    376. {
    377. material.SetFloat("_Zwrite", 0);
    378. }
    379. }
    380. EditorGUILayout.EndHorizontal();
    381. EditorGUILayout.EndVertical();
    382. GUILayout.Space(5);
    383. }
    384. }