Files
Assembly-CSharp/Assembly-CSharp/SpriteCounter.cs
2026-06-12 12:58:31 +08:00

371 lines
9.8 KiB
C#

using System;
using System.Collections.Generic;
using System.Text;
using UnityEngine;
using UnityEngine.Sprites;
using UnityEngine.UI;
// Token: 0x02000189 RID: 393
public class SpriteCounter : MaskableGraphic
{
// Token: 0x17000159 RID: 345
// (get) Token: 0x06000DE6 RID: 3558 RVA: 0x00041A25 File Offset: 0x00040C25
public List<SpriteCounterData> FrameList
{
get
{
return this.frameList;
}
}
// Token: 0x1700015A RID: 346
// (get) Token: 0x06000DE7 RID: 3559 RVA: 0x00041A2D File Offset: 0x00040C2D
public List<SpriteCounterBetweenData> BetweenList
{
get
{
return this.betweenList;
}
}
// Token: 0x1700015B RID: 347
// (get) Token: 0x06000DE8 RID: 3560 RVA: 0x00041A38 File Offset: 0x00040C38
private RectTransform GetRectTransform
{
get
{
if (!(this.getRectTransform != null))
{
return this.getRectTransform = base.GetComponent<RectTransform>();
}
return this.getRectTransform;
}
}
// Token: 0x06000DE9 RID: 3561 RVA: 0x00041A69 File Offset: 0x00040C69
public void SetSpriteSheet(Sprite[] sprites)
{
this.spriteSheet = sprites;
this.SetAllDirty();
}
// Token: 0x06000DEA RID: 3562 RVA: 0x00041A78 File Offset: 0x00040C78
private void Update()
{
for (int i = 0; i < this.frameList.Count; i++)
{
if (this.frameList[i].IsAnimated)
{
float num = this.frameList[i].PosYCurve.Evaluate(this.Timer / 60f);
this.frameList[i].AnimationYPos = num * this._posYMagnification;
float num2 = this.frameList[i].ScaleCurve.Evaluate(this.Timer / 60f);
this.frameList[i].AnimationScale = num2 * this._scaleMagnification;
}
else
{
this.frameList[i].AnimationYPos = 0f;
this.frameList[i].AnimationScale = 0f;
}
}
}
// Token: 0x06000DEB RID: 3563 RVA: 0x00041B5C File Offset: 0x00040D5C
public void AddFormatFream()
{
if (this.spriteSheet == null || this.spriteSheet.Length == 0)
{
return;
}
Sprite sprite = this.spriteSheet[0];
Vector4 drawingDimensions = SpriteCounter.GetDrawingDimensions(sprite);
Vector4 outerUV = DataUtility.GetOuterUV(sprite);
SpriteCounterData spriteCounterData = new SpriteCounterData
{
Text = "0"
};
spriteCounterData.UiVertexs[0] = new CustomUIVertex
{
Position = new Vector3(drawingDimensions.x, drawingDimensions.y),
Color = this.color,
UV = new Vector2(outerUV.x, outerUV.y)
};
spriteCounterData.UiVertexs[1] = new CustomUIVertex
{
Position = new Vector3(drawingDimensions.x, drawingDimensions.w),
Color = this.color,
UV = new Vector2(outerUV.x, outerUV.w)
};
spriteCounterData.UiVertexs[2] = new CustomUIVertex
{
Position = new Vector3(drawingDimensions.z, drawingDimensions.w),
Color = this.color,
UV = new Vector2(outerUV.z, outerUV.w)
};
spriteCounterData.UiVertexs[3] = new CustomUIVertex
{
Position = new Vector3(drawingDimensions.z, drawingDimensions.y),
Color = this.color,
UV = new Vector2(outerUV.z, outerUV.y)
};
spriteCounterData.DefaultScale = sprite.rect.size;
spriteCounterData.Scale = 1f;
this.frameList.Add(spriteCounterData);
if (this.frameList.Count > 1)
{
this.betweenList.Add(new SpriteCounterBetweenData
{
Size = new Vector2(sprite.rect.size.x, 0f)
});
}
this.GetRectTransform.sizeDelta = new Vector2(this.frameList[0].DefaultScale.x * (float)this.frameList.Count, this.frameList[0].DefaultScale.y);
if (this.mainText.Length < this.frameList.Count)
{
this.mainText += "0";
}
this.SetAllDirty();
}
// Token: 0x06000DEC RID: 3564 RVA: 0x00041DC0 File Offset: 0x00040FC0
public void RemoveFormatFrame()
{
if (this.frameList.Count > 0)
{
this.GetRectTransform.sizeDelta = new Vector2(this.frameList[0].DefaultScale.x * (float)(this.frameList.Count - 1), this.frameList[0].DefaultScale.y);
this.frameList.RemoveAt(this.frameList.Count - 1);
if (this.betweenList.Count > 0)
{
this.betweenList.RemoveAt(this.betweenList.Count - 1);
}
if (this.mainText.Length > 0)
{
this.mainText = this.mainText.Remove(this.mainText.Length - 1);
}
if (this.formatText.Length > 0)
{
this.formatText = this.formatText.Remove(this.formatText.Length - 1);
}
this.SetAllDirty();
}
}
// Token: 0x06000DED RID: 3565 RVA: 0x00041EC8 File Offset: 0x000410C8
public override Material GetModifiedMaterial(Material baseMaterial)
{
for (int i = 0; i < this.frameList.Count; i++)
{
for (int j = 0; j < this.frameList[i].UiVertexs.Length; j++)
{
this.frameList[i].UiVertexs[j].Color = this.color;
}
}
return base.GetModifiedMaterial(baseMaterial);
}
// Token: 0x06000DEE RID: 3566 RVA: 0x00041F34 File Offset: 0x00041134
public void ChangeText(string text, string format)
{
this.sb.Length = 0;
int num = 0;
foreach (char c in format)
{
if (c != '#')
{
switch (c)
{
}
this.sb.Append(text[num]);
}
else if (text[num] == '0')
{
this.sb.Append(" ");
}
else
{
this.sb.Append(text[num]);
}
num++;
}
this.ChangeText(this.sb.ToString());
}
// Token: 0x06000DEF RID: 3567 RVA: 0x00041FEC File Offset: 0x000411EC
public void ChangeText(string text)
{
int num = 0;
foreach (char c in text)
{
int num2 = (int)char.GetNumericValue(c);
bool flag = false;
if (num2 < 0)
{
if (c != ' ')
{
if (c != '%')
{
switch (c)
{
case '+':
num2 = 10;
break;
case ',':
num2 = 12;
break;
case '-':
num2 = 11;
break;
case '.':
num2 = 13;
break;
default:
return;
}
}
else
{
num2 = 14;
}
}
else
{
num2 = 0;
flag = true;
}
}
if (this.spriteSheet.Length <= num2)
{
return;
}
Sprite sprite = this.spriteSheet[num2];
Vector4 drawingDimensions = SpriteCounter.GetDrawingDimensions(sprite);
Vector4 vector = DataUtility.GetOuterUV(sprite);
if (num >= this.frameList.Count)
{
break;
}
this.frameList[num].UiVertexs[0].Position = new Vector3(drawingDimensions.x, drawingDimensions.y);
this.frameList[num].UiVertexs[1].Position = new Vector3(drawingDimensions.x, drawingDimensions.w);
this.frameList[num].UiVertexs[2].Position = new Vector3(drawingDimensions.z, drawingDimensions.w);
this.frameList[num].UiVertexs[3].Position = new Vector3(drawingDimensions.z, drawingDimensions.y);
if (flag)
{
vector = Vector4.zero;
}
this.frameList[num].UiVertexs[0].UV = new Vector2(vector.x, vector.y);
this.frameList[num].UiVertexs[1].UV = new Vector2(vector.x, vector.w);
this.frameList[num].UiVertexs[2].UV = new Vector2(vector.z, vector.w);
this.frameList[num].UiVertexs[3].UV = new Vector2(vector.z, vector.y);
this.frameList[num].Text = c.ToString();
num++;
}
this.SetAllDirty();
this.mainText = text;
}
// Token: 0x06000DF0 RID: 3568 RVA: 0x00042240 File Offset: 0x00041440
private static Vector4 GetDrawingDimensions(Sprite sprite)
{
return new Vector4(-(sprite.rect.width / 2f), -(sprite.rect.height / 2f), sprite.rect.width / 2f, sprite.rect.height / 2f);
}
// Token: 0x06000DF1 RID: 3569 RVA: 0x000422A4 File Offset: 0x000414A4
protected override void OnPopulateMesh(VertexHelper vh)
{
vh.Clear();
if (this.spriteSheet == null || this.spriteSheet.Length < 1)
{
return;
}
for (int i = 0; i < this.frameList.Count; i++)
{
Vector2 zero = Vector2.zero;
if (this.frameList.Count > 1)
{
zero.y = 0f;
zero.x = -(this.frameList[i].DefaultScale.x * (float)this.frameList.Count / 2f) + this.frameList[i].DefaultScale.x * (float)i + this.frameList[i].DefaultScale.x / 2f;
}
for (int j = 0; j < 4; j++)
{
this.tempArray[j] = this.frameList[i].UiVertexs[j].Get();
UIVertex[] array = this.tempArray;
int num = j;
array[num].position = array[num].position * (this.frameList[i].Scale + this.frameList[i].AnimationScale);
UIVertex[] array2 = this.tempArray;
int num2 = j;
array2[num2].position.x = array2[num2].position.x + (zero.x + this.frameList[i].RelativePosition.x);
UIVertex[] array3 = this.tempArray;
int num3 = j;
array3[num3].position.y = array3[num3].position.y + (zero.y + this.frameList[i].RelativePosition.y + this.frameList[i].AnimationYPos);
}
vh.AddUIVertexQuad(this.tempArray);
}
}
// Token: 0x06000DF2 RID: 3570 RVA: 0x00042478 File Offset: 0x00041678
public void SetColor(Color setColor)
{
this.color = setColor;
for (int i = 0; i < this.frameList.Count; i++)
{
for (int j = 0; j < this.frameList[i].UiVertexs.Length; j++)
{
this.frameList[i].UiVertexs[j].Color = this.color;
}
}
this.SetAllDirty();
}
// Token: 0x1700015C RID: 348
// (get) Token: 0x06000DF3 RID: 3571 RVA: 0x000424E9 File Offset: 0x000416E9
public override Texture mainTexture
{
get
{
if (this.spriteSheet != null && this.spriteSheet.Length != 0 && this.spriteSheet[0] != null)
{
return this.spriteSheet[0].texture;
}
return base.mainTexture;
}
}
// Token: 0x04000AA3 RID: 2723
private readonly StringBuilder sb = new StringBuilder();
// Token: 0x04000AA4 RID: 2724
private readonly UIVertex[] tempArray = new UIVertex[4];
// Token: 0x04000AA5 RID: 2725
[SerializeField]
private Sprite[] spriteSheet;
// Token: 0x04000AA6 RID: 2726
[SerializeField]
private string mainText;
// Token: 0x04000AA7 RID: 2727
[SerializeField]
private string formatText;
// Token: 0x04000AA8 RID: 2728
[SerializeField]
private List<SpriteCounterData> frameList = new List<SpriteCounterData>();
// Token: 0x04000AA9 RID: 2729
[SerializeField]
private List<SpriteCounterBetweenData> betweenList = new List<SpriteCounterBetweenData>();
// Token: 0x04000AAA RID: 2730
[SerializeField]
private float _posYMagnification = 10f;
// Token: 0x04000AAB RID: 2731
[SerializeField]
private float _scaleMagnification = 1f;
// Token: 0x04000AAC RID: 2732
private RectTransform getRectTransform;
// Token: 0x04000AAD RID: 2733
public float Timer;
}