summaryrefslogtreecommitdiff
path: root/Client/Assembly-CSharp/TextController.cs
blob: c98db4ec652c21a6c895a6a0f1e98f28ae912b23 (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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
using System;
using UnityEngine;

[RequireComponent(typeof(MeshFilter))]
[RequireComponent(typeof(MeshRenderer))]
public class TextController : MonoBehaviour
{
	public float Scale = 1f;

	[Multiline]
	public string Text;

	private string displaying;

	[HideInInspector]
	private Texture2D texture;

	[HideInInspector]
	private Texture2D colorTexture;

	private MeshRenderer rend;

	private float _scale = float.NegativeInfinity;

	public Color Color = Color.white;

	private Color lastColor;

	public Vector3 Offset;

	public bool topAligned;

	public void Update()
	{
		if (!this.rend)
		{
			this.rend = base.GetComponent<MeshRenderer>();
		}
		if (string.IsNullOrEmpty(this.Text))
		{
			this.rend.enabled = false;
			return;
		}
		if (this.displaying == null || this.displaying.GetHashCode() != this.Text.GetHashCode() || this.Color != this.lastColor)
		{
			int num = 0;
			int num2 = 0;
			int num3 = 1;
			for (int i = 0; i < this.Text.Length; i++)
			{
				if (this.Text[i] == '\n')
				{
					num2 = 0;
					num3++;
				}
				else
				{
					num2++;
					if (num2 > num)
					{
						num = num2;
					}
				}
			}
			if (!this.texture || !this.colorTexture)
			{
				if (!this.texture)
				{
					this.texture = new Texture2D(num, num3, TextureFormat.ARGB32, false);
					this.texture.filterMode = FilterMode.Point;
					this.texture.wrapMode = TextureWrapMode.Clamp;
				}
				if (!this.colorTexture)
				{
					this.colorTexture = new Texture2D(num, num3, TextureFormat.ARGB32, false);
					this.colorTexture.filterMode = FilterMode.Point;
					this.colorTexture.wrapMode = TextureWrapMode.Clamp;
				}
			}
			else if (this.texture.width != num || this.texture.height != num3)
			{
				this.texture.Resize(num, num3, TextureFormat.ARGB32, false);
				this.colorTexture.Resize(num, num3, TextureFormat.ARGB32, false);
			}
			Color[] array = new Color[num * num3];
			array.SetAll(this.Color);
			this.colorTexture.SetPixels(array);
			array.SetAll(new Color(0.125f, 0f, 0f));
			this.texture.SetPixels(array);
			int num4 = 0;
			int num5 = this.texture.height - 1;
			Color color = this.Color;
			for (int j = 0; j < this.Text.Length; j++)
			{
				char c = this.Text[j];
				if (c != '\r')
				{
					if (c == '\n')
					{
						num4 = 0;
						num5--;
					}
					else
					{
						this.texture.SetPixel(num4, num5, new Color((float)c / 256f, 0f, 0f));
						this.colorTexture.SetPixel(num4, num5, color);
						num4++;
					}
				}
			}
			this.texture.Apply(false, false);
			this.colorTexture.Apply(false, false);
			this.rend.enabled = true;
			this.rend.material.SetTexture("_InputTex", this.texture);
			this.rend.material.SetTexture("_ColorTex", this.colorTexture);
			this._scale = float.NegativeInfinity;
			this.displaying = this.Text;
			this.lastColor = this.Color;
		}
		if (this._scale != this.Scale)
		{
			this._scale = this.Scale;
			base.transform.localScale = new Vector3((float)this.texture.width, (float)this.texture.height, 1f) * this.Scale;
			if (this.topAligned)
			{
				base.transform.localPosition = this.Offset + new Vector3((float)this.texture.width * this.Scale / 2f, (float)(-(float)this.texture.height) * this.Scale / 2f, 0f);
			}
		}
	}
}