44using UnityEditor ;
55using UnityEngine ;
66
7- /// <summary>
8- /// Helper class for custom material editors
9- /// </summary>
10- public static class CustomMaterialEditor
7+ namespace HoloToolkit . Unity
118{
12- public static Rect TextureWithToggleableColorSingleLine
9+ /// <summary>
10+ /// Helper class for custom material editors
11+ /// </summary>
12+ public static class CustomMaterialEditor
13+ {
14+ public static Rect TextureWithToggleableColorSingleLine
1315 (
1416 MaterialEditor matEditor ,
1517 GUIContent label ,
1618 MaterialProperty textureProp ,
1719 MaterialProperty colorToggleProp ,
1820 MaterialProperty colorProp
1921 )
20- {
21- var lineRect = GetControlRectForSingleLine ( ) ;
22- var controlRect = lineRect ;
22+ {
23+ var lineRect = GetControlRectForSingleLine ( ) ;
24+ var controlRect = lineRect ;
2325
24- //TexturePropertyMiniThumbnail handles begin and end animation checks
25- matEditor . TexturePropertyMiniThumbnail ( lineRect , textureProp , label . text , label . tooltip ) ;
26+ //TexturePropertyMiniThumbnail handles begin and end animation checks
27+ matEditor . TexturePropertyMiniThumbnail ( lineRect , textureProp , label . text , label . tooltip ) ;
2628
27- controlRect . x += EditorGUIUtility . labelWidth ;
28- controlRect . width = EditorGUIUtility . fieldWidth ;
29+ controlRect . x += EditorGUIUtility . labelWidth ;
30+ controlRect . width = EditorGUIUtility . fieldWidth ;
2931
30- GUIContent toggleTooltip = new GUIContent ( ) ;
31- toggleTooltip . text = string . Empty ;
32- toggleTooltip . tooltip = "Enable/Disable color" ;
32+ GUIContent toggleTooltip = new GUIContent ( ) ;
33+ toggleTooltip . text = string . Empty ;
34+ toggleTooltip . tooltip = "Enable/Disable color" ;
3335
34- //label indent of -1 is the secret sauce to make it aligned with right aligned toggles that come after labels
35- //ShaderProperty handles begin and end animation checks
36- matEditor . ShaderProperty ( controlRect , colorToggleProp , toggleTooltip , - 1 ) ;
36+ //label indent of -1 is the secret sauce to make it aligned with right aligned toggles that come after labels
37+ //ShaderProperty handles begin and end animation checks
38+ matEditor . ShaderProperty ( controlRect , colorToggleProp , toggleTooltip , - 1 ) ;
3739
38- if ( colorToggleProp . floatValue != 0.0f )
39- {
40- controlRect . x += EditorStyles . toggle . fixedWidth ;
41- controlRect . x += EditorStyles . toggle . padding . right ;
40+ if ( colorToggleProp . floatValue != 0.0f )
41+ {
42+ controlRect . x += EditorStyles . toggle . fixedWidth ;
43+ controlRect . x += EditorStyles . toggle . padding . right ;
4244
43- //size it to take up the remainder of the space
44- controlRect . width = lineRect . width - controlRect . x ;
45+ //size it to take up the remainder of the space
46+ controlRect . width = lineRect . width - controlRect . x ;
4547
46- GUIContent tooltipOnly = new GUIContent ( ) ;
47- tooltipOnly . text = string . Empty ;
48- tooltipOnly . tooltip = label . tooltip ;
49- EditorGUI . BeginChangeCheck ( ) ;
48+ GUIContent tooltipOnly = new GUIContent ( ) ;
49+ tooltipOnly . text = string . Empty ;
50+ tooltipOnly . tooltip = label . tooltip ;
51+ EditorGUI . BeginChangeCheck ( ) ;
5052
51- var color = EditorGUI . ColorField ( controlRect , tooltipOnly , colorProp . colorValue ) ;
53+ var color = EditorGUI . ColorField ( controlRect , tooltipOnly , colorProp . colorValue ) ;
5254
53- if ( EditorGUI . EndChangeCheck ( ) )
54- {
55- colorProp . colorValue = color ;
55+ if ( EditorGUI . EndChangeCheck ( ) )
56+ {
57+ colorProp . colorValue = color ;
58+ }
5659 }
57- }
5860
59- return lineRect ;
60- }
61+ return lineRect ;
62+ }
6163
62- public static void SetScaleOffsetKeywords
64+ public static void SetScaleOffsetKeywords
6365 (
6466 MaterialEditor matEditor ,
6567 MaterialProperty textureProp ,
6668 MaterialProperty scaleOffsetProp
6769 )
68- {
69- var texScaleOffset = scaleOffsetProp . vectorValue ;
70- bool usesScale = texScaleOffset . x != 1.0f || texScaleOffset . y != 1.0f ;
71- bool usesOffset = texScaleOffset . z != 0.0f || texScaleOffset . w != 0.0f ;
70+ {
71+ var texScaleOffset = scaleOffsetProp . vectorValue ;
72+ bool usesScale = texScaleOffset . x != 1.0f || texScaleOffset . y != 1.0f ;
73+ bool usesOffset = texScaleOffset . z != 0.0f || texScaleOffset . w != 0.0f ;
7274
73- var mat = matEditor . target as Material ;
75+ var mat = matEditor . target as Material ;
7476
75- var scaleKeyword = textureProp . name + "_SCALE_ON" ;
76- var offsetKeyword = textureProp . name + "_OFFSET_ON" ;
77+ var scaleKeyword = textureProp . name + "_SCALE_ON" ;
78+ var offsetKeyword = textureProp . name + "_OFFSET_ON" ;
7779
78- ShaderGUIUtils . SetKeyword ( mat , scaleKeyword , usesScale ) ;
79- ShaderGUIUtils . SetKeyword ( mat , offsetKeyword , usesOffset ) ;
80- }
80+ ShaderGUIUtils . SetKeyword ( mat , scaleKeyword , usesScale ) ;
81+ ShaderGUIUtils . SetKeyword ( mat , offsetKeyword , usesOffset ) ;
82+ }
8183
82- public static Rect TextureWithToggleableColorAutoScaleOffsetSingleLine
84+ public static Rect TextureWithToggleableColorAutoScaleOffsetSingleLine
8385 (
8486 MaterialEditor matEditor ,
8587 GUIContent label ,
8688 MaterialProperty textureProp ,
8789 MaterialProperty colorToggleProp , MaterialProperty colorProp ,
8890 MaterialProperty scaleOffsetProp
8991 )
90- {
91- var rect = CustomMaterialEditor . TextureWithToggleableColorSingleLine ( matEditor , label , textureProp , colorToggleProp , colorProp ) ;
92+ {
93+ var rect = CustomMaterialEditor . TextureWithToggleableColorSingleLine ( matEditor , label , textureProp , colorToggleProp , colorProp ) ;
9294
93- CustomMaterialEditor . SetScaleOffsetKeywords ( matEditor , textureProp , scaleOffsetProp ) ;
95+ CustomMaterialEditor . SetScaleOffsetKeywords ( matEditor , textureProp , scaleOffsetProp ) ;
9496
95- return rect ;
96- }
97+ return rect ;
98+ }
9799
98- public static void TextureScaleOffsetVector4Property ( MaterialEditor matEditor , GUIContent label , MaterialProperty scaleOffsetProp )
99- {
100- matEditor . BeginAnimatedCheck ( scaleOffsetProp ) ;
100+ public static void TextureScaleOffsetVector4Property ( MaterialEditor matEditor , GUIContent label , MaterialProperty scaleOffsetProp )
101+ {
102+ matEditor . BeginAnimatedCheck ( scaleOffsetProp ) ;
101103
102- EditorGUI . BeginChangeCheck ( ) ;
104+ EditorGUI . BeginChangeCheck ( ) ;
103105
104- Vector4 scaleOffsetVector = scaleOffsetProp . vectorValue ;
106+ Vector4 scaleOffsetVector = scaleOffsetProp . vectorValue ;
105107
106- Vector2 textureScale = new Vector2 ( scaleOffsetVector . x , scaleOffsetVector . y ) ;
107- textureScale = EditorGUILayout . Vector2Field ( Styles . scale , textureScale , new GUILayoutOption [ 0 ] ) ;
108+ Vector2 textureScale = new Vector2 ( scaleOffsetVector . x , scaleOffsetVector . y ) ;
109+ textureScale = EditorGUILayout . Vector2Field ( Styles . scale , textureScale , new GUILayoutOption [ 0 ] ) ;
108110
109- Vector2 textureOffset = new Vector2 ( scaleOffsetVector . z , scaleOffsetVector . w ) ;
110- textureOffset = EditorGUILayout . Vector2Field ( Styles . offset , textureOffset , new GUILayoutOption [ 0 ] ) ;
111+ Vector2 textureOffset = new Vector2 ( scaleOffsetVector . z , scaleOffsetVector . w ) ;
112+ textureOffset = EditorGUILayout . Vector2Field ( Styles . offset , textureOffset , new GUILayoutOption [ 0 ] ) ;
111113
112- if ( EditorGUI . EndChangeCheck ( ) )
113- {
114- scaleOffsetProp . vectorValue = new Vector4 ( textureScale . x , textureScale . y , textureOffset . x , textureOffset . y ) ;
115- }
114+ if ( EditorGUI . EndChangeCheck ( ) )
115+ {
116+ scaleOffsetProp . vectorValue = new Vector4 ( textureScale . x , textureScale . y , textureOffset . x , textureOffset . y ) ;
117+ }
116118
117- matEditor . EndAnimatedCheck ( ) ;
118- }
119+ matEditor . EndAnimatedCheck ( ) ;
120+ }
119121
120- public static Rect GetControlRectForSingleLine ( )
121- {
122- return EditorGUILayout . GetControlRect ( true , 18f , EditorStyles . layerMaskField , new GUILayoutOption [ 0 ] ) ;
123- }
122+ public static Rect GetControlRectForSingleLine ( )
123+ {
124+ return EditorGUILayout . GetControlRect ( true , 18f , EditorStyles . layerMaskField , new GUILayoutOption [ 0 ] ) ;
125+ }
124126
125- private static class Styles
126- {
127- public static GUIContent scale = new GUIContent ( "Tiling" , "Scale of texture - multiplied by texture coordinates from vertices" ) ;
128- public static GUIContent offset = new GUIContent ( "Offset" , "Offset of texture - added to texture coordinates from vertices" ) ;
127+ private static class Styles
128+ {
129+ public static GUIContent scale = new GUIContent ( "Tiling" , "Scale of texture - multiplied by texture coordinates from vertices" ) ;
130+ public static GUIContent offset = new GUIContent ( "Offset" , "Offset of texture - added to texture coordinates from vertices" ) ;
131+ }
129132 }
130133}
0 commit comments