源战役客户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

202 lines
7.6 KiB

  1. using UnityEngine;
  2. using UnityEditor;
  3. public class CombineModelEffectLow : ShaderGUI
  4. {
  5. Material target;
  6. MaterialEditor editor;
  7. MaterialProperty[] properties;
  8. static GUIContent staticLabel = new GUIContent();
  9. bool checkFresnel = false;
  10. bool checkOutline = false;
  11. public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] properties)
  12. {
  13. // base.OnGUI(materialEditor, properties);
  14. this.target = materialEditor.target as Material;
  15. this.editor = materialEditor;
  16. this.properties = properties;
  17. GUILayout.Label("本特效材质至多支持一个UVRoll效果+一个Scan效果", EditorStyles.boldLabel);
  18. GUILayout.Space(20);
  19. DoEffectMask();
  20. DoUVRoll();
  21. DoScan();
  22. DoFresnel();
  23. DoOutline();
  24. }
  25. // uvroll
  26. void DoUVRoll()
  27. {
  28. GUILayout.Label("UVRoll 效果参数", EditorStyles.boldLabel);
  29. // 检查参数,优化editor视图
  30. EditorGUI.BeginChangeCheck();
  31. MaterialProperty uvRollTex = FindProperty("_UVRollTex");
  32. editor.TexturePropertySingleLine(
  33. MakeLabel(uvRollTex, "(RGBA)"), uvRollTex);
  34. editor.TextureScaleOffsetProperty(uvRollTex);
  35. if(uvRollTex.textureValue != null)
  36. {
  37. MaterialProperty uvrollColor1 = FindProperty("_UVRollColor1");
  38. MaterialProperty uvrollSpeed = FindProperty("_UVRollSpeed");
  39. MaterialProperty uvrollIntensity1 = FindProperty("_UVRollIntensity1");
  40. EditorGUI.indentLevel += 1;
  41. editor.ShaderProperty(uvrollColor1, MakeLabel(uvrollColor1));
  42. GUILayout.Label("整合UVRoll速度,x y代表u v速度", EditorStyles.boldLabel);
  43. editor.ShaderProperty(uvrollSpeed, MakeLabel(uvrollSpeed));
  44. GUILayout.Space(-10);
  45. editor.ShaderProperty(uvrollIntensity1, MakeLabel(uvrollIntensity1));
  46. EditorGUI.indentLevel -= 1;
  47. }
  48. if (EditorGUI.EndChangeCheck()) {
  49. // SetKeyword("_ROLLADD_MAP", uvRollTex.textureValue);
  50. }
  51. GUILayout.Space(20);
  52. DoUVRollNoise();
  53. }
  54. void DoUVRollNoise()
  55. {
  56. GUILayout.Label("UVRoll效果扰动纹理", EditorStyles.boldLabel);
  57. EditorGUI.BeginChangeCheck();
  58. MaterialProperty noise = FindProperty("_UVRollNoiseTex");
  59. editor.TexturePropertySingleLine(MakeLabel(noise), noise);
  60. if(noise.textureValue != null)
  61. {
  62. MaterialProperty uvrollNoiseSpeed = FindProperty("_UVRollNoiseSpeed");
  63. MaterialProperty uvrollNoiseIntensity = FindProperty("_UVRollNoiseIntensity");
  64. EditorGUI.indentLevel += 1;
  65. GUILayout.Label("整合Noise速度,x y代表u v速度", EditorStyles.boldLabel);
  66. editor.ShaderProperty(uvrollNoiseSpeed, MakeLabel(uvrollNoiseSpeed));
  67. GUILayout.Space(-10);
  68. editor.ShaderProperty(uvrollNoiseIntensity, MakeLabel(uvrollNoiseIntensity));
  69. EditorGUI.indentLevel -= 1;
  70. }
  71. if (EditorGUI.EndChangeCheck()) {
  72. SetKeyword("_ROLLADD_NOISE_MASK_MAP", noise.textureValue);
  73. }
  74. GUILayout.Space(20);
  75. }
  76. void DoEffectMask()
  77. {
  78. GUILayout.Label("特效遮罩(每个特效至多两种,RG通道为UVRoll遮罩,BA通道为扫描图遮罩)", EditorStyles.boldLabel);
  79. EditorGUI.BeginChangeCheck();
  80. MaterialProperty mask = FindProperty("_EffectMaskTex");
  81. editor.TexturePropertySingleLine(MakeLabel(mask), mask);
  82. if(mask.textureValue != null)
  83. {
  84. MaterialProperty uvrollMaskSpeed = FindProperty("_UVRollMaskSpeed");
  85. EditorGUI.indentLevel += 1;
  86. GUILayout.Label("整合UVRollMask速度,x y代表u v速度", EditorStyles.boldLabel);
  87. editor.ShaderProperty(uvrollMaskSpeed, MakeLabel(uvrollMaskSpeed));
  88. EditorGUI.indentLevel -= 1;
  89. }
  90. if (EditorGUI.EndChangeCheck()) {
  91. // SetKeyword("_EFFECT_MASK_MAP", mask.textureValue);
  92. }
  93. }
  94. // 扫描效果
  95. void DoScan()
  96. {
  97. GUILayout.Label("Scan扫描效果(网格纹理/扫描纹理 占用RG通道)", EditorStyles.boldLabel);
  98. EditorGUI.BeginChangeCheck();
  99. MaterialProperty scan = FindProperty("_ScanTex");
  100. editor.TexturePropertySingleLine(
  101. MakeLabel(scan, "(GR通道)"), scan,
  102. FindProperty("_ScanColor"));
  103. if(scan.textureValue != null)
  104. {
  105. MaterialProperty scan_gridline_st = FindProperty("_GridlineST");
  106. MaterialProperty scan_intensity = FindProperty("_ScanIntensity");
  107. MaterialProperty scan_speed = FindProperty("_ScanSpeed");
  108. EditorGUI.indentLevel += 1;
  109. GUILayout.Label("用这个网格图原先的纹理Tilling和Offset", EditorStyles.boldLabel);
  110. editor.ShaderProperty(scan_gridline_st, MakeLabel(scan_gridline_st));
  111. GUILayout.Space(-10);
  112. editor.ShaderProperty(scan_intensity, MakeLabel(scan_intensity));
  113. editor.ShaderProperty(scan_speed, MakeLabel(scan_speed));
  114. EditorGUI.indentLevel -= 1;
  115. }
  116. if (EditorGUI.EndChangeCheck()) {
  117. // SetKeyword("_SCAN_TEX", scan.textureValue);
  118. }
  119. GUILayout.Space(20);
  120. }
  121. // fresnel
  122. void DoFresnel()
  123. {
  124. GUILayout.Label("Fresnel外发光", EditorStyles.boldLabel);
  125. checkFresnel = IsKeywordEnabled("_MB_FRESNEL");
  126. EditorGUI.BeginChangeCheck();
  127. checkFresnel = EditorGUILayout.Toggle("Enable Fresnel", checkFresnel);
  128. if(checkFresnel)
  129. {
  130. MaterialProperty fresnelColor = FindProperty("_FresnelColor");
  131. MaterialProperty fresnelIntensity = FindProperty("_FresnelIntensity");
  132. EditorGUI.indentLevel += 1;
  133. editor.ShaderProperty(fresnelColor, MakeLabel(fresnelColor));
  134. editor.ShaderProperty(fresnelIntensity, MakeLabel(fresnelIntensity));
  135. EditorGUI.indentLevel -= 1;
  136. }
  137. if (EditorGUI.EndChangeCheck()) {
  138. SetKeyword("_MB_FRESNEL", checkFresnel);
  139. }
  140. GUILayout.Space(20);
  141. }
  142. void DoOutline()
  143. {
  144. GUILayout.Label("受击描边颜色", EditorStyles.boldLabel);
  145. MaterialProperty outlineColor = FindProperty("_OutlineColor");
  146. MaterialProperty outlineIntensity = FindProperty("_OutlineIntensity");
  147. editor.ShaderProperty(outlineColor, MakeLabel(outlineColor));
  148. editor.ShaderProperty(outlineIntensity, MakeLabel(outlineIntensity));
  149. GUILayout.Space(20);
  150. }
  151. // 利用方法优化GUI代码结构,使得代码更容易看
  152. MaterialProperty FindProperty(string name)
  153. {
  154. return FindProperty(name, properties);
  155. }
  156. static GUIContent MakeLabel(string text, string tooltip = null)
  157. {
  158. staticLabel.text = text;
  159. staticLabel.tooltip = tooltip;
  160. return staticLabel;
  161. }
  162. static GUIContent MakeLabel(MaterialProperty property, string tooltip = null)
  163. {
  164. staticLabel.text = property.displayName;
  165. staticLabel.tooltip = tooltip;
  166. return staticLabel;
  167. }
  168. // 设置shader关键字
  169. void SetKeyword(string keyword, bool state)
  170. {
  171. if(state)
  172. {
  173. foreach(Material m in editor.targets)
  174. {
  175. m.EnableKeyword(keyword);
  176. }
  177. }
  178. else{
  179. foreach(Material m in editor.targets)
  180. {
  181. m.DisableKeyword(keyword);
  182. }
  183. }
  184. }
  185. bool IsKeywordEnabled(string keyword)
  186. {
  187. return target.IsKeywordEnabled(keyword);
  188. }
  189. void RecordAction(string label)
  190. {
  191. editor.RegisterPropertyChangeUndo(label);
  192. }
  193. }