@@ -43,6 +43,12 @@ public class FontIconSetInspector : UnityEditor.Editor
4343 private string [ ] availableNamesArray = Array . Empty < string > ( ) ;
4444 private bool requiresUpdate = false ;
4545
46+ // Deferred State Variables
47+ private uint ? pendingIconToAdd = null ;
48+ private string pendingIconToRemove = null ;
49+ private string pendingIconToRenameOld = null ;
50+ private string pendingIconToRenameNew = null ;
51+
4652 /// <summary>
4753 /// A Unity event function that is called when the script component has been enabled.
4854 /// </summary>
@@ -127,10 +133,30 @@ private void UpdateIconEntries()
127133 /// </summary>
128134 public override void OnInspectorGUI ( )
129135 {
130- if ( requiresUpdate && Event . current . type == EventType . Layout )
136+ if ( Event . current . type == EventType . Layout )
131137 {
132- UpdateIconEntries ( ) ;
133- requiresUpdate = false ;
138+ if ( pendingIconToAdd . HasValue )
139+ {
140+ AddIcon ( ( FontIconSet ) target , pendingIconToAdd . Value ) ;
141+ pendingIconToAdd = null ;
142+ }
143+ if ( pendingIconToRemove != null )
144+ {
145+ RemoveIcon ( ( FontIconSet ) target , pendingIconToRemove ) ;
146+ pendingIconToRemove = null ;
147+ }
148+ if ( pendingIconToRenameOld != null && pendingIconToRenameNew != null )
149+ {
150+ UpdateIconName ( ( FontIconSet ) target , pendingIconToRenameOld , pendingIconToRenameNew ) ;
151+ pendingIconToRenameOld = null ;
152+ pendingIconToRenameNew = null ;
153+ }
154+
155+ if ( requiresUpdate )
156+ {
157+ UpdateIconEntries ( ) ;
158+ requiresUpdate = false ;
159+ }
134160 }
135161
136162 bool showGlyphIconFoldout = SessionState . GetBool ( ShowGlyphIconsFoldoutKey , false ) ;
@@ -148,8 +174,7 @@ public override void OnInspectorGUI()
148174 if ( EditorGUI . EndChangeCheck ( ) )
149175 {
150176 serializedObject . ApplyModifiedProperties ( ) ;
151- UpdateIconEntries ( ) ;
152- GUIUtility . ExitGUI ( ) ;
177+ requiresUpdate = true ;
153178 }
154179
155180 if ( iconFontAssetProp . objectReferenceValue == null )
@@ -227,14 +252,11 @@ public override void OnInspectorGUI()
227252 // Catch edge cases where the external asset size changes while this inspector is still focused
228253 if ( setDefinition . IconNames != null && validNames . Count != setDefinition . IconNames . Count )
229254 {
230- UpdateIconEntries ( ) ;
231- GUIUtility . ExitGUI ( ) ;
255+ requiresUpdate = true ;
232256 }
233257 }
234258
235259 int column = 0 ;
236- string iconToRemove = null ;
237- string iconToRename = null ;
238260 EditorGUILayout . BeginHorizontal ( ) ;
239261 foreach ( KeyValuePair < uint , string > iconEntry in iconEntries )
240262 {
@@ -251,7 +273,7 @@ public override void OnInspectorGUI()
251273 GUILayout . Height ( ButtonDimension ) ,
252274 GUILayout . MaxWidth ( ButtonDimension ) ) )
253275 {
254- iconToRemove = iconEntry . Value ;
276+ pendingIconToRemove = iconEntry . Value ;
255277 }
256278
257279 Rect textureRect = GUILayoutUtility . GetLastRect ( ) ;
@@ -275,8 +297,8 @@ public override void OnInspectorGUI()
275297 int selected = EditorGUILayout . Popup ( string . Empty , 0 , availableNamesArray , GUILayout . MaxWidth ( ButtonDimension ) ) ;
276298 if ( check . changed )
277299 {
278- iconToRename = availableNamesArray [ selected ] ;
279- iconToRemove = iconEntry . Value ;
300+ pendingIconToRenameNew = availableNamesArray [ selected ] ;
301+ pendingIconToRenameOld = iconEntry . Value ;
280302 }
281303 GUI . backgroundColor = oldColor ;
282304 }
@@ -286,26 +308,15 @@ public override void OnInspectorGUI()
286308 string currentName = EditorGUILayout . TextField ( iconEntry . Value ) ;
287309 if ( currentName != iconEntry . Value )
288310 {
289- iconToRename = currentName ;
290- iconToRemove = iconEntry . Value ;
311+ pendingIconToRenameNew = currentName ;
312+ pendingIconToRenameOld = iconEntry . Value ;
291313 }
292314 }
293315 EditorGUILayout . EndVertical ( ) ;
294316
295317 column ++ ;
296318 }
297319 EditorGUILayout . EndHorizontal ( ) ;
298-
299- if ( iconToRename != null )
300- {
301- UpdateIconName ( fontIconSet , iconToRemove , iconToRename ) ;
302- GUIUtility . ExitGUI ( ) ;
303- }
304- else if ( iconToRemove != null )
305- {
306- RemoveIcon ( fontIconSet , iconToRemove ) ;
307- GUIUtility . ExitGUI ( ) ;
308- }
309320 }
310321 else
311322 {
@@ -330,7 +341,7 @@ public override void OnInspectorGUI()
330341 [ Obsolete ( "This method has been deprecated in version 4.0 and will be removed in a future version." ) ]
331342 public void DrawFontGlyphsGrid ( FontIconSet fontIconSet , int maxButtonsPerColumn )
332343 {
333- DrawFontGlyphsGrid ( fontIconSet . IconFontAsset , fontIconSet , maxButtonsPerColumn ) ;
344+ DrawFontGlyphsGrid ( fontIconSet . IconFontAsset , maxButtonsPerColumn ) ;
334345 }
335346
336347 /// <summary>
@@ -339,10 +350,9 @@ public void DrawFontGlyphsGrid(FontIconSet fontIconSet, int maxButtonsPerColumn)
339350 /// <param name="fontAsset">The font asset containing the glyphs.</param>
340351 /// <param name="fontIconSet">The set of font glyphs to draw.</param>
341352 /// <param name="maxButtonsPerColumn">The number of buttons per column.</param>
342- private void DrawFontGlyphsGrid ( TMP_FontAsset fontAsset , FontIconSet fontIconSet , int maxButtonsPerColumn )
353+ private void DrawFontGlyphsGrid ( TMP_FontAsset fontAsset , int maxButtonsPerColumn )
343354 {
344355 int column = 0 ;
345- bool iconAdded = false ;
346356 EditorGUILayout . BeginHorizontal ( ) ;
347357 for ( int i = 0 ; i < fontAsset . characterTable . Count ; i ++ )
348358 {
@@ -359,8 +369,7 @@ private void DrawFontGlyphsGrid(TMP_FontAsset fontAsset, FontIconSet fontIconSet
359369 GUILayout . Height ( ButtonDimension ) ,
360370 GUILayout . MaxWidth ( ButtonDimension ) ) )
361371 {
362- AddIcon ( fontIconSet , fontAsset . characterTable [ i ] . unicode ) ;
363- iconAdded = true ;
372+ pendingIconToAdd = fontAsset . characterTable [ i ] . unicode ;
364373 }
365374
366375 Rect textureRect = GUILayoutUtility . GetLastRect ( ) ;
@@ -369,19 +378,9 @@ private void DrawFontGlyphsGrid(TMP_FontAsset fontAsset, FontIconSet fontIconSet
369378 EditorDrawTMPGlyph ( textureRect , fontAsset , fontAsset . characterTable [ i ] ) ;
370379 }
371380
372- if ( iconAdded )
373- {
374- break ;
375- }
376-
377381 column ++ ;
378382 }
379383 EditorGUILayout . EndHorizontal ( ) ;
380-
381- if ( iconAdded )
382- {
383- GUIUtility . ExitGUI ( ) ;
384- }
385384 }
386385
387386 private bool AddIcon ( FontIconSet fontIconSet , uint unicodeValue )
0 commit comments