@@ -107,6 +107,8 @@ public override void OnInspectorGUI()
107107
108108 private int numColumns = 4 ;
109109 private Vector2 scrollAmount ;
110+ private float cachedTileSize = 0f ;
111+ private GUILayoutOption [ ] cachedButtonOptions ;
110112
111113 public void DrawIconGrid ( FontIconSelector fontIconSelector , float tileSize )
112114 {
@@ -120,6 +122,12 @@ public void DrawIconGrid(FontIconSelector fontIconSelector, float tileSize)
120122 List < KeyValuePair < string , uint > > sortedIcons = new List < KeyValuePair < string , uint > > ( fontIconSet . GlyphIconsByName ) ;
121123 sortedIcons . Sort ( ( a , b ) => a . Key . CompareTo ( b . Key ) ) ;
122124
125+ if ( cachedTileSize != tileSize || cachedButtonOptions == null )
126+ {
127+ cachedTileSize = tileSize ;
128+ cachedButtonOptions = new GUILayoutOption [ ] { GUILayout . Height ( tileSize ) , GUILayout . Width ( tileSize ) } ;
129+ }
130+
123131 foreach ( KeyValuePair < string , uint > kvp in sortedIcons )
124132 {
125133 string iconName = kvp . Key ;
@@ -132,9 +140,7 @@ public void DrawIconGrid(FontIconSelector fontIconSelector, float tileSize)
132140 EditorGUILayout . BeginHorizontal ( ) ;
133141 }
134142
135- if ( GUILayout . Button ( " " ,
136- GUILayout . Height ( tileSize ) ,
137- GUILayout . Width ( tileSize ) ) )
143+ if ( GUILayout . Button ( " " , cachedButtonOptions ) )
138144 {
139145 // Flush any pending changes from other Inspector fields (e.g. lost focus) manually editing the icon name
140146 serializedObject . ApplyModifiedProperties ( ) ;
0 commit comments