Files
2026-06-04 11:42:34 +02:00

648 lines
16 KiB
C#

using System;
using System.Collections.Generic;
namespace UnityEngine.UI
{
// Token: 0x0200007D RID: 125
[AddComponentMenu("UI/Text", 10)]
public class Text : MaskableGraphic, ILayoutElement
{
// Token: 0x06000497 RID: 1175 RVA: 0x00019345 File Offset: 0x00017745
protected Text()
{
base.useLegacyMeshGeneration = false;
}
// Token: 0x1700013C RID: 316
// (get) Token: 0x06000498 RID: 1176 RVA: 0x00019380 File Offset: 0x00017780
public TextGenerator cachedTextGenerator
{
get
{
TextGenerator textGenerator;
if ((textGenerator = this.m_TextCache) == null)
{
textGenerator = (this.m_TextCache = ((this.m_Text.Length == 0) ? new TextGenerator() : new TextGenerator(this.m_Text.Length)));
}
return textGenerator;
}
}
// Token: 0x1700013D RID: 317
// (get) Token: 0x06000499 RID: 1177 RVA: 0x000193D8 File Offset: 0x000177D8
public TextGenerator cachedTextGeneratorForLayout
{
get
{
TextGenerator textGenerator;
if ((textGenerator = this.m_TextCacheForLayout) == null)
{
textGenerator = (this.m_TextCacheForLayout = new TextGenerator());
}
return textGenerator;
}
}
// Token: 0x1700013E RID: 318
// (get) Token: 0x0600049A RID: 1178 RVA: 0x00019408 File Offset: 0x00017808
public override Texture mainTexture
{
get
{
Texture texture;
if (this.font != null && this.font.material != null && this.font.material.mainTexture != null)
{
texture = this.font.material.mainTexture;
}
else if (this.m_Material != null)
{
texture = this.m_Material.mainTexture;
}
else
{
texture = base.mainTexture;
}
return texture;
}
}
// Token: 0x0600049B RID: 1179 RVA: 0x000194A0 File Offset: 0x000178A0
public void FontTextureChanged()
{
if (this)
{
if (!this.m_DisableFontTextureRebuiltCallback)
{
this.cachedTextGenerator.Invalidate();
if (this.IsActive())
{
if (CanvasUpdateRegistry.IsRebuildingGraphics() || CanvasUpdateRegistry.IsRebuildingLayout())
{
this.UpdateGeometry();
}
else
{
this.SetAllDirty();
}
}
}
}
}
// Token: 0x1700013F RID: 319
// (get) Token: 0x0600049C RID: 1180 RVA: 0x00019510 File Offset: 0x00017910
// (set) Token: 0x0600049D RID: 1181 RVA: 0x00019530 File Offset: 0x00017930
public Font font
{
get
{
return this.m_FontData.font;
}
set
{
if (!(this.m_FontData.font == value))
{
FontUpdateTracker.UntrackText(this);
this.m_FontData.font = value;
FontUpdateTracker.TrackText(this);
this.SetAllDirty();
}
}
}
// Token: 0x17000140 RID: 320
// (get) Token: 0x0600049E RID: 1182 RVA: 0x0001956C File Offset: 0x0001796C
// (set) Token: 0x0600049F RID: 1183 RVA: 0x00019588 File Offset: 0x00017988
public virtual string text
{
get
{
return this.m_Text;
}
set
{
if (string.IsNullOrEmpty(value))
{
if (!string.IsNullOrEmpty(this.m_Text))
{
this.m_Text = "";
this.SetVerticesDirty();
}
}
else if (this.m_Text != value)
{
this.m_Text = value;
this.SetVerticesDirty();
this.SetLayoutDirty();
}
}
}
// Token: 0x17000141 RID: 321
// (get) Token: 0x060004A0 RID: 1184 RVA: 0x000195F4 File Offset: 0x000179F4
// (set) Token: 0x060004A1 RID: 1185 RVA: 0x00019614 File Offset: 0x00017A14
public bool supportRichText
{
get
{
return this.m_FontData.richText;
}
set
{
if (this.m_FontData.richText != value)
{
this.m_FontData.richText = value;
this.SetVerticesDirty();
this.SetLayoutDirty();
}
}
}
// Token: 0x17000142 RID: 322
// (get) Token: 0x060004A2 RID: 1186 RVA: 0x00019648 File Offset: 0x00017A48
// (set) Token: 0x060004A3 RID: 1187 RVA: 0x00019668 File Offset: 0x00017A68
public bool resizeTextForBestFit
{
get
{
return this.m_FontData.bestFit;
}
set
{
if (this.m_FontData.bestFit != value)
{
this.m_FontData.bestFit = value;
this.SetVerticesDirty();
this.SetLayoutDirty();
}
}
}
// Token: 0x17000143 RID: 323
// (get) Token: 0x060004A4 RID: 1188 RVA: 0x0001969C File Offset: 0x00017A9C
// (set) Token: 0x060004A5 RID: 1189 RVA: 0x000196BC File Offset: 0x00017ABC
public int resizeTextMinSize
{
get
{
return this.m_FontData.minSize;
}
set
{
if (this.m_FontData.minSize != value)
{
this.m_FontData.minSize = value;
this.SetVerticesDirty();
this.SetLayoutDirty();
}
}
}
// Token: 0x17000144 RID: 324
// (get) Token: 0x060004A6 RID: 1190 RVA: 0x000196F0 File Offset: 0x00017AF0
// (set) Token: 0x060004A7 RID: 1191 RVA: 0x00019710 File Offset: 0x00017B10
public int resizeTextMaxSize
{
get
{
return this.m_FontData.maxSize;
}
set
{
if (this.m_FontData.maxSize != value)
{
this.m_FontData.maxSize = value;
this.SetVerticesDirty();
this.SetLayoutDirty();
}
}
}
// Token: 0x17000145 RID: 325
// (get) Token: 0x060004A8 RID: 1192 RVA: 0x00019744 File Offset: 0x00017B44
// (set) Token: 0x060004A9 RID: 1193 RVA: 0x00019764 File Offset: 0x00017B64
public TextAnchor alignment
{
get
{
return this.m_FontData.alignment;
}
set
{
if (this.m_FontData.alignment != value)
{
this.m_FontData.alignment = value;
this.SetVerticesDirty();
this.SetLayoutDirty();
}
}
}
// Token: 0x17000146 RID: 326
// (get) Token: 0x060004AA RID: 1194 RVA: 0x00019798 File Offset: 0x00017B98
// (set) Token: 0x060004AB RID: 1195 RVA: 0x000197B8 File Offset: 0x00017BB8
public bool alignByGeometry
{
get
{
return this.m_FontData.alignByGeometry;
}
set
{
if (this.m_FontData.alignByGeometry != value)
{
this.m_FontData.alignByGeometry = value;
this.SetVerticesDirty();
}
}
}
// Token: 0x17000147 RID: 327
// (get) Token: 0x060004AC RID: 1196 RVA: 0x000197E4 File Offset: 0x00017BE4
// (set) Token: 0x060004AD RID: 1197 RVA: 0x00019804 File Offset: 0x00017C04
public int fontSize
{
get
{
return this.m_FontData.fontSize;
}
set
{
if (this.m_FontData.fontSize != value)
{
this.m_FontData.fontSize = value;
this.SetVerticesDirty();
this.SetLayoutDirty();
}
}
}
// Token: 0x17000148 RID: 328
// (get) Token: 0x060004AE RID: 1198 RVA: 0x00019838 File Offset: 0x00017C38
// (set) Token: 0x060004AF RID: 1199 RVA: 0x00019858 File Offset: 0x00017C58
public HorizontalWrapMode horizontalOverflow
{
get
{
return this.m_FontData.horizontalOverflow;
}
set
{
if (this.m_FontData.horizontalOverflow != value)
{
this.m_FontData.horizontalOverflow = value;
this.SetVerticesDirty();
this.SetLayoutDirty();
}
}
}
// Token: 0x17000149 RID: 329
// (get) Token: 0x060004B0 RID: 1200 RVA: 0x0001988C File Offset: 0x00017C8C
// (set) Token: 0x060004B1 RID: 1201 RVA: 0x000198AC File Offset: 0x00017CAC
public VerticalWrapMode verticalOverflow
{
get
{
return this.m_FontData.verticalOverflow;
}
set
{
if (this.m_FontData.verticalOverflow != value)
{
this.m_FontData.verticalOverflow = value;
this.SetVerticesDirty();
this.SetLayoutDirty();
}
}
}
// Token: 0x1700014A RID: 330
// (get) Token: 0x060004B2 RID: 1202 RVA: 0x000198E0 File Offset: 0x00017CE0
// (set) Token: 0x060004B3 RID: 1203 RVA: 0x00019900 File Offset: 0x00017D00
public float lineSpacing
{
get
{
return this.m_FontData.lineSpacing;
}
set
{
if (this.m_FontData.lineSpacing != value)
{
this.m_FontData.lineSpacing = value;
this.SetVerticesDirty();
this.SetLayoutDirty();
}
}
}
// Token: 0x1700014B RID: 331
// (get) Token: 0x060004B4 RID: 1204 RVA: 0x00019934 File Offset: 0x00017D34
// (set) Token: 0x060004B5 RID: 1205 RVA: 0x00019954 File Offset: 0x00017D54
public FontStyle fontStyle
{
get
{
return this.m_FontData.fontStyle;
}
set
{
if (this.m_FontData.fontStyle != value)
{
this.m_FontData.fontStyle = value;
this.SetVerticesDirty();
this.SetLayoutDirty();
}
}
}
// Token: 0x1700014C RID: 332
// (get) Token: 0x060004B6 RID: 1206 RVA: 0x00019988 File Offset: 0x00017D88
public float pixelsPerUnit
{
get
{
Canvas canvas = base.canvas;
float num;
if (!canvas)
{
num = 1f;
}
else if (!this.font || this.font.dynamic)
{
num = canvas.scaleFactor;
}
else if (this.m_FontData.fontSize <= 0 || this.font.fontSize <= 0)
{
num = 1f;
}
else
{
num = (float)this.font.fontSize / (float)this.m_FontData.fontSize;
}
return num;
}
}
// Token: 0x060004B7 RID: 1207 RVA: 0x00019A2C File Offset: 0x00017E2C
protected override void OnEnable()
{
base.OnEnable();
this.cachedTextGenerator.Invalidate();
FontUpdateTracker.TrackText(this);
}
// Token: 0x060004B8 RID: 1208 RVA: 0x00019A46 File Offset: 0x00017E46
protected override void OnDisable()
{
FontUpdateTracker.UntrackText(this);
base.OnDisable();
}
// Token: 0x060004B9 RID: 1209 RVA: 0x00019A55 File Offset: 0x00017E55
protected override void UpdateGeometry()
{
if (this.font != null)
{
base.UpdateGeometry();
}
}
// Token: 0x060004BA RID: 1210 RVA: 0x00019A71 File Offset: 0x00017E71
internal void AssignDefaultFont()
{
this.font = Resources.GetBuiltinResource<Font>("Arial.ttf");
}
// Token: 0x060004BB RID: 1211 RVA: 0x00019A84 File Offset: 0x00017E84
public TextGenerationSettings GetGenerationSettings(Vector2 extents)
{
TextGenerationSettings textGenerationSettings = default(TextGenerationSettings);
textGenerationSettings.generationExtents = extents;
if (this.font != null && this.font.dynamic)
{
textGenerationSettings.fontSize = this.m_FontData.fontSize;
textGenerationSettings.resizeTextMinSize = this.m_FontData.minSize;
textGenerationSettings.resizeTextMaxSize = this.m_FontData.maxSize;
}
textGenerationSettings.textAnchor = this.m_FontData.alignment;
textGenerationSettings.alignByGeometry = this.m_FontData.alignByGeometry;
textGenerationSettings.scaleFactor = this.pixelsPerUnit;
textGenerationSettings.color = this.color;
textGenerationSettings.font = this.font;
textGenerationSettings.pivot = base.rectTransform.pivot;
textGenerationSettings.richText = this.m_FontData.richText;
textGenerationSettings.lineSpacing = this.m_FontData.lineSpacing;
textGenerationSettings.fontStyle = this.m_FontData.fontStyle;
textGenerationSettings.resizeTextForBestFit = this.m_FontData.bestFit;
textGenerationSettings.updateBounds = false;
textGenerationSettings.horizontalOverflow = this.m_FontData.horizontalOverflow;
textGenerationSettings.verticalOverflow = this.m_FontData.verticalOverflow;
return textGenerationSettings;
}
// Token: 0x060004BC RID: 1212 RVA: 0x00019BD4 File Offset: 0x00017FD4
public static Vector2 GetTextAnchorPivot(TextAnchor anchor)
{
Vector2 vector;
switch (anchor)
{
case TextAnchor.UpperLeft:
vector = new Vector2(0f, 1f);
break;
case TextAnchor.UpperCenter:
vector = new Vector2(0.5f, 1f);
break;
case TextAnchor.UpperRight:
vector = new Vector2(1f, 1f);
break;
case TextAnchor.MiddleLeft:
vector = new Vector2(0f, 0.5f);
break;
case TextAnchor.MiddleCenter:
vector = new Vector2(0.5f, 0.5f);
break;
case TextAnchor.MiddleRight:
vector = new Vector2(1f, 0.5f);
break;
case TextAnchor.LowerLeft:
vector = new Vector2(0f, 0f);
break;
case TextAnchor.LowerCenter:
vector = new Vector2(0.5f, 0f);
break;
case TextAnchor.LowerRight:
vector = new Vector2(1f, 0f);
break;
default:
vector = Vector2.zero;
break;
}
return vector;
}
// Token: 0x060004BD RID: 1213 RVA: 0x00019CDC File Offset: 0x000180DC
protected override void OnPopulateMesh(VertexHelper toFill)
{
if (!(this.font == null))
{
this.m_DisableFontTextureRebuiltCallback = true;
Vector2 size = base.rectTransform.rect.size;
TextGenerationSettings generationSettings = this.GetGenerationSettings(size);
this.cachedTextGenerator.PopulateWithErrors(this.text, generationSettings, base.gameObject);
IList<UIVertex> verts = this.cachedTextGenerator.verts;
float num = 1f / this.pixelsPerUnit;
int num2 = verts.Count - 4;
Vector2 vector = new Vector2(verts[0].position.x, verts[0].position.y) * num;
vector = base.PixelAdjustPoint(vector) - vector;
toFill.Clear();
if (vector != Vector2.zero)
{
for (int i = 0; i < num2; i++)
{
int num3 = i & 3;
this.m_TempVerts[num3] = verts[i];
UIVertex[] tempVerts = this.m_TempVerts;
int num4 = num3;
tempVerts[num4].position = tempVerts[num4].position * num;
UIVertex[] tempVerts2 = this.m_TempVerts;
int num5 = num3;
tempVerts2[num5].position.x = tempVerts2[num5].position.x + vector.x;
UIVertex[] tempVerts3 = this.m_TempVerts;
int num6 = num3;
tempVerts3[num6].position.y = tempVerts3[num6].position.y + vector.y;
if (num3 == 3)
{
toFill.AddUIVertexQuad(this.m_TempVerts);
}
}
}
else
{
for (int j = 0; j < num2; j++)
{
int num7 = j & 3;
this.m_TempVerts[num7] = verts[j];
UIVertex[] tempVerts4 = this.m_TempVerts;
int num8 = num7;
tempVerts4[num8].position = tempVerts4[num8].position * num;
if (num7 == 3)
{
toFill.AddUIVertexQuad(this.m_TempVerts);
}
}
}
this.m_DisableFontTextureRebuiltCallback = false;
}
}
// Token: 0x060004BE RID: 1214 RVA: 0x00019EF2 File Offset: 0x000182F2
public virtual void CalculateLayoutInputHorizontal()
{
}
// Token: 0x060004BF RID: 1215 RVA: 0x00019EF5 File Offset: 0x000182F5
public virtual void CalculateLayoutInputVertical()
{
}
// Token: 0x1700014D RID: 333
// (get) Token: 0x060004C0 RID: 1216 RVA: 0x00019EF8 File Offset: 0x000182F8
public virtual float minWidth
{
get
{
return 0f;
}
}
// Token: 0x1700014E RID: 334
// (get) Token: 0x060004C1 RID: 1217 RVA: 0x00019F14 File Offset: 0x00018314
public virtual float preferredWidth
{
get
{
TextGenerationSettings generationSettings = this.GetGenerationSettings(Vector2.zero);
return this.cachedTextGeneratorForLayout.GetPreferredWidth(this.m_Text, generationSettings) / this.pixelsPerUnit;
}
}
// Token: 0x1700014F RID: 335
// (get) Token: 0x060004C2 RID: 1218 RVA: 0x00019F50 File Offset: 0x00018350
public virtual float flexibleWidth
{
get
{
return -1f;
}
}
// Token: 0x17000150 RID: 336
// (get) Token: 0x060004C3 RID: 1219 RVA: 0x00019F6C File Offset: 0x0001836C
public virtual float minHeight
{
get
{
return 0f;
}
}
// Token: 0x17000151 RID: 337
// (get) Token: 0x060004C4 RID: 1220 RVA: 0x00019F88 File Offset: 0x00018388
public virtual float preferredHeight
{
get
{
TextGenerationSettings generationSettings = this.GetGenerationSettings(new Vector2(base.GetPixelAdjustedRect().size.x, 0f));
return this.cachedTextGeneratorForLayout.GetPreferredHeight(this.m_Text, generationSettings) / this.pixelsPerUnit;
}
}
// Token: 0x17000152 RID: 338
// (get) Token: 0x060004C5 RID: 1221 RVA: 0x00019FE0 File Offset: 0x000183E0
public virtual float flexibleHeight
{
get
{
return -1f;
}
}
// Token: 0x17000153 RID: 339
// (get) Token: 0x060004C6 RID: 1222 RVA: 0x00019FFC File Offset: 0x000183FC
public virtual int layoutPriority
{
get
{
return 0;
}
}
// Token: 0x04000242 RID: 578
[SerializeField]
private FontData m_FontData = FontData.defaultFontData;
// Token: 0x04000243 RID: 579
[TextArea(3, 10)]
[SerializeField]
protected string m_Text = string.Empty;
// Token: 0x04000244 RID: 580
private TextGenerator m_TextCache;
// Token: 0x04000245 RID: 581
private TextGenerator m_TextCacheForLayout;
// Token: 0x04000246 RID: 582
protected static Material s_DefaultText = null;
// Token: 0x04000247 RID: 583
[NonSerialized]
protected bool m_DisableFontTextureRebuiltCallback = false;
// Token: 0x04000248 RID: 584
private readonly UIVertex[] m_TempVerts = new UIVertex[4];
}
}