AllIn1SpriteShader.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479
  1. using UnityEngine;
  2. using UnityEditor;
  3. using UnityEditor.SceneManagement;
  4. using System.Linq;
  5. [CanEditMultipleObjects]
  6. public class AllIn1SpriteShader : ShaderGUI
  7. {
  8. private Material targetMat;
  9. private UnityEngine.Rendering.BlendMode srcMode, dstMode;
  10. private UnityEngine.Rendering.CompareFunction zTestMode;
  11. public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] properties)
  12. {
  13. targetMat = materialEditor.target as Material;
  14. string[] oldKeyWords = targetMat.shaderKeywords;
  15. GUIStyle style = EditorStyles.helpBox;
  16. style.margin = new RectOffset(0, 0, 0, 0);
  17. materialEditor.ShaderProperty(properties[0], properties[0].displayName);
  18. materialEditor.ShaderProperty(properties[1], properties[1].displayName);
  19. materialEditor.ShaderProperty(properties[2], properties[2].displayName);
  20. //Not needed since Unity batches sprites on its own
  21. //EditorGUILayout.Separator();
  22. //materialEditor.EnableInstancingField();
  23. //Debug.Log(materialEditor.IsInstancingEnabled() + " " + Application.isBatchMode);
  24. EditorGUILayout.Separator();
  25. Blending(materialEditor, properties, style, oldKeyWords.Contains("CUSTOMBLENDING_ON"), "Custom Blending", "CUSTOMBLENDING_ON");
  26. Billboard(materialEditor, properties, style, oldKeyWords.Contains("BILBOARD_ON"), "Bilboard active", "BILBOARD_ON");
  27. ZWrite(materialEditor, properties, style, "Depth Write");
  28. ZTest(materialEditor, properties, style, oldKeyWords.Contains("CUSTOMZTEST_ON"), "Z Test", "CUSTOMZTEST_ON");
  29. SpriteAtlas(materialEditor, style, oldKeyWords.Contains("ATLAS_ON"), "Sprite inside an atlas?", "ATLAS_ON");
  30. EditorGUILayout.Separator();
  31. GUILayout.Label("___Color Effects___", EditorStyles.boldLabel);
  32. Glow(materialEditor, properties, style, oldKeyWords.Contains("GLOW_ON"));
  33. GenericEffect(materialEditor, properties, style, oldKeyWords.Contains("FADE_ON"), "2.Fade", "FADE_ON", 7, 13);
  34. Outline(materialEditor, properties, style, oldKeyWords.Contains("OUTBASE_ON"));
  35. GenericEffect(materialEditor, properties, style, oldKeyWords.Contains("GRADIENT_ON"), "4.Gradient", "GRADIENT_ON", 31, 35);
  36. GenericEffect(materialEditor, properties, style, oldKeyWords.Contains("COLORSWAP_ON"), "5.Color Swap", "COLORSWAP_ON", 36, 42);
  37. GenericEffect(materialEditor, properties, style, oldKeyWords.Contains("HSV_ON"), "6.Hue Shift", "HSV_ON", 43, 45);
  38. GenericEffect(materialEditor, properties, style, oldKeyWords.Contains("CHANGECOLOR_ON"), "7.Change 1 Color", "CHANGECOLOR_ON", 123, 126);
  39. ColorRamp(materialEditor, properties, style, oldKeyWords.Contains("COLORRAMP_ON"));
  40. GenericEffect(materialEditor, properties, style, oldKeyWords.Contains("HITEFFECT_ON"), "9.Hit Effect", "HITEFFECT_ON", 46, 48);
  41. GenericEffect(materialEditor, properties, style, oldKeyWords.Contains("NEGATIVE_ON"), "10.Negative", "NEGATIVE_ON", 49, 49);
  42. GenericEffect(materialEditor, properties, style, oldKeyWords.Contains("PIXELATE_ON"), "11.Pixelate", "PIXELATE_ON", 50, 50);
  43. GreyScale(materialEditor, properties, style, oldKeyWords.Contains("GREYSCALE_ON"));
  44. Posterize(materialEditor, properties, style, oldKeyWords.Contains("POSTERIZE_ON"));
  45. Blur(materialEditor, properties, style, oldKeyWords.Contains("BLUR_ON"));
  46. GenericEffect(materialEditor, properties, style, oldKeyWords.Contains("MOTIONBLUR_ON"), "15.Motion Blur", "MOTIONBLUR_ON", 62, 63);
  47. GenericEffect(materialEditor, properties, style, oldKeyWords.Contains("GHOST_ON"), "16.Ghost", "GHOST_ON", 64, 65);
  48. InnerOutline(materialEditor, properties, style, oldKeyWords.Contains("INNEROUTLINE_ON"), "17.Inner Outline", "INNEROUTLINE_ON", 66, 69);
  49. GenericEffect(materialEditor, properties, style, oldKeyWords.Contains("HOLOGRAM_ON"), "18.Hologram", "HOLOGRAM_ON", 73, 77);
  50. GenericEffect(materialEditor, properties, style, oldKeyWords.Contains("CHROMABERR_ON"), "19.Chromatic Aberration", "CHROMABERR_ON", 78, 79);
  51. Glitch(materialEditor, properties, style, oldKeyWords.Contains("GLITCH_ON"), "20.Glitch", "GLITCH_ON");
  52. GenericEffect(materialEditor, properties, style, oldKeyWords.Contains("FLICKER_ON"), "21.Flicker", "FLICKER_ON", 81, 83);
  53. GenericEffect(materialEditor, properties, style, oldKeyWords.Contains("SHADOW_ON"), "22.Shadow", "SHADOW_ON", 84, 87);
  54. GenericEffect(materialEditor, properties, style, oldKeyWords.Contains("SHINE_ON"), "23.Shine", "SHINE_ON", 133, 137);
  55. GenericEffect(materialEditor, properties, style, oldKeyWords.Contains("ALPHACUTOFF_ON"), "24.Alpha Cutoff", "ALPHACUTOFF_ON", 70, 70);
  56. EditorGUILayout.Separator();
  57. GUILayout.Label("___UV Effects___", EditorStyles.boldLabel);
  58. GenericEffect(materialEditor, properties, style, oldKeyWords.Contains("DOODLE_ON"), "25.Hand Drawn", "DOODLE_ON", 88, 89);
  59. Grass(materialEditor, properties, style, oldKeyWords.Contains("WIND_ON"));
  60. GenericEffect(materialEditor, properties, style, oldKeyWords.Contains("WAVEUV_ON"), "27.Wave", "WAVEUV_ON", 94, 98);
  61. GenericEffect(materialEditor, properties, style, oldKeyWords.Contains("ROUNDWAVEUV_ON"), "28.Round Wave", "ROUNDWAVEUV_ON", 127, 128);
  62. GenericEffect(materialEditor, properties, style, oldKeyWords.Contains("RECTSIZE_ON"), "29.Rect Size (Enable wireframe to see result)", "RECTSIZE_ON", 99, 99);
  63. GenericEffect(materialEditor, properties, style, oldKeyWords.Contains("OFFSETUV_ON"), "30.Offset", "OFFSETUV_ON", 100, 101);
  64. GenericEffect(materialEditor, properties, style, oldKeyWords.Contains("CLIPPING_ON"), "31.Clipping / Fill Amount", "CLIPPING_ON", 102, 105);
  65. GenericEffect(materialEditor, properties, style, oldKeyWords.Contains("TEXTURESCROLL_ON"), "32.Texture Scroll", "TEXTURESCROLL_ON", 106, 107);
  66. GenericEffect(materialEditor, properties, style, oldKeyWords.Contains("ZOOMUV_ON"), "33.Zoom", "ZOOMUV_ON", 108, 108);
  67. GenericEffect(materialEditor, properties, style, oldKeyWords.Contains("DISTORT_ON"), "34.Distortion", "DISTORT_ON", 109, 112);
  68. GenericEffect(materialEditor, properties, style, oldKeyWords.Contains("TWISTUV_ON"), "35.Twist", "TWISTUV_ON", 113, 116);
  69. GenericEffect(materialEditor, properties, style, oldKeyWords.Contains("ROTATEUV_ON"), "36.Rotate", "ROTATEUV_ON", 117, 117);
  70. GenericEffect(materialEditor, properties, style, oldKeyWords.Contains("POLARUV_ON"), "37.Polar Coordinates (Tile texture for good results)", "POLARUV_ON", -1, -1);
  71. GenericEffect(materialEditor, properties, style, oldKeyWords.Contains("FISHEYE_ON"), "38.Fish Eye", "FISHEYE_ON", 118, 118);
  72. GenericEffect(materialEditor, properties, style, oldKeyWords.Contains("PINCH_ON"), "39.Pinch", "PINCH_ON", 119, 119);
  73. GenericEffect(materialEditor, properties, style, oldKeyWords.Contains("SHAKEUV_ON"), "40.Shake", "SHAKEUV_ON", 120, 122);
  74. }
  75. private void Blending(MaterialEditor materialEditor, MaterialProperty[] properties, GUIStyle style, bool toggle, string inspector, string flag)
  76. {
  77. MaterialProperty srcM = ShaderGUI.FindProperty("_MySrcMode", properties);
  78. MaterialProperty dstM = ShaderGUI.FindProperty("_MyDstMode", properties);
  79. if (srcM.floatValue == 0 && dstM.floatValue == 0)
  80. {
  81. srcM.floatValue = 5;
  82. dstM.floatValue = 10;
  83. }
  84. bool ini = toggle;
  85. toggle = EditorGUILayout.BeginToggleGroup(inspector, toggle);
  86. if (ini != toggle && !Application.isPlaying) EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
  87. if (toggle)
  88. {
  89. targetMat.EnableKeyword(flag);
  90. EditorGUILayout.BeginVertical(style);
  91. {
  92. GUILayout.Label("Look for 'ShaderLab: Blending' if you don't know what this is", style);
  93. srcMode = (UnityEngine.Rendering.BlendMode) srcM.floatValue;
  94. dstMode = (UnityEngine.Rendering.BlendMode) dstM.floatValue;
  95. srcMode = (UnityEngine.Rendering.BlendMode) EditorGUILayout.EnumPopup("SrcMode", srcMode);
  96. dstMode = (UnityEngine.Rendering.BlendMode) EditorGUILayout.EnumPopup("DstMode", dstMode);
  97. srcM.floatValue = (float)(srcMode);
  98. dstM.floatValue = (float)(dstMode);
  99. }
  100. EditorGUILayout.EndVertical();
  101. }
  102. else targetMat.DisableKeyword(flag);
  103. EditorGUILayout.EndToggleGroup();
  104. }
  105. private void Billboard(MaterialEditor materialEditor, MaterialProperty[] properties, GUIStyle style, bool toggle, string inspector, string flag)
  106. {
  107. bool ini = toggle;
  108. toggle = EditorGUILayout.BeginToggleGroup(inspector, toggle);
  109. if (ini != toggle && !Application.isPlaying) EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
  110. if (toggle)
  111. {
  112. targetMat.EnableKeyword(flag);
  113. EditorGUILayout.BeginVertical(style);
  114. {
  115. GUILayout.Label("Don't use this feature on UI elements!", style);
  116. materialEditor.ShaderProperty(properties[129], properties[129].displayName);
  117. MaterialProperty billboardY = ShaderGUI.FindProperty("_BillboardY", properties);
  118. if (billboardY.floatValue == 1) targetMat.EnableKeyword("BILBOARDY_ON");
  119. else targetMat.DisableKeyword("BILBOARDY_ON");
  120. }
  121. EditorGUILayout.EndVertical();
  122. }
  123. else targetMat.DisableKeyword(flag);
  124. EditorGUILayout.EndToggleGroup();
  125. }
  126. private void ZWrite(MaterialEditor materialEditor, MaterialProperty[] properties, GUIStyle style, string inspector)
  127. {
  128. MaterialProperty zWrite = ShaderGUI.FindProperty("_ZWrite", properties);
  129. bool toggle = zWrite.floatValue > 0.9f ? true : false;
  130. bool ini = toggle;
  131. toggle = EditorGUILayout.BeginToggleGroup(inspector, toggle);
  132. if (ini != toggle && !Application.isPlaying) EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
  133. if (toggle)
  134. {
  135. EditorGUILayout.BeginVertical(style);
  136. {
  137. GUILayout.Label("Usually used to sort Billboarded sprites", style);
  138. GUILayout.Label("Use effect instead 23.Alpha Cutoff for more optimum results", style);
  139. zWrite.floatValue = 1.0f;
  140. }
  141. EditorGUILayout.EndVertical();
  142. }
  143. else zWrite.floatValue = 0.0f;
  144. EditorGUILayout.EndToggleGroup();
  145. }
  146. private void ZTest(MaterialEditor materialEditor, MaterialProperty[] properties, GUIStyle style, bool toggle, string inspector, string flag)
  147. {
  148. MaterialProperty zTestM = ShaderGUI.FindProperty("_ZTestMode", properties);
  149. if (zTestM.floatValue == 0) zTestM.floatValue = 4;
  150. bool ini = toggle;
  151. toggle = EditorGUILayout.BeginToggleGroup(inspector, toggle);
  152. if (ini != toggle && !Application.isPlaying) EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
  153. if (toggle)
  154. {
  155. targetMat.EnableKeyword(flag);
  156. EditorGUILayout.BeginVertical(style);
  157. {
  158. GUILayout.Label("Look for 'ShaderLab culling and depth testing' if you don't know what this is", style);
  159. zTestMode = (UnityEngine.Rendering.CompareFunction)zTestM.floatValue;
  160. zTestMode = (UnityEngine.Rendering.CompareFunction)EditorGUILayout.EnumPopup("zTestMode", zTestMode);
  161. zTestM.floatValue = (float)(zTestMode);
  162. }
  163. EditorGUILayout.EndVertical();
  164. }
  165. else targetMat.DisableKeyword(flag);
  166. EditorGUILayout.EndToggleGroup();
  167. }
  168. private void SpriteAtlas(MaterialEditor materialEditor, GUIStyle style, bool toggle, string inspector, string flag)
  169. {
  170. bool ini = toggle;
  171. toggle = EditorGUILayout.BeginToggleGroup(inspector, toggle);
  172. if (ini != toggle && !Application.isPlaying) EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
  173. if (toggle)
  174. {
  175. targetMat.EnableKeyword(flag);
  176. EditorGUILayout.BeginVertical(style);
  177. {
  178. GUILayout.Label("Make sure SpriteAtlasUV component is added \n " +
  179. "*Check documentation if unsure what this does or how it works", style);
  180. }
  181. EditorGUILayout.EndVertical();
  182. }
  183. else targetMat.DisableKeyword(flag);
  184. EditorGUILayout.EndToggleGroup();
  185. }
  186. private void Outline(MaterialEditor materialEditor, MaterialProperty[] properties, GUIStyle style, bool toggle)
  187. {
  188. bool ini = toggle;
  189. toggle = EditorGUILayout.BeginToggleGroup("3.Outline", toggle);
  190. if (ini != toggle && !Application.isPlaying) EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
  191. if (toggle)
  192. {
  193. targetMat.EnableKeyword("OUTBASE_ON");
  194. EditorGUILayout.BeginVertical(style);
  195. {
  196. materialEditor.ShaderProperty(properties[14], properties[14].displayName);
  197. materialEditor.ShaderProperty(properties[15], properties[15].displayName);
  198. materialEditor.ShaderProperty(properties[16], properties[16].displayName);
  199. materialEditor.ShaderProperty(properties[17], properties[17].displayName);
  200. MaterialProperty outline8dir = ShaderGUI.FindProperty("_Outline8Directions", properties);
  201. if (outline8dir.floatValue == 1) targetMat.EnableKeyword("OUTBASE8DIR_ON");
  202. else targetMat.DisableKeyword("OUTBASE8DIR_ON");
  203. materialEditor.ShaderProperty(properties[19], properties[19].displayName);
  204. MaterialProperty outlinePixel = ShaderGUI.FindProperty("_OutlineIsPixel", properties);
  205. if (outlinePixel.floatValue == 1)
  206. {
  207. targetMat.EnableKeyword("OUTBASEPIXELPERF_ON");
  208. materialEditor.ShaderProperty(properties[20], properties[20].displayName);
  209. }
  210. else
  211. {
  212. targetMat.DisableKeyword("OUTBASEPIXELPERF_ON");
  213. materialEditor.ShaderProperty(properties[18], properties[18].displayName);
  214. }
  215. materialEditor.ShaderProperty(properties[21], properties[21].displayName);
  216. MaterialProperty outlineTex = ShaderGUI.FindProperty("_OutlineTexToggle", properties);
  217. if (outlineTex.floatValue == 1)
  218. {
  219. targetMat.EnableKeyword("OUTTEX_ON");
  220. materialEditor.ShaderProperty(properties[22], properties[22].displayName);
  221. materialEditor.ShaderProperty(properties[23], properties[23].displayName);
  222. materialEditor.ShaderProperty(properties[24], properties[24].displayName);
  223. materialEditor.ShaderProperty(properties[25], properties[25].displayName);
  224. MaterialProperty outlineTexGrey = ShaderGUI.FindProperty("_OutlineTexGrey", properties);
  225. if (outlineTexGrey.floatValue == 1) targetMat.EnableKeyword("OUTGREYTEXTURE_ON");
  226. else targetMat.DisableKeyword("OUTGREYTEXTURE_ON");
  227. }
  228. else targetMat.DisableKeyword("OUTTEX_ON");
  229. materialEditor.ShaderProperty(properties[26], properties[26].displayName);
  230. MaterialProperty outlineDistort = ShaderGUI.FindProperty("_OutlineDistortToggle", properties);
  231. if (outlineDistort.floatValue == 1)
  232. {
  233. targetMat.EnableKeyword("OUTDIST_ON");
  234. materialEditor.ShaderProperty(properties[27], properties[27].displayName);
  235. materialEditor.ShaderProperty(properties[28], properties[28].displayName);
  236. materialEditor.ShaderProperty(properties[29], properties[29].displayName);
  237. materialEditor.ShaderProperty(properties[30], properties[30].displayName);
  238. }
  239. else targetMat.DisableKeyword("OUTDIST_ON");
  240. EditorGUILayout.Separator();
  241. materialEditor.ShaderProperty(properties[71], properties[71].displayName);
  242. MaterialProperty onlyOutline = ShaderGUI.FindProperty("_OnlyOutline", properties);
  243. if (onlyOutline.floatValue == 1) targetMat.EnableKeyword("ONLYOUTLINE_ON");
  244. else targetMat.DisableKeyword("ONLYOUTLINE_ON");
  245. }
  246. EditorGUILayout.EndVertical();
  247. }
  248. else targetMat.DisableKeyword("OUTBASE_ON");
  249. EditorGUILayout.EndToggleGroup();
  250. }
  251. private void GenericEffect(MaterialEditor materialEditor, MaterialProperty[] properties, GUIStyle style, bool toggle, string inspector, string flag, int first, int last)
  252. {
  253. bool ini = toggle;
  254. toggle = EditorGUILayout.BeginToggleGroup(inspector, toggle);
  255. if (ini != toggle && !Application.isPlaying) EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
  256. if (toggle)
  257. {
  258. targetMat.EnableKeyword(flag);
  259. if (first > 0)
  260. {
  261. EditorGUILayout.BeginVertical(style);
  262. {
  263. for (int i = first; i <= last; i++) materialEditor.ShaderProperty(properties[i], properties[i].displayName);
  264. }
  265. EditorGUILayout.EndVertical();
  266. }
  267. }
  268. else targetMat.DisableKeyword(flag);
  269. EditorGUILayout.EndToggleGroup();
  270. }
  271. private void Glow(MaterialEditor materialEditor, MaterialProperty[] properties, GUIStyle style, bool toggle)
  272. {
  273. bool ini = toggle;
  274. toggle = EditorGUILayout.BeginToggleGroup("1.Glow", toggle);
  275. if (ini != toggle && !Application.isPlaying) EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
  276. if (toggle)
  277. {
  278. targetMat.EnableKeyword("GLOW_ON");
  279. EditorGUILayout.BeginVertical(style);
  280. {
  281. materialEditor.ShaderProperty(properties[3], properties[3].displayName);
  282. materialEditor.ShaderProperty(properties[4], properties[4].displayName);
  283. materialEditor.ShaderProperty(properties[5], properties[5].displayName);
  284. MaterialProperty useGlowTex = ShaderGUI.FindProperty("_GlowTexUsed", properties);
  285. if (useGlowTex.floatValue == 1)
  286. {
  287. targetMat.EnableKeyword("GLOWTEX_ON");
  288. materialEditor.ShaderProperty(properties[6], properties[6].displayName);
  289. }
  290. else targetMat.DisableKeyword("GLOWTEX_ON");
  291. }
  292. EditorGUILayout.EndVertical();
  293. }
  294. else targetMat.DisableKeyword("GLOW_ON");
  295. EditorGUILayout.EndToggleGroup();
  296. }
  297. private void ColorRamp(MaterialEditor materialEditor, MaterialProperty[] properties, GUIStyle style, bool toggle)
  298. {
  299. bool ini = toggle;
  300. toggle = EditorGUILayout.BeginToggleGroup("8.Color Ramp", toggle);
  301. if (ini != toggle && !Application.isPlaying) EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
  302. if (toggle)
  303. {
  304. targetMat.EnableKeyword("COLORRAMP_ON");
  305. EditorGUILayout.BeginVertical(style);
  306. {
  307. materialEditor.ShaderProperty(properties[51], properties[51].displayName);
  308. materialEditor.ShaderProperty(properties[52], properties[52].displayName);
  309. materialEditor.ShaderProperty(properties[53], properties[53].displayName);
  310. MaterialProperty colorRampOut = ShaderGUI.FindProperty("_ColorRampOutline", properties);
  311. if (colorRampOut.floatValue == 1) targetMat.EnableKeyword("COLORRAMPOUTLINE_ON");
  312. else targetMat.DisableKeyword("COLORRAMPOUTLINE_ON");
  313. }
  314. EditorGUILayout.EndVertical();
  315. }
  316. else targetMat.DisableKeyword("COLORRAMP_ON");
  317. EditorGUILayout.EndToggleGroup();
  318. }
  319. private void GreyScale(MaterialEditor materialEditor, MaterialProperty[] properties, GUIStyle style, bool toggle)
  320. {
  321. bool ini = toggle;
  322. toggle = EditorGUILayout.BeginToggleGroup("12.Greyscale", toggle);
  323. if (ini != toggle && !Application.isPlaying) EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
  324. if (toggle)
  325. {
  326. targetMat.EnableKeyword("GREYSCALE_ON");
  327. EditorGUILayout.BeginVertical(style);
  328. {
  329. materialEditor.ShaderProperty(properties[54], properties[54].displayName);
  330. materialEditor.ShaderProperty(properties[55], properties[55].displayName);
  331. materialEditor.ShaderProperty(properties[56], properties[56].displayName);
  332. MaterialProperty greyScaleOut = ShaderGUI.FindProperty("_GreyscaleOutline", properties);
  333. if (greyScaleOut.floatValue == 1) targetMat.EnableKeyword("GREYSCALEOUTLINE_ON");
  334. else targetMat.DisableKeyword("GREYSCALEOUTLINE_ON");
  335. }
  336. EditorGUILayout.EndVertical();
  337. }
  338. else targetMat.DisableKeyword("GREYSCALE_ON");
  339. EditorGUILayout.EndToggleGroup();
  340. }
  341. private void Posterize(MaterialEditor materialEditor, MaterialProperty[] properties, GUIStyle style, bool toggle)
  342. {
  343. bool ini = toggle;
  344. toggle = EditorGUILayout.BeginToggleGroup("13.Posterize", toggle);
  345. if (ini != toggle && !Application.isPlaying) EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
  346. if (toggle)
  347. {
  348. targetMat.EnableKeyword("POSTERIZE_ON");
  349. EditorGUILayout.BeginVertical(style);
  350. {
  351. materialEditor.ShaderProperty(properties[57], properties[57].displayName);
  352. materialEditor.ShaderProperty(properties[58], properties[58].displayName);
  353. materialEditor.ShaderProperty(properties[59], properties[59].displayName);
  354. MaterialProperty posterizeOut = ShaderGUI.FindProperty("_PosterizeOutline", properties);
  355. if (posterizeOut.floatValue == 1) targetMat.EnableKeyword("POSTERIZEOUTLINE_ON");
  356. else targetMat.DisableKeyword("POSTERIZEOUTLINE_ON");
  357. }
  358. EditorGUILayout.EndVertical();
  359. }
  360. else targetMat.DisableKeyword("POSTERIZE_ON");
  361. EditorGUILayout.EndToggleGroup();
  362. }
  363. private void Blur(MaterialEditor materialEditor, MaterialProperty[] properties, GUIStyle style, bool toggle)
  364. {
  365. bool ini = toggle;
  366. toggle = EditorGUILayout.BeginToggleGroup("14.Blur", toggle);
  367. if (ini != toggle && !Application.isPlaying) EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
  368. if (toggle)
  369. {
  370. targetMat.EnableKeyword("BLUR_ON");
  371. EditorGUILayout.BeginVertical(style);
  372. {
  373. materialEditor.ShaderProperty(properties[60], properties[60].displayName);
  374. materialEditor.ShaderProperty(properties[61], properties[61].displayName);
  375. MaterialProperty blurIsHd = ShaderGUI.FindProperty("_BlurHD", properties);
  376. if (blurIsHd.floatValue == 1) targetMat.EnableKeyword("BLURISHD_ON");
  377. else targetMat.DisableKeyword("BLURISHD_ON");
  378. }
  379. EditorGUILayout.EndVertical();
  380. }
  381. else targetMat.DisableKeyword("BLUR_ON");
  382. EditorGUILayout.EndToggleGroup();
  383. }
  384. private void Grass(MaterialEditor materialEditor, MaterialProperty[] properties, GUIStyle style, bool toggle)
  385. {
  386. bool ini = toggle;
  387. toggle = EditorGUILayout.BeginToggleGroup("26.Grass Movement / Wind", toggle);
  388. if (ini != toggle && !Application.isPlaying) EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
  389. if (toggle)
  390. {
  391. targetMat.EnableKeyword("WIND_ON");
  392. EditorGUILayout.BeginVertical(style);
  393. {
  394. materialEditor.ShaderProperty(properties[90], properties[90].displayName);
  395. materialEditor.ShaderProperty(properties[91], properties[91].displayName);
  396. materialEditor.ShaderProperty(properties[92], properties[92].displayName);
  397. materialEditor.ShaderProperty(properties[93], properties[93].displayName);
  398. MaterialProperty grassManual = ShaderGUI.FindProperty("_GrassManualToggle", properties);
  399. if (grassManual.floatValue == 1) targetMat.EnableKeyword("MANUALWIND_ON");
  400. else targetMat.DisableKeyword("MANUALWIND_ON");
  401. }
  402. EditorGUILayout.EndVertical();
  403. }
  404. else targetMat.DisableKeyword("WIND_ON");
  405. EditorGUILayout.EndToggleGroup();
  406. }
  407. private void InnerOutline(MaterialEditor materialEditor, MaterialProperty[] properties, GUIStyle style, bool toggle, string inspector, string flag, int first, int last)
  408. {
  409. bool ini = toggle;
  410. toggle = EditorGUILayout.BeginToggleGroup(inspector, toggle);
  411. if (ini != toggle && !Application.isPlaying) EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
  412. if (toggle)
  413. {
  414. targetMat.EnableKeyword(flag);
  415. if (first > 0)
  416. {
  417. EditorGUILayout.BeginVertical(style);
  418. {
  419. for (int i = first; i <= last; i++) materialEditor.ShaderProperty(properties[i], properties[i].displayName);
  420. EditorGUILayout.Separator();
  421. materialEditor.ShaderProperty(properties[72], properties[72].displayName);
  422. MaterialProperty onlyInOutline = ShaderGUI.FindProperty("_OnlyInnerOutline", properties);
  423. if (onlyInOutline.floatValue == 1) targetMat.EnableKeyword("ONLYINNEROUTLINE_ON");
  424. else targetMat.DisableKeyword("ONLYINNEROUTLINE_ON");
  425. }
  426. EditorGUILayout.EndVertical();
  427. }
  428. }
  429. else targetMat.DisableKeyword(flag);
  430. EditorGUILayout.EndToggleGroup();
  431. }
  432. private void Glitch(MaterialEditor materialEditor, MaterialProperty[] properties, GUIStyle style, bool toggle, string inspector, string flag)
  433. {
  434. bool ini = toggle;
  435. toggle = EditorGUILayout.BeginToggleGroup(inspector, toggle);
  436. if (ini != toggle && !Application.isPlaying) EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
  437. if (toggle)
  438. {
  439. targetMat.EnableKeyword(flag);
  440. EditorGUILayout.BeginVertical(style);
  441. {
  442. materialEditor.ShaderProperty(properties[80], properties[80].displayName);
  443. materialEditor.ShaderProperty(properties[138], properties[138].displayName);
  444. }
  445. EditorGUILayout.EndVertical();
  446. }
  447. else targetMat.DisableKeyword(flag);
  448. EditorGUILayout.EndToggleGroup();
  449. }
  450. }