@@ -9,14 +9,10 @@ internal static class BitmapFontCreator
9
9
{
10
10
private const char IgnoreCharacter = ' ' ;
11
11
12
- public static void TryCreateFont ( ExecutionData data , bool warnBeforeOverwrite )
12
+ public static bool TryCreateFont ( ExecutionData data , bool warnBeforeOverwrite , out string error )
13
13
{
14
- var error = CheckForErrors ( data ) ;
15
- if ( ! string . IsNullOrEmpty ( error ) )
16
- {
17
- Debug . LogError ( error ) ;
18
- return ;
19
- }
14
+ error = CheckForErrors ( data ) ;
15
+ if ( ! string . IsNullOrEmpty ( error ) ) return false ;
20
16
21
17
var path = AssetDatabase . GetAssetPath ( data . Texture ) ;
22
18
var baseName = Path . GetFileNameWithoutExtension ( path ) ;
@@ -27,16 +23,18 @@ public static void TryCreateFont(ExecutionData data, bool warnBeforeOverwrite)
27
23
if ( warnBeforeOverwrite && ! ( AssetDatabase . GUIDFromAssetPath ( materialPath ) == null && AssetDatabase . GUIDFromAssetPath ( fontPath ) == null ) )
28
24
{
29
25
if ( ! EditorUtility . DisplayDialog ( "Warning" , "Asset already exists. Overwrite? (It will keep the references)" , "Yes" , "No" ) )
30
- return ;
26
+ return false ;
31
27
}
32
28
33
29
var material = CreateMaterial ( baseName , data . Texture ) ;
34
- var font = CreateFontAsset ( baseName , material , data ) ;
30
+ var font = CreateFontAsset ( baseName , material , data , out error ) ;
31
+ if ( ! string . IsNullOrEmpty ( error ) ) return false ;
35
32
36
33
AssetDatabase . CreateAsset ( material , materialPath ) ;
37
34
CreateOrReplaceAsset ( font , fontPath ) ;
38
35
39
36
AssetDatabase . Refresh ( ) ;
37
+ return true ;
40
38
}
41
39
42
40
private static string CheckForErrors ( ExecutionData data )
@@ -62,11 +60,20 @@ private static Material CreateMaterial(string baseName, Texture2D texture)
62
60
} ;
63
61
}
64
62
65
- private static Font CreateFontAsset ( string baseName , Material material , ExecutionData data )
63
+ private static Font CreateFontAsset ( string baseName , Material material , ExecutionData data , out string error )
66
64
{
65
+ error = null ;
67
66
var map = new Dictionary < char , CharacterProps > ( ) ;
68
- foreach ( var e in data . CustomCharacterProps )
67
+ for ( var i = 0 ; i < data . CustomCharacterProps . Count ; i ++ )
68
+ {
69
+ var e = data . CustomCharacterProps [ i ] ;
70
+ if ( string . IsNullOrEmpty ( e . Character ) )
71
+ {
72
+ error = $ "Character for Custom Character Properties at position { i + 1 } is empty";
73
+ return null ;
74
+ }
69
75
map . Add ( e . Character [ 0 ] , e ) ;
76
+ }
70
77
71
78
return new Font ( baseName )
72
79
{
0 commit comments