@@ -205,6 +205,7 @@ public static string ConvertUInt32ToUnicodeCharString(uint unicode)
205
205
private Texture [ ] spriteIconTextures = null ;
206
206
private static Material fontRenderMat ;
207
207
208
+ private const string missingPreviewImagesMessage = "Not all icon previews were loaded. Check the settings of the icons included in your iconset." ;
208
209
private const string noIconFontMessage = "No icon font selected. Icon fonts will be unavailable." ;
209
210
private const string downloadIconFontMessage = "For instructions on how to install the HoloLens icon font, click the button below." ;
210
211
private const string hololensIconFontUrl = "https://docs.microsoft.com/windows/mixed-reality/mrtk-unity/features/ux-building-blocks/button" ;
@@ -344,8 +345,16 @@ public bool EditorDrawSpriteIconSelector(Sprite currentSprite, out bool foundSpr
344
345
{
345
346
float height = maxButtonSize * ( ( float ) spriteIcons . Length / maxButtonsPerColumn ) ;
346
347
var maxHeight = GUILayout . MaxHeight ( height ) ;
348
+
349
+ bool allPreviewsLoaded ;
350
+ var gridContent = GenerateGridContent ( spriteIconTextures , out allPreviewsLoaded ) ;
351
+
352
+ if ( ! allPreviewsLoaded )
353
+ {
354
+ EditorGUILayout . HelpBox ( missingPreviewImagesMessage , MessageType . Warning ) ;
355
+ }
347
356
#if UNITY_2019_3_OR_NEWER
348
- int newSelection = GUILayout . SelectionGrid ( currentSelection , spriteIconTextures , maxButtonsPerColumn , maxHeight ) ;
357
+ int newSelection = GUILayout . SelectionGrid ( currentSelection , gridContent , maxButtonsPerColumn , maxHeight ) ;
349
358
#else
350
359
var maxWidth = GUILayout . MaxWidth ( maxButtonSize * maxButtonsPerColumn ) ;
351
360
int newSelection = GUILayout . SelectionGrid ( currentSelection , spriteIconTextures , maxButtonsPerColumn , maxHeight , maxWidth ) ;
@@ -363,7 +372,6 @@ public bool EditorDrawSpriteIconSelector(Sprite currentSprite, out bool foundSpr
363
372
return newSprite != null ;
364
373
}
365
374
366
-
367
375
/// <summary>
368
376
/// Updates the cached sprite icon textures to the latest textures in spriteIcons
369
377
/// </summary>
@@ -420,8 +428,16 @@ public bool EditorDrawQuadIconSelector(Texture currentTexture, out bool foundTex
420
428
{
421
429
float height = maxButtonSize * ( ( float ) quadIcons . Length / maxButtonsPerColumn ) ;
422
430
var maxHeight = GUILayout . MaxHeight ( height ) ;
431
+
432
+ bool allPreviewsLoaded ;
433
+ var gridContent = GenerateGridContent ( quadIcons , out allPreviewsLoaded ) ;
434
+
435
+ if ( ! allPreviewsLoaded )
436
+ {
437
+ EditorGUILayout . HelpBox ( missingPreviewImagesMessage , MessageType . Warning ) ;
438
+ }
423
439
#if UNITY_2019_3_OR_NEWER
424
- int newSelection = GUILayout . SelectionGrid ( currentSelection , quadIcons , maxButtonsPerColumn , maxHeight ) ;
440
+ int newSelection = GUILayout . SelectionGrid ( currentSelection , gridContent , maxButtonsPerColumn , maxHeight ) ;
425
441
#else
426
442
var maxWidth = GUILayout . MaxWidth ( maxButtonSize * maxButtonsPerColumn ) ;
427
443
int newSelection = GUILayout . SelectionGrid ( currentSelection , quadIcons , maxButtonsPerColumn , maxHeight , maxWidth ) ;
@@ -544,6 +560,27 @@ public bool EditorAddCustomQuadIcon(Texture customQuadIcon)
544
560
return true ;
545
561
}
546
562
563
+ public GUIContent [ ] GenerateGridContent ( Texture [ ] previewTextures , out bool allPreviewsLoaded )
564
+ {
565
+ GUIContent [ ] gridContent = new GUIContent [ previewTextures . Length ] ;
566
+ allPreviewsLoaded = true ;
567
+
568
+ for ( int i = 0 ; i < previewTextures . Length ; i ++ )
569
+ {
570
+ if ( previewTextures [ i ] != null )
571
+ {
572
+ gridContent [ i ] = new GUIContent ( previewTextures [ i ] ) ;
573
+ }
574
+ else
575
+ {
576
+ gridContent [ i ] = new GUIContent ( "N/A" ) ;
577
+ allPreviewsLoaded = false ;
578
+ }
579
+ }
580
+
581
+ return gridContent ;
582
+ }
583
+
547
584
[ CustomEditor ( typeof ( ButtonIconSet ) ) ]
548
585
private class ButtonIconSetInspector : UnityEditor . Editor
549
586
{
@@ -578,6 +615,7 @@ public override void OnInspectorGUI()
578
615
579
616
#if UNITY_2019_3_OR_NEWER
580
617
showQuadIconFoldout = EditorGUILayout . BeginFoldoutHeaderGroup ( showQuadIconFoldout , "Quad Icons" ) ;
618
+ EditorGUILayout . EndFoldoutHeaderGroup ( ) ;
581
619
#else
582
620
showQuadIconFoldout = EditorGUILayout . Foldout ( showQuadIconFoldout , "Quad Icons" ) ;
583
621
#endif
@@ -589,12 +627,10 @@ public override void OnInspectorGUI()
589
627
EditorGUILayout . PropertyField ( quadIconsProp , true ) ;
590
628
}
591
629
}
592
- #if UNITY_2019_3_OR_NEWER
593
- EditorGUILayout . EndFoldoutHeaderGroup ( ) ;
594
- #endif
595
630
596
631
#if UNITY_2019_3_OR_NEWER
597
632
showSpriteIconFoldout = EditorGUILayout . BeginFoldoutHeaderGroup ( showSpriteIconFoldout , "Sprite Icons" ) ;
633
+ EditorGUILayout . EndFoldoutHeaderGroup ( ) ;
598
634
#else
599
635
showSpriteIconFoldout = EditorGUILayout . Foldout ( showSpriteIconFoldout , "Sprite Icons" ) ;
600
636
#endif
@@ -615,21 +651,14 @@ public override void OnInspectorGUI()
615
651
}
616
652
}
617
653
}
618
- #if UNITY_2019_3_OR_NEWER
619
- EditorGUILayout . EndFoldoutHeaderGroup ( ) ;
620
- #endif
621
654
622
655
#if UNITY_2019_3_OR_NEWER
623
656
showCharIconFoldout = EditorGUILayout . BeginFoldoutHeaderGroup ( showCharIconFoldout , "Font Icons" ) ;
657
+ EditorGUILayout . EndFoldoutHeaderGroup ( ) ;
624
658
#else
625
659
showCharIconFoldout = EditorGUILayout . Foldout ( showCharIconFoldout , "Font Icons" ) ;
626
660
#endif
627
661
628
-
629
- #if UNITY_2019_3_OR_NEWER
630
- EditorGUILayout . EndFoldoutHeaderGroup ( ) ;
631
- #endif
632
-
633
662
if ( showCharIconFoldout )
634
663
{
635
664
EditorGUILayout . PropertyField ( charIconFontProp ) ;
@@ -823,6 +852,11 @@ private bool CheckIfHololensIconFontExists()
823
852
824
853
Texture2D GetTextureFromSprite ( Sprite sprite )
825
854
{
855
+ if ( sprite == null || sprite . texture == null )
856
+ {
857
+ return null ;
858
+ }
859
+
826
860
var rect = sprite . rect ;
827
861
var tex = new Texture2D ( ( int ) rect . width , ( int ) rect . height ) ;
828
862
var data = sprite . texture . GetPixels ( ( int ) rect . x , ( int ) rect . y , ( int ) rect . width , ( int ) rect . height ) ;
0 commit comments