源战役客户端
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.

206 lines
8.0 KiB

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