Fix flag aspect ratio and font instantiation

This commit is contained in:
Andrew Cassidy 2020-12-04 17:05:37 -08:00
parent 35fce78616
commit 9dc98a6f9d
4 changed files with 13 additions and 11 deletions

View File

@ -50,8 +50,6 @@ namespace ConformalDecals {
public static IEnumerable<DecalFont> Fonts => _fontList.Values; public static IEnumerable<DecalFont> Fonts => _fontList.Values;
public static DecalFont FallbackFont { get; private set; }
public static bool IsBlacklisted(Shader shader) { public static bool IsBlacklisted(Shader shader) {
return IsBlacklisted(shader.name); return IsBlacklisted(shader.name);
} }
@ -96,7 +94,7 @@ namespace ConformalDecals {
foreach (var fontNode in node.GetNodes("FONT")) { foreach (var fontNode in node.GetNodes("FONT")) {
try { try {
var font = new DecalFont(fontNode, allFonts); var font = DecalFont.Parse(fontNode, allFonts);
_fontList.Add(font.Name, font); _fontList.Add(font.Name, font);
} }
catch (Exception e) { catch (Exception e) {

View File

@ -83,7 +83,7 @@ namespace ConformalDecals {
} }
protected override void UpdateTextures() { protected override void UpdateTextures() {
_flagTextureProperty ??= materialProperties.AddOrGetTextureProperty("_Decal"); _flagTextureProperty ??= materialProperties.AddOrGetTextureProperty("_Decal", true);
base.UpdateTextures(); base.UpdateTextures();
if (useCustomFlag) { if (useCustomFlag) {

View File

@ -46,21 +46,25 @@ namespace ConformalDecals.Text {
public bool SmallCapsMask => (_fontStyleMask & FontStyles.SmallCaps) != 0; public bool SmallCapsMask => (_fontStyleMask & FontStyles.SmallCaps) != 0;
public DecalFont(ConfigNode node, IEnumerable<TMP_FontAsset> fontAssets) { public static DecalFont Parse(ConfigNode node, IEnumerable<TMP_FontAsset> fontAssets) {
if (node == null) throw new ArgumentNullException(nameof(node)); if (node == null) throw new ArgumentNullException(nameof(node));
if (fontAssets == null) throw new ArgumentNullException(nameof(fontAssets)); if (fontAssets == null) throw new ArgumentNullException(nameof(fontAssets));
var font = ScriptableObject.CreateInstance<DecalFont>();
var name = ParseUtil.ParseString(node, "name"); var name = ParseUtil.ParseString(node, "name");
_fontAsset = fontAssets.First(o => o.name == name); var fontAsset = fontAssets.First(o => o.name == name);
if (FontAsset == null) { if (fontAsset == null) {
throw new FormatException($"Could not find font asset named {name}"); throw new FormatException($"Could not find font asset named {name}");
} }
_title = ParseUtil.ParseString(node, "title", true, name); font._fontAsset = fontAsset;
_fontStyle = (FontStyles) ParseUtil.ParseInt(node, "style", true); font._title = ParseUtil.ParseString(node, "title", true, name);
_fontStyleMask = (FontStyles) ParseUtil.ParseInt(node, "styleMask", true); font._fontStyle = (FontStyles) ParseUtil.ParseInt(node, "style", true);
} font._fontStyleMask = (FontStyles) ParseUtil.ParseInt(node, "styleMask", true);
return font;
}
public void SetupSample(TMP_Text tmp) { public void SetupSample(TMP_Text tmp) {
if (tmp == null) throw new ArgumentNullException(nameof(tmp)); if (tmp == null) throw new ArgumentNullException(nameof(tmp));