14 public static Rect TextureWithToggleableColorSingleLine
16 MaterialEditor matEditor,
18 MaterialProperty textureProp,
19 MaterialProperty colorToggleProp,
20 MaterialProperty colorProp
23 var lineRect = GetControlRectForSingleLine();
24 var controlRect = lineRect;
27 matEditor.TexturePropertyMiniThumbnail(lineRect, textureProp, label.text, label.tooltip);
29 controlRect.x += EditorGUIUtility.labelWidth;
30 controlRect.width = EditorGUIUtility.fieldWidth;
32 var toggleTooltip =
new GUIContent
35 tooltip =
"Enable/Disable color" 40 matEditor.ShaderProperty(controlRect, colorToggleProp, toggleTooltip, -1);
42 if (colorToggleProp.floatValue != 0.0f)
44 controlRect.x += EditorStyles.toggle.fixedWidth;
45 controlRect.x += EditorStyles.toggle.padding.right;
48 controlRect.width = lineRect.width - controlRect.x;
50 var tooltipOnly =
new GUIContent
53 tooltip = label.tooltip
56 EditorGUI.showMixedValue = colorProp.hasMixedValue;
57 EditorGUI.BeginChangeCheck();
58 var color = EditorGUI.ColorField(controlRect, tooltipOnly, colorProp.colorValue);
59 if (EditorGUI.EndChangeCheck())
61 colorProp.colorValue = color;
63 EditorGUI.showMixedValue =
false;
69 public static void SetScaleOffsetKeywords
71 MaterialEditor matEditor,
72 MaterialProperty textureProp,
73 MaterialProperty scaleOffsetProp
76 var texScaleOffset = scaleOffsetProp.vectorValue;
77 bool usesScale = texScaleOffset.x != 1.0f || texScaleOffset.y != 1.0f;
78 bool usesOffset = texScaleOffset.z != 0.0f || texScaleOffset.w != 0.0f;
80 var mat = matEditor.target as Material;
82 var scaleKeyword = textureProp.name +
"_SCALE_ON";
83 var offsetKeyword = textureProp.name +
"_OFFSET_ON";
89 public static Rect TextureWithToggleableColorAutoScaleOffsetSingleLine
91 MaterialEditor matEditor,
93 MaterialProperty textureProp,
94 MaterialProperty colorToggleProp, MaterialProperty colorProp,
95 MaterialProperty scaleOffsetProp
98 var rect = TextureWithToggleableColorSingleLine(matEditor, label, textureProp, colorToggleProp, colorProp);
100 SetScaleOffsetKeywords(matEditor, textureProp, scaleOffsetProp);
107 matEditor.BeginAnimatedCheck(
108 #
if UNITY_2017_1_OR_NEWER
109 GetControlRectForSingleLine(),
113 EditorGUI.showMixedValue = scaleOffsetProp.hasMixedValue;
114 EditorGUI.BeginChangeCheck();
116 Vector4 scaleOffsetVector = scaleOffsetProp.vectorValue;
118 var textureScale =
new Vector2(scaleOffsetVector.x, scaleOffsetVector.y);
119 textureScale = EditorGUILayout.Vector2Field(Styles.scale, textureScale);
121 var textureOffset =
new Vector2(scaleOffsetVector.z, scaleOffsetVector.w);
122 textureOffset = EditorGUILayout.Vector2Field(Styles.offset, textureOffset);
124 if (EditorGUI.EndChangeCheck())
126 scaleOffsetProp.vectorValue =
new Vector4(textureScale.x, textureScale.y, textureOffset.x, textureOffset.y);
129 EditorGUI.showMixedValue =
false;
131 matEditor.EndAnimatedCheck();
136 return EditorGUILayout.GetControlRect(
true, 18f, EditorStyles.layerMaskField);
139 private static class Styles
141 public static GUIContent scale =
new GUIContent(
"Tiling",
"Scale of texture - multiplied by texture coordinates from vertices");
142 public static GUIContent offset =
new GUIContent(
"Offset",
"Offset of texture - added to texture coordinates from vertices");