summaryrefslogtreecommitdiff
path: root/Client/Assembly-CSharp/FontCache.cs
blob: 91dc7a0ab41782a03cd979b5ab3688aa5083ea28 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
using System;
using System.Collections.Generic;
using UnityEngine;

public class FontCache : MonoBehaviour
{
	public static FontCache Instance;

	private Dictionary<string, FontData> cache = new Dictionary<string, FontData>();

	public List<FontExtensionData> extraData = new List<FontExtensionData>();

	public List<TextAsset> DefaultFonts = new List<TextAsset>();

	public List<Material> DefaultFontMaterials = new List<Material>();

	public void OnEnable()
	{
		if (!FontCache.Instance)
		{
			FontCache.Instance = this;
			UnityEngine.Object.DontDestroyOnLoad(base.gameObject);
			return;
		}
		if (FontCache.Instance != null)
		{
			UnityEngine.Object.Destroy(base.gameObject);
		}
	}

	public void SetFont(TextRenderer self, string name)
	{
		if (self.FontData.name == name)
		{
			return;
		}
		for (int i = 0; i < this.DefaultFonts.Count; i++)
		{
			if (this.DefaultFonts[i].name == name)
			{
				MeshRenderer component = self.GetComponent<MeshRenderer>();
				Material material = component.material;
				self.FontData = this.DefaultFonts[i];
				component.sharedMaterial = this.DefaultFontMaterials[i];
				component.material.SetColor("_OutlineColor", material.GetColor("_OutlineColor"));
				component.material.SetInt("_Mask", material.GetInt("_Mask"));
				return;
			}
		}
	}

	public FontData LoadFont(TextAsset dataSrc)
	{
		if (this.cache == null)
		{
			this.cache = new Dictionary<string, FontData>();
		}
		FontData fontData;
		if (this.cache.TryGetValue(dataSrc.name, out fontData))
		{
			return fontData;
		}
		int num = this.extraData.FindIndex((FontExtensionData ed) => ed.FontName.Equals(dataSrc.name, StringComparison.OrdinalIgnoreCase));
		FontExtensionData eData = null;
		if (num >= 0)
		{
			eData = this.extraData[num];
		}
		fontData = FontCache.LoadFontUncached(dataSrc, eData);
		this.cache[dataSrc.name] = fontData;
		return fontData;
	}

	public static FontData LoadFontUncached(TextAsset dataSrc, FontExtensionData eData = null)
	{
		return FontLoader.FromBinary(dataSrc, eData);
	}
}