|
7 | 7 |
|
8 | 8 | public class TMP_SDFShaderGUI_Dissolve : TMP_SDFShaderGUI |
9 | 9 | { |
10 | | - static MaterialPanel dissolvePanel = new MaterialPanel ("Dissolve", true); |
11 | | - static MaterialPanel spritePanel = new MaterialPanel ("Sprite", true); |
| 10 | + GUIStyle panelTitle; |
| 11 | + Material currentMaterial; |
| 12 | + |
| 13 | + public override void OnGUI (MaterialEditor materialEditor, MaterialProperty [] properties) |
| 14 | + { |
| 15 | + currentMaterial = materialEditor.target as Material; |
| 16 | + base.OnGUI (materialEditor, properties); |
| 17 | + } |
12 | 18 |
|
13 | 19 | protected override void DoGUI () |
14 | 20 | { |
15 | | - if(material.HasProperty("_FaceColor")) |
| 21 | + if (currentMaterial.HasProperty ("_FaceColor")) |
16 | 22 | { |
17 | 23 | base.DoGUI (); |
18 | 24 | } |
19 | | - else if(DoPanelHeader (spritePanel)) |
| 25 | + else |
20 | 26 | { |
21 | | - EditorGUI.indentLevel += 1; |
22 | | - DoTexture2D ("_MainTex", "Texture"); |
23 | | - DoColor ("_Color", "Color"); |
24 | | - EditorGUI.indentLevel -= 1; |
| 27 | + if (BeginCommonPanel ("Sprite", true)) |
| 28 | + { |
| 29 | + EditorGUI.indentLevel++; |
| 30 | + DoTexture2D ("_MainTex", "Texture"); |
| 31 | + DoColor ("_Color", "Color"); |
| 32 | + EditorGUI.indentLevel--; |
| 33 | + } |
| 34 | + EndCommonPanel (); |
25 | 35 | } |
26 | 36 |
|
27 | | - if (DoPanelHeader (dissolvePanel)) |
| 37 | + if (BeginCommonPanel ("Dissolve", true)) |
28 | 38 | { |
29 | | - EditorGUI.indentLevel += 1; |
| 39 | + EditorGUI.indentLevel++; |
30 | 40 | DoTexture2D ("_NoiseTex", "Texture"); |
31 | 41 |
|
32 | 42 | ColorMode color = |
33 | | - material.IsKeywordEnabled ("ADD") ? ColorMode.Add |
34 | | - : material.IsKeywordEnabled ("SUBTRACT") ? ColorMode.Subtract |
35 | | - : material.IsKeywordEnabled ("FILL") ? ColorMode.Fill |
| 43 | + currentMaterial.IsKeywordEnabled ("ADD") ? ColorMode.Add |
| 44 | + : currentMaterial.IsKeywordEnabled ("SUBTRACT") ? ColorMode.Subtract |
| 45 | + : currentMaterial.IsKeywordEnabled ("FILL") ? ColorMode.Fill |
36 | 46 | : ColorMode.Multiply; |
37 | 47 |
|
38 | 48 | var newColor = (ColorMode)EditorGUILayout.EnumPopup ("Color Mode", color); |
39 | 49 | if (color != newColor) |
40 | 50 | { |
41 | | - material.DisableKeyword (color.ToString ().ToUpper ()); |
| 51 | + currentMaterial.DisableKeyword (color.ToString ().ToUpper ()); |
42 | 52 | if (newColor != ColorMode.Multiply) |
43 | 53 | { |
44 | | - material.EnableKeyword (newColor.ToString ().ToUpper ()); |
| 54 | + currentMaterial.EnableKeyword (newColor.ToString ().ToUpper ()); |
45 | 55 | } |
46 | 56 | } |
47 | | - EditorGUI.indentLevel -= 1; |
| 57 | + EditorGUI.indentLevel--; |
| 58 | + } |
| 59 | + EndCommonPanel (); |
| 60 | + } |
| 61 | + |
| 62 | + bool BeginCommonPanel (string panel, bool expanded) |
| 63 | + { |
| 64 | + if (panelTitle == null) |
| 65 | + { |
| 66 | + panelTitle = new GUIStyle (EditorStyles.label) { fontStyle = FontStyle.Bold }; |
48 | 67 | } |
| 68 | + |
| 69 | + EditorGUILayout.BeginVertical (EditorStyles.helpBox); |
| 70 | + Rect position = EditorGUI.IndentedRect (GUILayoutUtility.GetRect (20f, 18f)); |
| 71 | + position.x += 20; |
| 72 | + position.width += 6f; |
| 73 | + expanded = GUI.Toggle (position, expanded, panel, panelTitle); |
| 74 | + EditorGUI.indentLevel++; |
| 75 | + EditorGUI.BeginDisabledGroup (false); |
| 76 | + return expanded; |
| 77 | + } |
| 78 | + |
| 79 | + void EndCommonPanel () |
| 80 | + { |
| 81 | + EditorGUI.EndDisabledGroup (); |
| 82 | + EditorGUI.indentLevel--; |
| 83 | + EditorGUILayout.EndVertical (); |
49 | 84 | } |
50 | 85 | } |
0 commit comments