|
|
|
|
|
|
using System.Collections; |
|
|
|
using System.Collections.Generic; |
|
|
|
using NUnit.Framework; |
|
|
|
using System.Linq; |
|
|
|
using Unity.UIWidgets.editor2; |
|
|
|
using Unity.UIWidgets.engine2; |
|
|
|
using Unity.UIWidgets.foundation; |
|
|
|
|
|
|
Input_OnDisable(); |
|
|
|
} |
|
|
|
|
|
|
|
protected virtual void onFill() {} |
|
|
|
protected virtual void loadConfiguration() {} |
|
|
|
List<UIWidgetsPanel.TextFont> _internalTextFonts = new List<UIWidgetsPanel.TextFont>(); |
|
|
|
Dictionary<string,UIWidgetsPanel.TextFont> _internalTextFonts = new Dictionary<string, UIWidgetsPanel.TextFont>(); |
|
|
|
int repeat = 0; |
|
|
|
for(int i = 0; i< _internalTextFonts.Count; i++ ) { |
|
|
|
if (_internalTextFonts[i].family == family) |
|
|
|
repeat++; |
|
|
|
if (assets.Count != weights.Count) { |
|
|
|
UnityEngine.Debug.Log($"The size of {family}‘s assets should be equal to the weights'."); |
|
|
|
return; |
|
|
|
if (repeat == 0) { |
|
|
|
UIWidgetsPanel.TextFont textFont = new UIWidgetsPanel.TextFont(); |
|
|
|
textFont.family = family; |
|
|
|
UIWidgetsPanel.Font[] fonts = new UIWidgetsPanel.Font[assets.Count]; |
|
|
|
for (int i = 0; i < assets.Count; i++) { |
|
|
|
UIWidgetsPanel.Font font = new UIWidgetsPanel.Font(); |
|
|
|
font.asset = assets[i]; |
|
|
|
font.weight = weights[i]; |
|
|
|
fonts[i] = font; |
|
|
|
} |
|
|
|
textFont.fonts = fonts; |
|
|
|
_internalTextFonts.Add(textFont); |
|
|
|
UIWidgetsPanel.TextFont textFont = new UIWidgetsPanel.TextFont(); |
|
|
|
textFont.family = family; |
|
|
|
UIWidgetsPanel.Font[] fonts = new UIWidgetsPanel.Font[assets.Count]; |
|
|
|
for (int j = 0; j < assets.Count; j++) { |
|
|
|
UIWidgetsPanel.Font font = new UIWidgetsPanel.Font(); |
|
|
|
font.asset = assets[j]; |
|
|
|
font.weight = weights[j]; |
|
|
|
fonts[j] = font; |
|
|
|
textFont.fonts = fonts; |
|
|
|
_internalTextFonts.Add(family,textFont); |
|
|
|
|
|
|
|
onFill(); |
|
|
|
loadConfiguration(); |
|
|
|
settings.Add("fonts", fontsToObject(textFonts)); |
|
|
|
|
|
|
|
settings.Add("fonts", _wrapper.fontsToObject(textFonts)); |
|
|
|
_wrapper.Initiate(this, _currentWidth, _currentHeight, _currentDevicePixelRatio, settings); |
|
|
|
Input_OnEnable(); |
|
|
|
} |
|
|
|
|
|
|
Input_OnGUIEvent(Event.current); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
static object fontsToObject(UIWidgetsPanel.TextFont[] textFont) { |
|
|
|
if (textFont == null || textFont.Length == 0) { |
|
|
|
return null; |
|
|
|
} |
|
|
|
var result = new object[textFont.Length]; |
|
|
|
for (int i = 0; i < textFont.Length; i++) { |
|
|
|
var font = new Dictionary<string, object>(); |
|
|
|
font.Add("family", textFont[i].family); |
|
|
|
var dic = new Dictionary<string, object>[textFont[i].fonts.Length]; |
|
|
|
for (int j = 0; j < textFont[i].fonts.Length; j++) { |
|
|
|
dic[j] = new Dictionary<string, object>(); |
|
|
|
if (textFont[i].fonts[j].asset.Length > 0) { |
|
|
|
dic[j].Add("asset", textFont[i].fonts[j].asset); |
|
|
|
} |
|
|
|
|
|
|
|
if (textFont[i].fonts[j].weight > 0) { |
|
|
|
dic[j].Add("weight", textFont[i].fonts[j].weight); |
|
|
|
} |
|
|
|
} |
|
|
|
font.Add("fonts", dic); |
|
|
|
result[i] = font; |
|
|
|
} |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
for (int i = 0; i < _internalTextFonts.Count; i++) { |
|
|
|
textFonts[i] = _internalTextFonts[i]; |
|
|
|
List<UIWidgetsPanel.TextFont> fontValues = _internalTextFonts.Values.ToList(); |
|
|
|
for (int i = 0; i < fontValues.Count; i++) { |
|
|
|
textFonts[i] = fontValues[i]; |
|
|
|
} |
|
|
|
return textFonts; |
|
|
|
} |
|
|
|