HologramShaderEditor.cs 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEditor;
  4. using UnityEngine;
  5. namespace Knife.HologramEffect
  6. {
  7. public class HologramShaderEditor : ShaderGUI
  8. {
  9. private List<MaterialProperty> propertiesList = new List<MaterialProperty>();
  10. private List<MaterialProperty> otherPropetiesList = new List<MaterialProperty>();
  11. private List<MaterialProperty> propertiesFresnel = new List<MaterialProperty>();
  12. private List<MaterialProperty> propertiesLine1 = new List<MaterialProperty>();
  13. private List<MaterialProperty> propertiesLine2 = new List<MaterialProperty>();
  14. private List<MaterialProperty> propertiesLineGlitch = new List<MaterialProperty>();
  15. private List<MaterialProperty> propertiesRandomGlitch = new List<MaterialProperty>();
  16. private List<MaterialProperty> propertiesColorGlitch = new List<MaterialProperty>();
  17. private List<MaterialProperty> propertiesGrain = new List<MaterialProperty>();
  18. private List<MaterialProperty> propertiesNormalMap = new List<MaterialProperty>();
  19. private List<MaterialProperty> propertiesSoftIntersection1 = new List<MaterialProperty>();
  20. private List<MaterialProperty> propertiesSoftIntersection2 = new List<MaterialProperty>();
  21. private List<MaterialProperty> propertiesDissolve = new List<MaterialProperty>();
  22. private List<MaterialProperty> propertiesMask = new List<MaterialProperty>();
  23. private List<MaterialProperty> propertiesAlphaMask = new List<MaterialProperty>();
  24. private List<MaterialProperty> propertiesVoxelization = new List<MaterialProperty>();
  25. private static bool isExpandedFresnel;
  26. private static bool isExpandedLine1;
  27. private static bool isExpandedLine2;
  28. private static bool isExpandedLineGlitch;
  29. private static bool isExpandedRandomGlitch;
  30. private static bool isExpandedColorGlitch;
  31. private static bool isExpandedGrain;
  32. private static bool isExpandedNormalMap;
  33. private static bool isExpandedSoftIntersection1;
  34. private static bool isExpandedSoftIntersection2;
  35. private static bool isExpandedDissolve;
  36. private static bool isExpandedMask;
  37. private static bool isExpandedPosition;
  38. private static bool isExpandedAlphaMask;
  39. private static bool isExpandedVoxelization;
  40. private MaterialProperty mainColorProperty;
  41. private MaterialProperty fresnelFeature;
  42. private MaterialProperty line1Feature;
  43. private MaterialProperty line2Feature;
  44. private MaterialProperty lineBothFeature;
  45. private MaterialProperty lineGlitchFeature;
  46. private MaterialProperty randomGlitchFeature;
  47. private MaterialProperty colorGlitchFeature;
  48. private MaterialProperty grainFeature;
  49. private MaterialProperty normalMapFeature;
  50. private MaterialProperty softIntersection1Feature;
  51. private MaterialProperty softIntersection2Feature;
  52. private MaterialProperty dissolveFeature;
  53. private MaterialProperty maskFeature;
  54. private MaterialProperty maskLocalFeature;
  55. private MaterialProperty positionFeature;
  56. private MaterialProperty positionSpaceFeature;
  57. private MaterialProperty alphaMaskFeature;
  58. private MaterialProperty voxelizationFeature;
  59. private MaterialProperty positionDirectionProperty;
  60. private MaterialProperty randomOffsetProperty;
  61. private MaterialProperty zWriteProperty;
  62. private MaterialProperty cullModeProperty;
  63. private MaterialProperty alphaProperty;
  64. /*
  65. #pragma shader_feature _FRESNELFEATURE_ON
  66. #pragma shader_feature _LINE1FEATURE_ON
  67. #pragma shader_feature _LINE2FEATURE_ON
  68. #pragma shader_feature _LINEBOTHFEATURE_ON
  69. #pragma shader_feature _LINEGLITCHFEATURE_ON
  70. #pragma shader_feature _RANDOMGLITCHFEATURE_ON
  71. #pragma shader_feature _COLORGLITCHFEATURE_ON
  72. #pragma shader_feature _GRAINFEATURE_ON
  73. #pragma shader_feature _NORMALMAPFEATURE_ON
  74. #pragma shader_feature _SOFTINTERSECTIONFEATURE_OFF _SOFTINTERSECTIONFEATURE_ALPHA _SOFTINTERSECTIONFEATURE_COLOR
  75. #pragma shader_feature _DISSOLVEFEATURE_ON
  76. #pragma shader_feature _MASKFEATURE_ON
  77. #pragma shader_feature _POSITIONSPACEFEATURE_WORLD _POSITIONSPACEFEATURE_LOCAL _POSITIONSPACEFEATURE_CUSTOM
  78. #pragma shader_feature _POSITIONFEATURE_X _POSITIONFEATURE_Y _POSITIONFEATURE_Z
  79. */
  80. private string[] softIntersection1Keywords = { "_SOFTINTERSECTION1FEATURE_OFF", "_SOFTINTERSECTION1FEATURE_ALPHA", "_SOFTINTERSECTION1FEATURE_COLOR" };
  81. private string[] softIntersection2Keywords = { "_SOFTINTERSECTION2FEATURE_OFF", "_SOFTINTERSECTION2FEATURE_ALPHA", "_SOFTINTERSECTION2FEATURE_COLOR" };
  82. private string[] softIntersectionNames = { "Off", "Alpha", "Color" };
  83. private int[] softIntersectionValues = { 0, 1, 2 };
  84. private string[] positionKeywords = { "_POSITIONFEATURE_X", "_POSITIONFEATURE_Y", "_POSITIONFEATURE_Z" };
  85. private string[] positionNames = { "X", "Y", "Z" };
  86. private int[] positionValues = { 0, 1, 2 };
  87. private string[] positionSpaceKeywords = { "_POSITIONSPACEFEATURE_WORLD", "_POSITIONSPACEFEATURE_LOCAL", "_POSITIONSPACEFEATURE_CUSTOM" };
  88. private string[] positionSpaceNames = { "World", "Local", "Custom" };
  89. private int[] positionSpaceValues = { 0, 1, 2 };
  90. private MaterialEditor materialEditor;
  91. public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] properties)
  92. {
  93. try
  94. {
  95. this.materialEditor = materialEditor;
  96. propertiesList.Clear();
  97. otherPropetiesList.Clear();
  98. propertiesList.AddRange(properties);
  99. propertiesFresnel.Clear();
  100. propertiesLine1.Clear();
  101. propertiesLine2.Clear();
  102. propertiesLineGlitch.Clear();
  103. propertiesRandomGlitch.Clear();
  104. propertiesColorGlitch.Clear();
  105. propertiesGrain.Clear();
  106. propertiesNormalMap.Clear();
  107. propertiesSoftIntersection1.Clear();
  108. propertiesSoftIntersection2.Clear();
  109. propertiesDissolve.Clear();
  110. propertiesMask.Clear();
  111. propertiesAlphaMask.Clear();
  112. propertiesVoxelization.Clear();
  113. const string feature = "Feature";
  114. EditorGUI.BeginChangeCheck();
  115. foreach (var p in propertiesList)
  116. {
  117. string propName = p.displayName;
  118. if (propName.Equals("Main Color"))
  119. {
  120. mainColorProperty = p;
  121. } else if(propName.Equals("Random Offset"))
  122. {
  123. randomOffsetProperty = p;
  124. } else if (propName.Equals("Line Both Feature"))
  125. {
  126. lineBothFeature = p;
  127. } else if (propName.Equals("Position Feature"))
  128. {
  129. positionFeature = p;
  130. } else if (propName.Equals("Position Space Feature"))
  131. {
  132. positionSpaceFeature = p;
  133. } else if (propName.Equals("Position Direction"))
  134. {
  135. positionDirectionProperty = p;
  136. } else if(propName.Equals("ZWrite"))
  137. {
  138. zWriteProperty = p;
  139. } else if(propName.Equals("Cull Mode"))
  140. {
  141. cullModeProperty = p;
  142. } else if(propName.Equals("Alpha"))
  143. {
  144. alphaProperty = p;
  145. }
  146. else if (propName.StartsWith("Fresnel"))
  147. {
  148. if (propName.Contains(feature))
  149. {
  150. fresnelFeature = p;
  151. }
  152. else
  153. {
  154. propertiesFresnel.Add(p);
  155. }
  156. }
  157. else if (propName.StartsWith("Line 1"))
  158. {
  159. if (propName.Contains(feature))
  160. {
  161. line1Feature = p;
  162. }
  163. else
  164. {
  165. propertiesLine1.Add(p);
  166. }
  167. }
  168. else if (propName.StartsWith("Line 2"))
  169. {
  170. if (propName.Contains(feature))
  171. {
  172. line2Feature = p;
  173. }
  174. else
  175. {
  176. propertiesLine2.Add(p);
  177. }
  178. }
  179. else if (propName.StartsWith("Line Glitch"))
  180. {
  181. if (propName.Contains(feature))
  182. {
  183. lineGlitchFeature = p;
  184. }
  185. else
  186. {
  187. propertiesLineGlitch.Add(p);
  188. }
  189. }
  190. else if (propName.StartsWith("Random Glitch"))
  191. {
  192. if (propName.Contains(feature))
  193. {
  194. randomGlitchFeature = p;
  195. }
  196. else
  197. {
  198. propertiesRandomGlitch.Add(p);
  199. }
  200. }
  201. else if (propName.StartsWith("Color Glitch"))
  202. {
  203. if (propName.Contains(feature))
  204. {
  205. colorGlitchFeature = p;
  206. }
  207. else
  208. {
  209. propertiesColorGlitch.Add(p);
  210. }
  211. }
  212. else if (propName.StartsWith("Grain"))
  213. {
  214. if (propName.Contains(feature))
  215. {
  216. grainFeature = p;
  217. }
  218. else
  219. {
  220. propertiesGrain.Add(p);
  221. }
  222. }
  223. else if (propName.StartsWith("Normal"))
  224. {
  225. if (propName.Contains(feature))
  226. {
  227. normalMapFeature = p;
  228. }
  229. else
  230. {
  231. propertiesNormalMap.Add(p);
  232. }
  233. }
  234. else if (propName.StartsWith("Soft Intersection 1"))
  235. {
  236. if (propName.Contains(feature))
  237. {
  238. softIntersection1Feature = p;
  239. }
  240. else
  241. {
  242. propertiesSoftIntersection1.Add(p);
  243. }
  244. }
  245. else if (propName.StartsWith("Soft Intersection 2"))
  246. {
  247. if (propName.Contains(feature))
  248. {
  249. softIntersection2Feature = p;
  250. }
  251. else
  252. {
  253. propertiesSoftIntersection2.Add(p);
  254. }
  255. }
  256. else if (propName.StartsWith("Dissolve"))
  257. {
  258. if (propName.Contains(feature))
  259. {
  260. dissolveFeature = p;
  261. }
  262. else
  263. {
  264. propertiesDissolve.Add(p);
  265. }
  266. } else if (propName.StartsWith("Mask"))
  267. {
  268. if (propName.Contains(feature))
  269. {
  270. if (propName.Equals("Mask Local Feature"))
  271. {
  272. maskLocalFeature = p;
  273. }
  274. else
  275. {
  276. maskFeature = p;
  277. }
  278. }
  279. else
  280. {
  281. propertiesMask.Add(p);
  282. }
  283. } else if (propName.StartsWith("Alpha Mask"))
  284. {
  285. if (propName.Contains(feature))
  286. {
  287. alphaMaskFeature = p;
  288. }
  289. else
  290. {
  291. propertiesAlphaMask.Add(p);
  292. }
  293. }
  294. else if (propName.StartsWith("Voxelization"))
  295. {
  296. if (propName.Contains(feature))
  297. {
  298. voxelizationFeature = p;
  299. }
  300. else
  301. {
  302. propertiesVoxelization.Add(p);
  303. }
  304. }
  305. else
  306. {
  307. otherPropetiesList.Add(p);
  308. }
  309. }
  310. materialEditor.ColorProperty(mainColorProperty, "Main Color");
  311. materialEditor.ShaderProperty(alphaProperty, "Alpha");
  312. if(GUILayout.Button("Randomize"))
  313. {
  314. randomOffsetProperty.floatValue = Random.Range(0f, 100000f);
  315. }
  316. materialEditor.FloatProperty(randomOffsetProperty, "Random Offset");
  317. materialEditor.ShaderProperty(zWriteProperty, "ZWrite");
  318. materialEditor.ShaderProperty(cullModeProperty, "Cull Mode");
  319. isExpandedFresnel = EditorGUILayout.Foldout(isExpandedFresnel, "Fresnel");
  320. if (isExpandedFresnel)
  321. {
  322. EditorGUI.indentLevel++;
  323. DrawFeature(fresnelFeature, "_FRESNELFEATURE_ON");
  324. if (IsFeatureEnabled(fresnelFeature))
  325. {
  326. foreach (var p in propertiesFresnel)
  327. {
  328. DrawProperty(p);
  329. }
  330. }
  331. EditorGUI.indentLevel--;
  332. }
  333. isExpandedLine1 = EditorGUILayout.Foldout(isExpandedLine1, "Line 1");
  334. if (isExpandedLine1)
  335. {
  336. EditorGUI.indentLevel++;
  337. DrawFeature(line1Feature, "_LINE1FEATURE_ON");
  338. if (IsFeatureEnabled(line1Feature))
  339. {
  340. foreach (var p in propertiesLine1)
  341. {
  342. DrawProperty(p);
  343. }
  344. }
  345. EditorGUI.indentLevel--;
  346. }
  347. isExpandedLine2 = EditorGUILayout.Foldout(isExpandedLine2, "Line 2");
  348. if (isExpandedLine2)
  349. {
  350. EditorGUI.indentLevel++;
  351. DrawFeature(line2Feature, "_LINE2FEATURE_ON");
  352. if (IsFeatureEnabled(line2Feature))
  353. {
  354. foreach (var p in propertiesLine2)
  355. {
  356. DrawProperty(p);
  357. }
  358. }
  359. EditorGUI.indentLevel--;
  360. }
  361. if (IsFeatureEnabled(line1Feature) && IsFeatureEnabled(line2Feature))
  362. {
  363. lineBothFeature.floatValue = 1f;
  364. EnableKeyword("_LINEBOTHFEATURE_ON", true);
  365. }
  366. else
  367. {
  368. lineBothFeature.floatValue = 0f;
  369. EnableKeyword("_LINEBOTHFEATURE_ON", false);
  370. }
  371. isExpandedLineGlitch = EditorGUILayout.Foldout(isExpandedLineGlitch, "Line Glitch");
  372. if (isExpandedLineGlitch)
  373. {
  374. EditorGUI.indentLevel++;
  375. DrawFeature(lineGlitchFeature, "_LINEGLITCHFEATURE_ON");
  376. if (IsFeatureEnabled(lineGlitchFeature))
  377. {
  378. foreach (var p in propertiesLineGlitch)
  379. {
  380. DrawProperty(p);
  381. }
  382. }
  383. EditorGUI.indentLevel--;
  384. }
  385. isExpandedRandomGlitch = EditorGUILayout.Foldout(isExpandedRandomGlitch, "Random Glitch");
  386. if (isExpandedRandomGlitch)
  387. {
  388. EditorGUI.indentLevel++;
  389. DrawFeature(randomGlitchFeature, "_RANDOMGLITCHFEATURE_ON");
  390. if (IsFeatureEnabled(randomGlitchFeature))
  391. {
  392. foreach (var p in propertiesRandomGlitch)
  393. {
  394. DrawProperty(p);
  395. }
  396. }
  397. EditorGUI.indentLevel--;
  398. }
  399. isExpandedColorGlitch = EditorGUILayout.Foldout(isExpandedColorGlitch, "Color Glitch");
  400. if (isExpandedColorGlitch)
  401. {
  402. EditorGUI.indentLevel++;
  403. DrawFeature(colorGlitchFeature, "_COLORGLITCHFEATURE_ON");
  404. if (IsFeatureEnabled(colorGlitchFeature))
  405. {
  406. foreach (var p in propertiesColorGlitch)
  407. {
  408. DrawProperty(p);
  409. }
  410. }
  411. EditorGUI.indentLevel--;
  412. }
  413. isExpandedGrain = EditorGUILayout.Foldout(isExpandedGrain, "Grain");
  414. if (isExpandedGrain)
  415. {
  416. EditorGUI.indentLevel++;
  417. DrawFeature(grainFeature, "_GRAINFEATURE_ON");
  418. if (IsFeatureEnabled(grainFeature))
  419. {
  420. foreach (var p in propertiesGrain)
  421. {
  422. DrawProperty(p);
  423. }
  424. }
  425. EditorGUI.indentLevel--;
  426. }
  427. isExpandedNormalMap = EditorGUILayout.Foldout(isExpandedNormalMap, "Normal Map");
  428. if (isExpandedNormalMap)
  429. {
  430. EditorGUI.indentLevel++;
  431. DrawFeature(normalMapFeature, "_NORMALMAPFEATURE_ON");
  432. if (IsFeatureEnabled(normalMapFeature))
  433. {
  434. foreach (var p in propertiesNormalMap)
  435. {
  436. DrawProperty(p);
  437. }
  438. }
  439. EditorGUI.indentLevel--;
  440. }
  441. isExpandedSoftIntersection1 = EditorGUILayout.Foldout(isExpandedSoftIntersection1, "Soft Intersection 1");
  442. if (isExpandedSoftIntersection1)
  443. {
  444. EditorGUI.indentLevel++;
  445. DrawFeatureEnum(softIntersection1Feature, softIntersectionNames, softIntersectionValues, softIntersection1Keywords);
  446. if (GetFeatureEnumValue(softIntersection1Feature) != 0)
  447. {
  448. foreach (var p in propertiesSoftIntersection1)
  449. {
  450. DrawProperty(p);
  451. }
  452. }
  453. EditorGUI.indentLevel--;
  454. }
  455. isExpandedSoftIntersection2 = EditorGUILayout.Foldout(isExpandedSoftIntersection2, "Soft Intersection 2");
  456. if (isExpandedSoftIntersection2)
  457. {
  458. EditorGUI.indentLevel++;
  459. DrawFeatureEnum(softIntersection2Feature, softIntersectionNames, softIntersectionValues, softIntersection2Keywords);
  460. if (GetFeatureEnumValue(softIntersection2Feature) != 0)
  461. {
  462. foreach (var p in propertiesSoftIntersection2)
  463. {
  464. DrawProperty(p);
  465. }
  466. }
  467. EditorGUI.indentLevel--;
  468. }
  469. isExpandedDissolve = EditorGUILayout.Foldout(isExpandedDissolve, "Dissolve");
  470. if (isExpandedDissolve)
  471. {
  472. EditorGUI.indentLevel++;
  473. DrawFeature(dissolveFeature, "_DISSOLVEFEATURE_ON");
  474. if (IsFeatureEnabled(dissolveFeature))
  475. {
  476. foreach (var p in propertiesDissolve)
  477. {
  478. DrawProperty(p);
  479. }
  480. }
  481. EditorGUI.indentLevel--;
  482. }
  483. isExpandedMask = EditorGUILayout.Foldout(isExpandedMask, "Mask");
  484. if (isExpandedMask)
  485. {
  486. EditorGUI.indentLevel++;
  487. DrawFeature(maskFeature, "_MASKFEATURE_ON");
  488. if (IsFeatureEnabled(maskFeature))
  489. {
  490. DrawFeature(maskLocalFeature, "_MASKLOCALFEATURE_ON", maskLocalFeature.displayName.Replace(" Feature", ""));
  491. foreach (var p in propertiesMask)
  492. {
  493. DrawProperty(p);
  494. }
  495. }
  496. EditorGUI.indentLevel--;
  497. }
  498. isExpandedPosition = EditorGUILayout.Foldout(isExpandedPosition, "Position");
  499. if (isExpandedPosition)
  500. {
  501. EditorGUI.indentLevel++;
  502. DrawFeatureEnum(positionSpaceFeature, positionSpaceNames, positionSpaceValues, positionSpaceKeywords);
  503. DrawFeatureEnum(positionFeature, positionNames, positionValues, positionKeywords);
  504. DrawProperty(positionDirectionProperty);
  505. EditorGUI.indentLevel--;
  506. }
  507. isExpandedAlphaMask = EditorGUILayout.Foldout(isExpandedAlphaMask, "Alpha Mask");
  508. if (isExpandedAlphaMask)
  509. {
  510. EditorGUI.indentLevel++;
  511. DrawFeature(alphaMaskFeature, "_ALPHAMASKFEATURE_ON");
  512. if (IsFeatureEnabled(alphaMaskFeature))
  513. {
  514. foreach (var p in propertiesAlphaMask)
  515. {
  516. DrawProperty(p);
  517. }
  518. }
  519. EditorGUI.indentLevel--;
  520. }
  521. isExpandedVoxelization = EditorGUILayout.Foldout(isExpandedVoxelization, "Voxelization");
  522. if (isExpandedVoxelization)
  523. {
  524. EditorGUI.indentLevel++;
  525. DrawFeature(voxelizationFeature, "_VOXELIZATIONFEATURE_ON");
  526. if (IsFeatureEnabled(voxelizationFeature))
  527. {
  528. foreach (var p in propertiesVoxelization)
  529. {
  530. DrawProperty(p);
  531. }
  532. }
  533. EditorGUI.indentLevel--;
  534. }
  535. if (EditorGUI.EndChangeCheck())
  536. {
  537. foreach (var t in materialEditor.targets)
  538. {
  539. Material m = t as Material;
  540. EditorUtility.SetDirty(m);
  541. }
  542. }
  543. } catch (System.Exception ex)
  544. {
  545. base.OnGUI(materialEditor, properties);
  546. throw ex;
  547. }
  548. }
  549. private bool IsFeatureEnabled(MaterialProperty property)
  550. {
  551. return (int)property.floatValue == 1;
  552. }
  553. private int GetFeatureEnumValue(MaterialProperty property)
  554. {
  555. return (int)property.floatValue;
  556. }
  557. private void EnableKeyword(string keywordName, bool value)
  558. {
  559. if (value)
  560. {
  561. foreach (var t in materialEditor.targets)
  562. {
  563. Material m = t as Material;
  564. m.EnableKeyword(keywordName);
  565. }
  566. }
  567. else
  568. {
  569. foreach (var t in materialEditor.targets)
  570. {
  571. Material m = t as Material;
  572. m.DisableKeyword(keywordName);
  573. }
  574. }
  575. }
  576. private void EnableKeywordEnum(string[] keywords, int index)
  577. {
  578. for (int i = 0; i < keywords.Length; i++)
  579. {
  580. if(index == i)
  581. {
  582. foreach (var t in materialEditor.targets)
  583. {
  584. Material m = t as Material;
  585. m.EnableKeyword(keywords[i]);
  586. }
  587. }
  588. else
  589. {
  590. foreach (var t in materialEditor.targets)
  591. {
  592. Material m = t as Material;
  593. m.DisableKeyword(keywords[i]);
  594. }
  595. }
  596. }
  597. }
  598. private void DrawFeature(MaterialProperty property, string keywordName, string propCustomName = "Enabled")
  599. {
  600. string propName = property.displayName;
  601. propName = propCustomName;
  602. bool hasMixedValue = property.hasMixedValue;
  603. if (hasMixedValue)
  604. EditorGUI.showMixedValue = true;
  605. bool value = (int)property.floatValue == 1;
  606. EditorGUI.BeginChangeCheck();
  607. value = EditorGUILayout.Toggle(propName, value);
  608. if (EditorGUI.EndChangeCheck())
  609. {
  610. property.floatValue = value ? 1 : 0;
  611. EnableKeyword(keywordName, value);
  612. }
  613. if(hasMixedValue)
  614. EditorGUI.showMixedValue = false;
  615. }
  616. private void DrawFeatureEnum(MaterialProperty property, string[] names, int[] values, string[] keywords)
  617. {
  618. string propName = property.displayName;
  619. propName = propName.Replace("Feature", "");
  620. bool hasMixedValue = property.hasMixedValue;
  621. if (hasMixedValue)
  622. EditorGUI.showMixedValue = true;
  623. int value = (int)property.floatValue;
  624. EditorGUI.BeginChangeCheck();
  625. value = EditorGUILayout.IntPopup(propName, value, names, values);
  626. if (EditorGUI.EndChangeCheck())
  627. {
  628. property.floatValue = value;
  629. EnableKeywordEnum(keywords, value);
  630. }
  631. if (hasMixedValue)
  632. EditorGUI.showMixedValue = false;
  633. }
  634. private void DrawProperty(MaterialProperty property)
  635. {
  636. string propName = property.displayName;
  637. switch (property.type)
  638. {
  639. case MaterialProperty.PropType.Color:
  640. materialEditor.ColorProperty(property, propName);
  641. break;
  642. case MaterialProperty.PropType.Float:
  643. materialEditor.FloatProperty(property, propName);
  644. break;
  645. case MaterialProperty.PropType.Range:
  646. materialEditor.RangeProperty(property, propName);
  647. break;
  648. case MaterialProperty.PropType.Texture:
  649. materialEditor.TexturePropertySingleLine(new GUIContent(propName), property);
  650. if(!property.flags.HasFlag((System.Enum)MaterialProperty.PropFlags.NoScaleOffset))
  651. materialEditor.TextureScaleOffsetProperty(property);
  652. break;
  653. case MaterialProperty.PropType.Vector:
  654. materialEditor.VectorProperty(property, propName);
  655. break;
  656. }
  657. }
  658. }
  659. }