|
1 | 1 | using System; |
2 | 2 | using System.Collections; |
3 | 3 | using System.Collections.Generic; |
| 4 | +using System.IO; |
4 | 5 | using Unity.UIWidgets.external.simplejson; |
5 | 6 | using Unity.UIWidgets.foundation; |
6 | 7 | using Unity.UIWidgets.rendering; |
|
11 | 12 | using UnityEngine.Profiling; |
12 | 13 | using UnityEngine.Scripting; |
13 | 14 | using UnityEngine.UI; |
| 15 | +using Path = System.IO.Path; |
14 | 16 | using RawImage = UnityEngine.UI.RawImage; |
15 | 17 |
|
16 | 18 | namespace Unity.UIWidgets.engine { |
@@ -66,19 +68,33 @@ public object fontsToObject() { |
66 | 68 | foreach (var setting in settings) { |
67 | 69 | var font = new Dictionary<string, object>(); |
68 | 70 | font.Add("family", value: setting.Key); |
69 | | - var dic = new Dictionary<string, object>[setting.Value.fonts.Length]; |
| 71 | + var dic = new List<Dictionary<string, object>>(); |
70 | 72 | for (var j = 0; j < setting.Value.fonts.Length; j++) { |
71 | | - dic[j] = new Dictionary<string, object>(); |
| 73 | + var fontDic = new Dictionary<string, object>(); |
| 74 | + var fileExist = false; |
| 75 | + |
72 | 76 | if (setting.Value.fonts[j].asset.Length > 0) { |
73 | | - dic[j].Add("asset", value: setting.Value.fonts[j].asset); |
| 77 | + var assetPath = setting.Value.fonts[j].asset; |
| 78 | + var assetAbsolutePath = Path.Combine(Application.streamingAssetsPath, assetPath); |
| 79 | + if (!File.Exists(assetAbsolutePath)) { |
| 80 | + Debug.LogError($"The font asset (family: \"{setting.Key}\", path: \"{assetPath}\") is not found"); |
| 81 | + } |
| 82 | + else { |
| 83 | + fileExist = true; |
| 84 | + } |
| 85 | + fontDic.Add("asset", value: setting.Value.fonts[j].asset); |
74 | 86 | } |
75 | 87 |
|
76 | 88 | if (setting.Value.fonts[j].weight > 0) { |
77 | | - dic[j].Add("weight", value: setting.Value.fonts[j].weight); |
| 89 | + fontDic.Add("weight", value: setting.Value.fonts[j].weight); |
| 90 | + } |
| 91 | + |
| 92 | + if (fileExist) { |
| 93 | + dic.Add(fontDic); |
78 | 94 | } |
79 | 95 | } |
80 | 96 |
|
81 | | - font.Add("fonts", value: dic); |
| 97 | + font.Add("fonts", value: dic.ToArray()); |
82 | 98 | result[i] = font; |
83 | 99 | i++; |
84 | 100 | } |
|
0 commit comments