Add decompiled sources

This commit is contained in:
Lncvrt committed 2025-08-04 00:16:57 -07:00
commit ead5df3cd0
14016 files changed
+1030428

No files matched your search

@@ -0,0 +1,92 @@
using System.Collections;
using UnityEngine;
namespace TMPro.Examples
{
public class Benchmark01 : MonoBehaviour
{
public int BenchmarkType;
public TMP_FontAsset TMProFont;
public Font TextMeshFont;
private TextMeshPro m_textMeshPro;
private TextContainer m_textContainer;
private TextMesh m_textMesh;
private const string label01 = "The <#0050FF>count is: </color>{0}";
private const string label02 = "The <color=#0050FF>count is: </color>";
private Material m_material01;
private Material m_material02;
private IEnumerator Start()
{
if (BenchmarkType == 0)
{
m_textMeshPro = base.gameObject.AddComponent<TextMeshPro>();
m_textMeshPro.autoSizeTextContainer = true;
if (TMProFont != null)
{
m_textMeshPro.font = TMProFont;
}
m_textMeshPro.fontSize = 48f;
m_textMeshPro.alignment = TextAlignmentOptions.Center;
m_textMeshPro.extraPadding = true;
m_textMeshPro.enableWordWrapping = false;
m_material01 = m_textMeshPro.font.material;
m_material02 = Resources.Load<Material>("Fonts & Materials/LiberationSans SDF - Drop Shadow");
}
else if (BenchmarkType == 1)
{
m_textMesh = base.gameObject.AddComponent<TextMesh>();
if (TextMeshFont != null)
{
m_textMesh.font = TextMeshFont;
m_textMesh.GetComponent<Renderer>().sharedMaterial = m_textMesh.font.material;
}
else
{
m_textMesh.font = Resources.Load("Fonts/ARIAL", typeof(Font)) as Font;
m_textMesh.GetComponent<Renderer>().sharedMaterial = m_textMesh.font.material;
}
m_textMesh.fontSize = 48;
m_textMesh.anchor = TextAnchor.MiddleCenter;
}
for (int i = 0; i <= 1000000; i++)
{
if (BenchmarkType == 0)
{
m_textMeshPro.SetText("The <#0050FF>count is: </color>{0}", i % 1000);
if (i % 1000 == 999)
{
TextMeshPro textMeshPro = m_textMeshPro;
Material fontSharedMaterial;
if (!(m_textMeshPro.fontSharedMaterial == m_material01))
{
Material material = (m_textMeshPro.fontSharedMaterial = m_material01);
fontSharedMaterial = material;
}
else
{
Material material = (m_textMeshPro.fontSharedMaterial = m_material02);
fontSharedMaterial = material;
}
textMeshPro.fontSharedMaterial = fontSharedMaterial;
}
}
else if (BenchmarkType == 1)
{
m_textMesh.text = "The <color=#0050FF>count is: </color>" + i % 1000;
}
yield return null;
}
yield return null;
}
}
}
@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 2dce2f3a66b559d26c4169ce420c9935
timeCreated: 1754265943
licenseType: Free
MonoImporter:
serializedVersion: 2
externalObjects: {}
defaultReferences: []
executionOrder: 0
icon: {fileID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,85 @@
using System.Collections;
using UnityEngine;
using UnityEngine.UI;
namespace TMPro.Examples
{
public class Benchmark01_UGUI : MonoBehaviour
{
public int BenchmarkType;
public Canvas canvas;
public TMP_FontAsset TMProFont;
public Font TextMeshFont;
private TextMeshProUGUI m_textMeshPro;
private Text m_textMesh;
private const string label01 = "The <#0050FF>count is: </color>";
private const string label02 = "The <color=#0050FF>count is: </color>";
private Material m_material01;
private Material m_material02;
private IEnumerator Start()
{
if (BenchmarkType == 0)
{
m_textMeshPro = base.gameObject.AddComponent<TextMeshProUGUI>();
if (TMProFont != null)
{
m_textMeshPro.font = TMProFont;
}
m_textMeshPro.fontSize = 48f;
m_textMeshPro.alignment = TextAlignmentOptions.Center;
m_textMeshPro.extraPadding = true;
m_material01 = m_textMeshPro.font.material;
m_material02 = Resources.Load<Material>("Fonts & Materials/LiberationSans SDF - BEVEL");
}
else if (BenchmarkType == 1)
{
m_textMesh = base.gameObject.AddComponent<Text>();
if (TextMeshFont != null)
{
m_textMesh.font = TextMeshFont;
}
m_textMesh.fontSize = 48;
m_textMesh.alignment = TextAnchor.MiddleCenter;
}
for (int i = 0; i <= 1000000; i++)
{
if (BenchmarkType == 0)
{
m_textMeshPro.text = "The <#0050FF>count is: </color>" + i % 1000;
if (i % 1000 == 999)
{
TextMeshProUGUI textMeshPro = m_textMeshPro;
Material fontSharedMaterial;
if (!(m_textMeshPro.fontSharedMaterial == m_material01))
{
Material material = (m_textMeshPro.fontSharedMaterial = m_material01);
fontSharedMaterial = material;
}
else
{
Material material = (m_textMeshPro.fontSharedMaterial = m_material02);
fontSharedMaterial = material;
}
textMeshPro.fontSharedMaterial = fontSharedMaterial;
}
}
else if (BenchmarkType == 1)
{
m_textMesh.text = "The <color=#0050FF>count is: </color>" + i % 1000;
}
yield return null;
}
yield return null;
}
}
}
@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: d3e6497e5acfd415838b7f55dfda96f0
timeCreated: 1754265943
licenseType: Free
MonoImporter:
serializedVersion: 2
externalObjects: {}
defaultReferences: []
executionOrder: 0
icon: {fileID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,68 @@
using UnityEngine;
namespace TMPro.Examples
{
public class Benchmark02 : MonoBehaviour
{
public int SpawnType;
public int NumberOfNPC = 12;
public bool IsTextObjectScaleStatic;
private TextMeshProFloatingText floatingText_Script;
private void Start()
{
for (int i = 0; i < NumberOfNPC; i++)
{
if (SpawnType == 0)
{
GameObject gameObject = new GameObject();
gameObject.transform.position = new Vector3(Random.Range(-95f, 95f), 0.25f, Random.Range(-95f, 95f));
TextMeshPro textMeshPro = gameObject.AddComponent<TextMeshPro>();
textMeshPro.autoSizeTextContainer = true;
textMeshPro.rectTransform.pivot = new Vector2(0.5f, 0f);
textMeshPro.alignment = TextAlignmentOptions.Bottom;
textMeshPro.fontSize = 96f;
textMeshPro.enableKerning = false;
textMeshPro.color = new Color32(byte.MaxValue, byte.MaxValue, 0, byte.MaxValue);
textMeshPro.text = "!";
textMeshPro.isTextObjectScaleStatic = IsTextObjectScaleStatic;
floatingText_Script = gameObject.AddComponent<TextMeshProFloatingText>();
floatingText_Script.SpawnType = 0;
floatingText_Script.IsTextObjectScaleStatic = IsTextObjectScaleStatic;
}
else if (SpawnType == 1)
{
GameObject gameObject2 = new GameObject();
gameObject2.transform.position = new Vector3(Random.Range(-95f, 95f), 0.25f, Random.Range(-95f, 95f));
TextMesh textMesh = gameObject2.AddComponent<TextMesh>();
textMesh.font = Resources.Load<Font>("Fonts/ARIAL");
textMesh.GetComponent<Renderer>().sharedMaterial = textMesh.font.material;
textMesh.anchor = TextAnchor.LowerCenter;
textMesh.fontSize = 96;
textMesh.color = new Color32(byte.MaxValue, byte.MaxValue, 0, byte.MaxValue);
textMesh.text = "!";
floatingText_Script = gameObject2.AddComponent<TextMeshProFloatingText>();
floatingText_Script.SpawnType = 1;
}
else if (SpawnType == 2)
{
GameObject gameObject3 = new GameObject();
gameObject3.AddComponent<Canvas>().worldCamera = Camera.main;
gameObject3.transform.localScale = new Vector3(0.1f, 0.1f, 0.1f);
gameObject3.transform.position = new Vector3(Random.Range(-95f, 95f), 5f, Random.Range(-95f, 95f));
TextMeshProUGUI textMeshProUGUI = new GameObject().AddComponent<TextMeshProUGUI>();
textMeshProUGUI.rectTransform.SetParent(gameObject3.transform, worldPositionStays: false);
textMeshProUGUI.color = new Color32(byte.MaxValue, byte.MaxValue, 0, byte.MaxValue);
textMeshProUGUI.alignment = TextAlignmentOptions.Bottom;
textMeshProUGUI.fontSize = 96f;
textMeshProUGUI.text = "!";
floatingText_Script = gameObject3.AddComponent<TextMeshProFloatingText>();
floatingText_Script.SpawnType = 0;
}
}
}
}
}
@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: ff0fb97368bda127693108d5e4753dc4
timeCreated: 1754265943
licenseType: Free
MonoImporter:
serializedVersion: 2
externalObjects: {}
defaultReferences: []
executionOrder: 0
icon: {fileID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,87 @@
using UnityEngine;
using UnityEngine.TextCore.LowLevel;
namespace TMPro.Examples
{
public class Benchmark03 : MonoBehaviour
{
public enum BenchmarkType
{
TMP_SDF_MOBILE = 0,
TMP_SDF__MOBILE_SSD = 1,
TMP_SDF = 2,
TMP_BITMAP_MOBILE = 3,
TEXTMESH_BITMAP = 4
}
public int NumberOfSamples = 100;
public BenchmarkType Benchmark;
public Font SourceFont;
private void Awake()
{
}
private void Start()
{
TMP_FontAsset tMP_FontAsset = null;
switch (Benchmark)
{
case BenchmarkType.TMP_SDF_MOBILE:
tMP_FontAsset = TMP_FontAsset.CreateFontAsset(SourceFont, 90, 9, GlyphRenderMode.SDFAA, 256, 256);
break;
case BenchmarkType.TMP_SDF__MOBILE_SSD:
tMP_FontAsset = TMP_FontAsset.CreateFontAsset(SourceFont, 90, 9, GlyphRenderMode.SDFAA, 256, 256);
tMP_FontAsset.material.shader = Shader.Find("TextMeshPro/Mobile/Distance Field SSD");
break;
case BenchmarkType.TMP_SDF:
tMP_FontAsset = TMP_FontAsset.CreateFontAsset(SourceFont, 90, 9, GlyphRenderMode.SDFAA, 256, 256);
tMP_FontAsset.material.shader = Shader.Find("TextMeshPro/Distance Field");
break;
case BenchmarkType.TMP_BITMAP_MOBILE:
tMP_FontAsset = TMP_FontAsset.CreateFontAsset(SourceFont, 90, 9, GlyphRenderMode.SMOOTH, 256, 256);
break;
}
for (int i = 0; i < NumberOfSamples; i++)
{
switch (Benchmark)
{
case BenchmarkType.TMP_SDF_MOBILE:
case BenchmarkType.TMP_SDF__MOBILE_SSD:
case BenchmarkType.TMP_SDF:
case BenchmarkType.TMP_BITMAP_MOBILE:
{
GameObject obj2 = new GameObject();
obj2.transform.position = new Vector3(0f, 1.2f, 0f);
TextMeshPro textMeshPro = obj2.AddComponent<TextMeshPro>();
textMeshPro.font = tMP_FontAsset;
textMeshPro.fontSize = 128f;
textMeshPro.text = "@";
textMeshPro.alignment = TextAlignmentOptions.Center;
textMeshPro.color = new Color32(byte.MaxValue, byte.MaxValue, 0, byte.MaxValue);
if (Benchmark == BenchmarkType.TMP_BITMAP_MOBILE)
{
textMeshPro.fontSize = 132f;
}
break;
}
case BenchmarkType.TEXTMESH_BITMAP:
{
GameObject obj = new GameObject();
obj.transform.position = new Vector3(0f, 1.2f, 0f);
TextMesh textMesh = obj.AddComponent<TextMesh>();
textMesh.GetComponent<Renderer>().sharedMaterial = SourceFont.material;
textMesh.font = SourceFont;
textMesh.anchor = TextAnchor.MiddleCenter;
textMesh.fontSize = 130;
textMesh.color = new Color32(byte.MaxValue, byte.MaxValue, 0, byte.MaxValue);
textMesh.text = "@";
break;
}
}
}
}
}
}
@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 25b8c11b3f2b345300d242fc9b0545f1
timeCreated: 1754265943
licenseType: Free
MonoImporter:
serializedVersion: 2
externalObjects: {}
defaultReferences: []
executionOrder: 0
icon: {fileID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,47 @@
using UnityEngine;
namespace TMPro.Examples
{
public class Benchmark04 : MonoBehaviour
{
public int SpawnType;
public int MinPointSize = 12;
public int MaxPointSize = 64;
public int Steps = 4;
private Transform m_Transform;
private void Start()
{
m_Transform = base.transform;
float num = 0f;
float num2 = (Camera.main.orthographicSize = Screen.height / 2);
float num4 = num2;
float num5 = (float)Screen.width / (float)Screen.height;
for (int i = MinPointSize; i <= MaxPointSize; i += Steps)
{
if (SpawnType == 0)
{
GameObject gameObject = new GameObject("Text - " + i + " Pts");
if (num > num4 * 2f)
{
break;
}
gameObject.transform.position = m_Transform.position + new Vector3(num5 * (0f - num4) * 0.975f, num4 * 0.975f - num, 0f);
TextMeshPro textMeshPro = gameObject.AddComponent<TextMeshPro>();
textMeshPro.rectTransform.pivot = new Vector2(0f, 0.5f);
textMeshPro.enableWordWrapping = false;
textMeshPro.extraPadding = true;
textMeshPro.isOrthographic = true;
textMeshPro.fontSize = i;
textMeshPro.text = i + " pts - Lorem ipsum dolor sit...";
textMeshPro.color = new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue);
num += (float)i;
}
}
}
}
}
@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 6d7b6d2813f1e8bd2fab94941f6982c1
timeCreated: 1754265943
licenseType: Free
MonoImporter:
serializedVersion: 2
externalObjects: {}
defaultReferences: []
executionOrder: 0
icon: {fileID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,246 @@
using UnityEngine;
namespace TMPro.Examples
{
public class CameraController : MonoBehaviour
{
public enum CameraModes
{
Follow = 0,
Isometric = 1,
Free = 2
}
private Transform cameraTransform;
private Transform dummyTarget;
public Transform CameraTarget;
public float FollowDistance = 30f;
public float MaxFollowDistance = 100f;
public float MinFollowDistance = 2f;
public float ElevationAngle = 30f;
public float MaxElevationAngle = 85f;
public float MinElevationAngle;
public float OrbitalAngle;
public CameraModes CameraMode;
public bool MovementSmoothing = true;
public bool RotationSmoothing;
private bool previousSmoothing;
public float MovementSmoothingValue = 25f;
public float RotationSmoothingValue = 5f;
public float MoveSensitivity = 2f;
private Vector3 currentVelocity = Vector3.zero;
private Vector3 desiredPosition;
private float mouseX;
private float mouseY;
private Vector3 moveVector;
private float mouseWheel;
private const string event_SmoothingValue = "Slider - Smoothing Value";
private const string event_FollowDistance = "Slider - Camera Zoom";
private void Awake()
{
if (QualitySettings.vSyncCount > 0)
{
Application.targetFrameRate = 60;
}
else
{
Application.targetFrameRate = -1;
}
if (Application.platform == RuntimePlatform.IPhonePlayer || Application.platform == RuntimePlatform.Android)
{
Input.simulateMouseWithTouches = false;
}
cameraTransform = base.transform;
previousSmoothing = MovementSmoothing;
}
private void Start()
{
if (CameraTarget == null)
{
dummyTarget = new GameObject("Camera Target").transform;
CameraTarget = dummyTarget;
}
}
private void LateUpdate()
{
GetPlayerInput();
if (CameraTarget != null)
{
if (CameraMode == CameraModes.Isometric)
{
desiredPosition = CameraTarget.position + Quaternion.Euler(ElevationAngle, OrbitalAngle, 0f) * new Vector3(0f, 0f, 0f - FollowDistance);
}
else if (CameraMode == CameraModes.Follow)
{
desiredPosition = CameraTarget.position + CameraTarget.TransformDirection(Quaternion.Euler(ElevationAngle, OrbitalAngle, 0f) * new Vector3(0f, 0f, 0f - FollowDistance));
}
if (MovementSmoothing)
{
cameraTransform.position = Vector3.SmoothDamp(cameraTransform.position, desiredPosition, ref currentVelocity, MovementSmoothingValue * Time.fixedDeltaTime);
}
else
{
cameraTransform.position = desiredPosition;
}
if (RotationSmoothing)
{
cameraTransform.rotation = Quaternion.Lerp(cameraTransform.rotation, Quaternion.LookRotation(CameraTarget.position - cameraTransform.position), RotationSmoothingValue * Time.deltaTime);
}
else
{
cameraTransform.LookAt(CameraTarget);
}
}
}
private void GetPlayerInput()
{
moveVector = Vector3.zero;
mouseWheel = Input.GetAxis("Mouse ScrollWheel");
float num = Input.touchCount;
if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift) || num > 0f)
{
mouseWheel *= 10f;
if (Input.GetKeyDown(KeyCode.I))
{
CameraMode = CameraModes.Isometric;
}
if (Input.GetKeyDown(KeyCode.F))
{
CameraMode = CameraModes.Follow;
}
if (Input.GetKeyDown(KeyCode.S))
{
MovementSmoothing = !MovementSmoothing;
}
if (Input.GetMouseButton(1))
{
mouseY = Input.GetAxis("Mouse Y");
mouseX = Input.GetAxis("Mouse X");
if (mouseY > 0.01f || mouseY < -0.01f)
{
ElevationAngle -= mouseY * MoveSensitivity;
ElevationAngle = Mathf.Clamp(ElevationAngle, MinElevationAngle, MaxElevationAngle);
}
if (mouseX > 0.01f || mouseX < -0.01f)
{
OrbitalAngle += mouseX * MoveSensitivity;
if (OrbitalAngle > 360f)
{
OrbitalAngle -= 360f;
}
if (OrbitalAngle < 0f)
{
OrbitalAngle += 360f;
}
}
}
if (num == 1f && Input.GetTouch(0).phase == TouchPhase.Moved)
{
Vector2 deltaPosition = Input.GetTouch(0).deltaPosition;
if (deltaPosition.y > 0.01f || deltaPosition.y < -0.01f)
{
ElevationAngle -= deltaPosition.y * 0.1f;
ElevationAngle = Mathf.Clamp(ElevationAngle, MinElevationAngle, MaxElevationAngle);
}
if (deltaPosition.x > 0.01f || deltaPosition.x < -0.01f)
{
OrbitalAngle += deltaPosition.x * 0.1f;
if (OrbitalAngle > 360f)
{
OrbitalAngle -= 360f;
}
if (OrbitalAngle < 0f)
{
OrbitalAngle += 360f;
}
}
}
if (Input.GetMouseButton(0) && Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out var hitInfo, 300f, 23552))
{
if (hitInfo.transform == CameraTarget)
{
OrbitalAngle = 0f;
}
else
{
CameraTarget = hitInfo.transform;
OrbitalAngle = 0f;
MovementSmoothing = previousSmoothing;
}
}
if (Input.GetMouseButton(2))
{
if (dummyTarget == null)
{
dummyTarget = new GameObject("Camera Target").transform;
dummyTarget.position = CameraTarget.position;
dummyTarget.rotation = CameraTarget.rotation;
CameraTarget = dummyTarget;
previousSmoothing = MovementSmoothing;
MovementSmoothing = false;
}
else if (dummyTarget != CameraTarget)
{
dummyTarget.position = CameraTarget.position;
dummyTarget.rotation = CameraTarget.rotation;
CameraTarget = dummyTarget;
previousSmoothing = MovementSmoothing;
MovementSmoothing = false;
}
mouseY = Input.GetAxis("Mouse Y");
mouseX = Input.GetAxis("Mouse X");
moveVector = cameraTransform.TransformDirection(mouseX, mouseY, 0f);
dummyTarget.Translate(-moveVector, Space.World);
}
}
if (num == 2f)
{
Touch touch = Input.GetTouch(0);
Touch touch2 = Input.GetTouch(1);
Vector2 vector = touch.position - touch.deltaPosition;
Vector2 vector2 = touch2.position - touch2.deltaPosition;
float magnitude = (vector - vector2).magnitude;
float magnitude2 = (touch.position - touch2.position).magnitude;
float num2 = magnitude - magnitude2;
if (num2 > 0.01f || num2 < -0.01f)
{
FollowDistance += num2 * 0.25f;
FollowDistance = Mathf.Clamp(FollowDistance, MinFollowDistance, MaxFollowDistance);
}
}
if (mouseWheel < -0.01f || mouseWheel > 0.01f)
{
FollowDistance -= mouseWheel * 5f;
FollowDistance = Mathf.Clamp(FollowDistance, MinFollowDistance, MaxFollowDistance);
}
}
}
}
@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: bbe7700f9732df029498b31ad05eb0f1
timeCreated: 1754265943
licenseType: Free
MonoImporter:
serializedVersion: 2
externalObjects: {}
defaultReferences: []
executionOrder: 0
icon: {fileID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,65 @@
using UnityEngine;
namespace TMPro.Examples
{
public class ObjectSpin : MonoBehaviour
{
public enum MotionType
{
Rotation = 0,
BackAndForth = 1,
Translation = 2
}
public float SpinSpeed = 5f;
public int RotationRange = 15;
private Transform m_transform;
private float m_time;
private Vector3 m_prevPOS;
private Vector3 m_initial_Rotation;
private Vector3 m_initial_Position;
private Color32 m_lightColor;
private int frames;
public MotionType Motion;
private void Awake()
{
m_transform = base.transform;
m_initial_Rotation = m_transform.rotation.eulerAngles;
m_initial_Position = m_transform.position;
Light component = GetComponent<Light>();
m_lightColor = ((component != null) ? component.color : Color.black);
}
private void Update()
{
if (Motion == MotionType.Rotation)
{
m_transform.Rotate(0f, SpinSpeed * Time.deltaTime, 0f);
return;
}
if (Motion == MotionType.BackAndForth)
{
m_time += SpinSpeed * Time.deltaTime;
m_transform.rotation = Quaternion.Euler(m_initial_Rotation.x, Mathf.Sin(m_time) * (float)RotationRange + m_initial_Rotation.y, m_initial_Rotation.z);
return;
}
m_time += SpinSpeed * Time.deltaTime;
float x = 15f * Mathf.Cos(m_time * 0.95f);
float z = 10f;
float y = 0f;
m_transform.position = m_initial_Position + new Vector3(x, y, z);
m_prevPOS = m_transform.position;
frames++;
}
}
}
@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: d61f3dbe903e9fadcfb368280226c814
timeCreated: 1754265943
licenseType: Free
MonoImporter:
serializedVersion: 2
externalObjects: {}
defaultReferences: []
executionOrder: 0
icon: {fileID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,39 @@
using System.Collections;
using UnityEngine;
namespace TMPro.Examples
{
public class ShaderPropAnimator : MonoBehaviour
{
private Renderer m_Renderer;
private Material m_Material;
public AnimationCurve GlowCurve;
public float m_frame;
private void Awake()
{
m_Renderer = GetComponent<Renderer>();
m_Material = m_Renderer.material;
}
private void Start()
{
StartCoroutine(AnimateProperties());
}
private IEnumerator AnimateProperties()
{
m_frame = Random.Range(0f, 1f);
while (true)
{
float value = GlowCurve.Evaluate(m_frame);
m_Material.SetFloat(ShaderUtilities.ID_GlowPower, value);
m_frame += Time.deltaTime * Random.Range(0.2f, 0.3f);
yield return new WaitForEndOfFrame();
}
}
}
}
@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 0b7b7b79e67a79cfd7d8014563f62eee
timeCreated: 1754265943
licenseType: Free
MonoImporter:
serializedVersion: 2
externalObjects: {}
defaultReferences: []
executionOrder: 0
icon: {fileID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,28 @@
using UnityEngine;
namespace TMPro.Examples
{
public class SimpleScript : MonoBehaviour
{
private TextMeshPro m_textMeshPro;
private const string label = "The <#0050FF>count is: </color>{0:2}";
private float m_frame;
private void Start()
{
m_textMeshPro = base.gameObject.AddComponent<TextMeshPro>();
m_textMeshPro.autoSizeTextContainer = true;
m_textMeshPro.fontSize = 48f;
m_textMeshPro.alignment = TextAlignmentOptions.Center;
m_textMeshPro.enableWordWrapping = false;
}
private void Update()
{
m_textMeshPro.SetText("The <#0050FF>count is: </color>{0:2}", m_frame % 1000f);
m_frame += 1f * Time.deltaTime;
}
}
}
@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: fb7abe824271dea330088875fb7e3850
timeCreated: 1754265943
licenseType: Free
MonoImporter:
serializedVersion: 2
externalObjects: {}
defaultReferences: []
executionOrder: 0
icon: {fileID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,105 @@
using System.Collections;
using UnityEngine;
namespace TMPro.Examples
{
public class SkewTextExample : MonoBehaviour
{
private TMP_Text m_TextComponent;
public AnimationCurve VertexCurve = new AnimationCurve(new Keyframe(0f, 0f), new Keyframe(0.25f, 2f), new Keyframe(0.5f, 0f), new Keyframe(0.75f, 2f), new Keyframe(1f, 0f));
public float CurveScale = 1f;
public float ShearAmount = 1f;
private void Awake()
{
m_TextComponent = base.gameObject.GetComponent<TMP_Text>();
}
private void Start()
{
StartCoroutine(WarpText());
}
private AnimationCurve CopyAnimationCurve(AnimationCurve curve)
{
return new AnimationCurve
{
keys = curve.keys
};
}
private IEnumerator WarpText()
{
VertexCurve.preWrapMode = WrapMode.Once;
VertexCurve.postWrapMode = WrapMode.Once;
m_TextComponent.havePropertiesChanged = true;
CurveScale *= 10f;
float old_CurveScale = CurveScale;
float old_ShearValue = ShearAmount;
AnimationCurve old_curve = CopyAnimationCurve(VertexCurve);
while (true)
{
if (!m_TextComponent.havePropertiesChanged && old_CurveScale == CurveScale && old_curve.keys[1].value == VertexCurve.keys[1].value && old_ShearValue == ShearAmount)
{
yield return null;
continue;
}
old_CurveScale = CurveScale;
old_curve = CopyAnimationCurve(VertexCurve);
old_ShearValue = ShearAmount;
m_TextComponent.ForceMeshUpdate();
TMP_TextInfo textInfo = m_TextComponent.textInfo;
int characterCount = textInfo.characterCount;
if (characterCount == 0)
{
continue;
}
float x = m_TextComponent.bounds.min.x;
float x2 = m_TextComponent.bounds.max.x;
for (int i = 0; i < characterCount; i++)
{
if (textInfo.characterInfo[i].isVisible)
{
int vertexIndex = textInfo.characterInfo[i].vertexIndex;
int materialReferenceIndex = textInfo.characterInfo[i].materialReferenceIndex;
Vector3[] vertices = textInfo.meshInfo[materialReferenceIndex].vertices;
Vector3 vector = new Vector2((vertices[vertexIndex].x + vertices[vertexIndex + 2].x) / 2f, textInfo.characterInfo[i].baseLine);
vertices[vertexIndex] += -vector;
vertices[vertexIndex + 1] += -vector;
vertices[vertexIndex + 2] += -vector;
vertices[vertexIndex + 3] += -vector;
float num = ShearAmount * 0.01f;
Vector3 vector2 = new Vector3(num * (textInfo.characterInfo[i].topRight.y - textInfo.characterInfo[i].baseLine), 0f, 0f);
Vector3 vector3 = new Vector3(num * (textInfo.characterInfo[i].baseLine - textInfo.characterInfo[i].bottomRight.y), 0f, 0f);
vertices[vertexIndex] += -vector3;
vertices[vertexIndex + 1] += vector2;
vertices[vertexIndex + 2] += vector2;
vertices[vertexIndex + 3] += -vector3;
float num2 = (vector.x - x) / (x2 - x);
float num3 = num2 + 0.0001f;
float y = VertexCurve.Evaluate(num2) * CurveScale;
float y2 = VertexCurve.Evaluate(num3) * CurveScale;
Vector3 lhs = new Vector3(1f, 0f, 0f);
Vector3 rhs = new Vector3(num3 * (x2 - x) + x, y2) - new Vector3(vector.x, y);
float num4 = Mathf.Acos(Vector3.Dot(lhs, rhs.normalized)) * 57.29578f;
float z = ((Vector3.Cross(lhs, rhs).z > 0f) ? num4 : (360f - num4));
Matrix4x4 matrix4x = Matrix4x4.TRS(new Vector3(0f, y, 0f), Quaternion.Euler(0f, 0f, z), Vector3.one);
vertices[vertexIndex] = matrix4x.MultiplyPoint3x4(vertices[vertexIndex]);
vertices[vertexIndex + 1] = matrix4x.MultiplyPoint3x4(vertices[vertexIndex + 1]);
vertices[vertexIndex + 2] = matrix4x.MultiplyPoint3x4(vertices[vertexIndex + 2]);
vertices[vertexIndex + 3] = matrix4x.MultiplyPoint3x4(vertices[vertexIndex + 3]);
vertices[vertexIndex] += vector;
vertices[vertexIndex + 1] += vector;
vertices[vertexIndex + 2] += vector;
vertices[vertexIndex + 3] += vector;
}
}
m_TextComponent.UpdateVertexData();
yield return null;
}
}
}
}
@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 7cc2fd07ebef5ee2dc3238fe38524d59
timeCreated: 1754265943
licenseType: Free
MonoImporter:
serializedVersion: 2
externalObjects: {}
defaultReferences: []
executionOrder: 0
icon: {fileID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,50 @@
using UnityEngine;
namespace TMPro.Examples
{
public class TMP_ExampleScript_01 : MonoBehaviour
{
public enum objectType
{
TextMeshPro = 0,
TextMeshProUGUI = 1
}
public objectType ObjectType;
public bool isStatic;
private TMP_Text m_text;
private const string k_label = "The count is <#0080ff>{0}</color>";
private int count;
private void Awake()
{
if (ObjectType == objectType.TextMeshPro)
{
m_text = GetComponent<TextMeshPro>() ?? base.gameObject.AddComponent<TextMeshPro>();
}
else
{
m_text = GetComponent<TextMeshProUGUI>() ?? base.gameObject.AddComponent<TextMeshProUGUI>();
}
m_text.font = Resources.Load<TMP_FontAsset>("Fonts & Materials/Anton SDF");
m_text.fontSharedMaterial = Resources.Load<Material>("Fonts & Materials/Anton SDF - Drop Shadow");
m_text.fontSize = 120f;
m_text.text = "A <#0080ff>simple</color> line of text.";
Vector2 preferredValues = m_text.GetPreferredValues(float.PositiveInfinity, float.PositiveInfinity);
m_text.rectTransform.sizeDelta = new Vector2(preferredValues.x, preferredValues.y);
}
private void Update()
{
if (!isStatic)
{
m_text.SetText("The count is <#0080ff>{0}</color>", count % 1000);
count++;
}
}
}
}
@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: a74a8724ad40affc6cb4e6ab790c9cea
timeCreated: 1754265943
licenseType: Free
MonoImporter:
serializedVersion: 2
externalObjects: {}
defaultReferences: []
executionOrder: 0
icon: {fileID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,120 @@
using UnityEngine;
namespace TMPro.Examples
{
public class TMP_FrameRateCounter : MonoBehaviour
{
public enum FpsCounterAnchorPositions
{
TopLeft = 0,
BottomLeft = 1,
TopRight = 2,
BottomRight = 3
}
public float UpdateInterval = 5f;
private float m_LastInterval;
private int m_Frames;
public FpsCounterAnchorPositions AnchorPosition = FpsCounterAnchorPositions.TopRight;
private string htmlColorTag;
private const string fpsLabel = "{0:2}</color> <#8080ff>FPS \n<#FF8000>{1:2} <#8080ff>MS";
private TextMeshPro m_TextMeshPro;
private Transform m_frameCounter_transform;
private Camera m_camera;
private FpsCounterAnchorPositions last_AnchorPosition;
private void Awake()
{
if (base.enabled)
{
m_camera = Camera.main;
Application.targetFrameRate = 9999;
GameObject gameObject = new GameObject("Frame Counter");
m_TextMeshPro = gameObject.AddComponent<TextMeshPro>();
m_TextMeshPro.font = Resources.Load<TMP_FontAsset>("Fonts & Materials/LiberationSans SDF");
m_TextMeshPro.fontSharedMaterial = Resources.Load<Material>("Fonts & Materials/LiberationSans SDF - Overlay");
m_frameCounter_transform = gameObject.transform;
m_frameCounter_transform.SetParent(m_camera.transform);
m_frameCounter_transform.localRotation = Quaternion.identity;
m_TextMeshPro.enableWordWrapping = false;
m_TextMeshPro.fontSize = 24f;
Set_FrameCounter_Position(AnchorPosition);
last_AnchorPosition = AnchorPosition;
}
}
private void Start()
{
m_LastInterval = Time.realtimeSinceStartup;
m_Frames = 0;
}
private void Update()
{
if (AnchorPosition != last_AnchorPosition)
{
Set_FrameCounter_Position(AnchorPosition);
}
last_AnchorPosition = AnchorPosition;
m_Frames++;
float realtimeSinceStartup = Time.realtimeSinceStartup;
if (realtimeSinceStartup > m_LastInterval + UpdateInterval)
{
float num = (float)m_Frames / (realtimeSinceStartup - m_LastInterval);
float arg = 1000f / Mathf.Max(num, 1E-05f);
if (num < 30f)
{
htmlColorTag = "<color=yellow>";
}
else if (num < 10f)
{
htmlColorTag = "<color=red>";
}
else
{
htmlColorTag = "<color=green>";
}
m_TextMeshPro.SetText(htmlColorTag + "{0:2}</color> <#8080ff>FPS \n<#FF8000>{1:2} <#8080ff>MS", num, arg);
m_Frames = 0;
m_LastInterval = realtimeSinceStartup;
}
}
private void Set_FrameCounter_Position(FpsCounterAnchorPositions anchor_position)
{
m_TextMeshPro.margin = new Vector4(1f, 1f, 1f, 1f);
switch (anchor_position)
{
case FpsCounterAnchorPositions.TopLeft:
m_TextMeshPro.alignment = TextAlignmentOptions.TopLeft;
m_TextMeshPro.rectTransform.pivot = new Vector2(0f, 1f);
m_frameCounter_transform.position = m_camera.ViewportToWorldPoint(new Vector3(0f, 1f, 100f));
break;
case FpsCounterAnchorPositions.BottomLeft:
m_TextMeshPro.alignment = TextAlignmentOptions.BottomLeft;
m_TextMeshPro.rectTransform.pivot = new Vector2(0f, 0f);
m_frameCounter_transform.position = m_camera.ViewportToWorldPoint(new Vector3(0f, 0f, 100f));
break;
case FpsCounterAnchorPositions.TopRight:
m_TextMeshPro.alignment = TextAlignmentOptions.TopRight;
m_TextMeshPro.rectTransform.pivot = new Vector2(1f, 1f);
m_frameCounter_transform.position = m_camera.ViewportToWorldPoint(new Vector3(1f, 1f, 100f));
break;
case FpsCounterAnchorPositions.BottomRight:
m_TextMeshPro.alignment = TextAlignmentOptions.BottomRight;
m_TextMeshPro.rectTransform.pivot = new Vector2(1f, 0f);
m_frameCounter_transform.position = m_camera.ViewportToWorldPoint(new Vector3(1f, 0f, 100f));
break;
}
}
}
}
@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 1a54c53eb4e48d8f878461e014fe7742
timeCreated: 1754265943
licenseType: Free
MonoImporter:
serializedVersion: 2
externalObjects: {}
defaultReferences: []
executionOrder: 0
icon: {fileID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,65 @@
using UnityEngine;
namespace TMPro.Examples
{
public class TMP_TextEventCheck : MonoBehaviour
{
public TMP_TextEventHandler TextEventHandler;
private TMP_Text m_TextComponent;
private void OnEnable()
{
if (TextEventHandler != null)
{
m_TextComponent = TextEventHandler.GetComponent<TMP_Text>();
TextEventHandler.onCharacterSelection.AddListener(OnCharacterSelection);
TextEventHandler.onSpriteSelection.AddListener(OnSpriteSelection);
TextEventHandler.onWordSelection.AddListener(OnWordSelection);
TextEventHandler.onLineSelection.AddListener(OnLineSelection);
TextEventHandler.onLinkSelection.AddListener(OnLinkSelection);
}
}
private void OnDisable()
{
if (TextEventHandler != null)
{
TextEventHandler.onCharacterSelection.RemoveListener(OnCharacterSelection);
TextEventHandler.onSpriteSelection.RemoveListener(OnSpriteSelection);
TextEventHandler.onWordSelection.RemoveListener(OnWordSelection);
TextEventHandler.onLineSelection.RemoveListener(OnLineSelection);
TextEventHandler.onLinkSelection.RemoveListener(OnLinkSelection);
}
}
private void OnCharacterSelection(char c, int index)
{
Debug.Log("Character [" + c + "] at Index: " + index + " has been selected.");
}
private void OnSpriteSelection(char c, int index)
{
Debug.Log("Sprite [" + c + "] at Index: " + index + " has been selected.");
}
private void OnWordSelection(string word, int firstCharacterIndex, int length)
{
Debug.Log("Word [" + word + "] with first character index of " + firstCharacterIndex + " and length of " + length + " has been selected.");
}
private void OnLineSelection(string lineText, int firstCharacterIndex, int length)
{
Debug.Log("Line [" + lineText + "] with first character index of " + firstCharacterIndex + " and length of " + length + " has been selected.");
}
private void OnLinkSelection(string linkID, string linkText, int linkIndex)
{
if (m_TextComponent != null)
{
_ = ref m_TextComponent.textInfo.linkInfo[linkIndex];
}
Debug.Log("Link Index: " + linkIndex + " with ID [" + linkID + "] and Text \"" + linkText + "\" has been selected.");
}
}
}
@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 54efb719a127edb2a5212e04e8987006
timeCreated: 1754265943
licenseType: Free
MonoImporter:
serializedVersion: 2
externalObjects: {}
defaultReferences: []
executionOrder: 0
icon: {fileID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,8 @@
using UnityEngine;
namespace TMPro.Examples
{
public class TMP_TextInfoDebugTool : MonoBehaviour
{
}
}
@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 11cae6bd7323ff28f59fa7725fd3dbfe
timeCreated: 1754265943
licenseType: Free
MonoImporter:
serializedVersion: 2
externalObjects: {}
defaultReferences: []
executionOrder: 0
icon: {fileID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,101 @@
using UnityEngine;
using UnityEngine.EventSystems;
namespace TMPro.Examples
{
public class TMP_TextSelector_A : MonoBehaviour, IPointerEnterHandler, IEventSystemHandler, IPointerExitHandler
{
private TextMeshPro m_TextMeshPro;
private Camera m_Camera;
private bool m_isHoveringObject;
private int m_selectedLink = -1;
private int m_lastCharIndex = -1;
private int m_lastWordIndex = -1;
private void Awake()
{
m_TextMeshPro = base.gameObject.GetComponent<TextMeshPro>();
m_Camera = Camera.main;
m_TextMeshPro.ForceMeshUpdate();
}
private void LateUpdate()
{
m_isHoveringObject = false;
if (TMP_TextUtilities.IsIntersectingRectTransform(m_TextMeshPro.rectTransform, Input.mousePosition, Camera.main))
{
m_isHoveringObject = true;
}
if (!m_isHoveringObject)
{
return;
}
int num = TMP_TextUtilities.FindIntersectingCharacter(m_TextMeshPro, Input.mousePosition, Camera.main, visibleOnly: true);
if (num != -1 && num != m_lastCharIndex && (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift)))
{
m_lastCharIndex = num;
int materialReferenceIndex = m_TextMeshPro.textInfo.characterInfo[num].materialReferenceIndex;
int vertexIndex = m_TextMeshPro.textInfo.characterInfo[num].vertexIndex;
Color32 color = new Color32((byte)Random.Range(0, 255), (byte)Random.Range(0, 255), (byte)Random.Range(0, 255), byte.MaxValue);
Color32[] colors = m_TextMeshPro.textInfo.meshInfo[materialReferenceIndex].colors32;
colors[vertexIndex] = color;
colors[vertexIndex + 1] = color;
colors[vertexIndex + 2] = color;
colors[vertexIndex + 3] = color;
m_TextMeshPro.textInfo.meshInfo[materialReferenceIndex].mesh.colors32 = colors;
}
int num2 = TMP_TextUtilities.FindIntersectingLink(m_TextMeshPro, Input.mousePosition, m_Camera);
if ((num2 == -1 && m_selectedLink != -1) || num2 != m_selectedLink)
{
m_selectedLink = -1;
}
if (num2 != -1 && num2 != m_selectedLink)
{
m_selectedLink = num2;
TMP_LinkInfo tMP_LinkInfo = m_TextMeshPro.textInfo.linkInfo[num2];
RectTransformUtility.ScreenPointToWorldPointInRectangle(m_TextMeshPro.rectTransform, Input.mousePosition, m_Camera, out var _);
string linkID = tMP_LinkInfo.GetLinkID();
if (!(linkID == "id_01"))
{
_ = linkID == "id_02";
}
}
int num3 = TMP_TextUtilities.FindIntersectingWord(m_TextMeshPro, Input.mousePosition, Camera.main);
if (num3 != -1 && num3 != m_lastWordIndex)
{
m_lastWordIndex = num3;
TMP_WordInfo tMP_WordInfo = m_TextMeshPro.textInfo.wordInfo[num3];
Vector3 position = m_TextMeshPro.transform.TransformPoint(m_TextMeshPro.textInfo.characterInfo[tMP_WordInfo.firstCharacterIndex].bottomLeft);
position = Camera.main.WorldToScreenPoint(position);
Color32[] colors2 = m_TextMeshPro.textInfo.meshInfo[0].colors32;
Color32 color2 = new Color32((byte)Random.Range(0, 255), (byte)Random.Range(0, 255), (byte)Random.Range(0, 255), byte.MaxValue);
for (int i = 0; i < tMP_WordInfo.characterCount; i++)
{
int vertexIndex2 = m_TextMeshPro.textInfo.characterInfo[tMP_WordInfo.firstCharacterIndex + i].vertexIndex;
colors2[vertexIndex2] = color2;
colors2[vertexIndex2 + 1] = color2;
colors2[vertexIndex2 + 2] = color2;
colors2[vertexIndex2 + 3] = color2;
}
m_TextMeshPro.mesh.colors32 = colors2;
}
}
public void OnPointerEnter(PointerEventData eventData)
{
Debug.Log("OnPointerEnter()");
m_isHoveringObject = true;
}
public void OnPointerExit(PointerEventData eventData)
{
Debug.Log("OnPointerExit()");
m_isHoveringObject = false;
}
}
}
@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 9e740b8b0ef376f7ef63ead313fc8c51
timeCreated: 1754265943
licenseType: Free
MonoImporter:
serializedVersion: 2
externalObjects: {}
defaultReferences: []
executionOrder: 0
icon: {fileID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,255 @@
using UnityEngine;
using UnityEngine.EventSystems;
namespace TMPro.Examples
{
public class TMP_TextSelector_B : MonoBehaviour, IPointerEnterHandler, IEventSystemHandler, IPointerExitHandler, IPointerClickHandler, IPointerUpHandler
{
public RectTransform TextPopup_Prefab_01;
private RectTransform m_TextPopup_RectTransform;
private TextMeshProUGUI m_TextPopup_TMPComponent;
private const string k_LinkText = "You have selected link <#ffff00>";
private const string k_WordText = "Word Index: <#ffff00>";
private TextMeshProUGUI m_TextMeshPro;
private Canvas m_Canvas;
private Camera m_Camera;
private bool isHoveringObject;
private int m_selectedWord = -1;
private int m_selectedLink = -1;
private int m_lastIndex = -1;
private Matrix4x4 m_matrix;
private TMP_MeshInfo[] m_cachedMeshInfoVertexData;
private void Awake()
{
m_TextMeshPro = base.gameObject.GetComponent<TextMeshProUGUI>();
m_Canvas = base.gameObject.GetComponentInParent<Canvas>();
if (m_Canvas.renderMode == RenderMode.ScreenSpaceOverlay)
{
m_Camera = null;
}
else
{
m_Camera = m_Canvas.worldCamera;
}
m_TextPopup_RectTransform = Object.Instantiate(TextPopup_Prefab_01);
m_TextPopup_RectTransform.SetParent(m_Canvas.transform, worldPositionStays: false);
m_TextPopup_TMPComponent = m_TextPopup_RectTransform.GetComponentInChildren<TextMeshProUGUI>();
m_TextPopup_RectTransform.gameObject.SetActive(value: false);
}
private void OnEnable()
{
TMPro_EventManager.TEXT_CHANGED_EVENT.Add(ON_TEXT_CHANGED);
}
private void OnDisable()
{
TMPro_EventManager.TEXT_CHANGED_EVENT.Remove(ON_TEXT_CHANGED);
}
private void ON_TEXT_CHANGED(Object obj)
{
if (obj == m_TextMeshPro)
{
m_cachedMeshInfoVertexData = m_TextMeshPro.textInfo.CopyMeshInfoVertexData();
}
}
private void LateUpdate()
{
if (isHoveringObject)
{
int num = TMP_TextUtilities.FindIntersectingCharacter(m_TextMeshPro, Input.mousePosition, m_Camera, visibleOnly: true);
if (num == -1 || num != m_lastIndex)
{
RestoreCachedVertexAttributes(m_lastIndex);
m_lastIndex = -1;
}
if (num != -1 && num != m_lastIndex && (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift)))
{
m_lastIndex = num;
int materialReferenceIndex = m_TextMeshPro.textInfo.characterInfo[num].materialReferenceIndex;
int vertexIndex = m_TextMeshPro.textInfo.characterInfo[num].vertexIndex;
Vector3[] vertices = m_TextMeshPro.textInfo.meshInfo[materialReferenceIndex].vertices;
Vector3 vector = (Vector2)((vertices[vertexIndex] + vertices[vertexIndex + 2]) / 2f);
vertices[vertexIndex] -= vector;
vertices[vertexIndex + 1] -= vector;
vertices[vertexIndex + 2] -= vector;
vertices[vertexIndex + 3] -= vector;
float num2 = 1.5f;
m_matrix = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, Vector3.one * num2);
vertices[vertexIndex] = m_matrix.MultiplyPoint3x4(vertices[vertexIndex]);
vertices[vertexIndex + 1] = m_matrix.MultiplyPoint3x4(vertices[vertexIndex + 1]);
vertices[vertexIndex + 2] = m_matrix.MultiplyPoint3x4(vertices[vertexIndex + 2]);
vertices[vertexIndex + 3] = m_matrix.MultiplyPoint3x4(vertices[vertexIndex + 3]);
vertices[vertexIndex] += vector;
vertices[vertexIndex + 1] += vector;
vertices[vertexIndex + 2] += vector;
vertices[vertexIndex + 3] += vector;
Color32 color = new Color32(byte.MaxValue, byte.MaxValue, 192, byte.MaxValue);
Color32[] colors = m_TextMeshPro.textInfo.meshInfo[materialReferenceIndex].colors32;
colors[vertexIndex] = color;
colors[vertexIndex + 1] = color;
colors[vertexIndex + 2] = color;
colors[vertexIndex + 3] = color;
TMP_MeshInfo tMP_MeshInfo = m_TextMeshPro.textInfo.meshInfo[materialReferenceIndex];
int dst = vertices.Length - 4;
tMP_MeshInfo.SwapVertexData(vertexIndex, dst);
m_TextMeshPro.UpdateVertexData(TMP_VertexDataUpdateFlags.All);
}
int num3 = TMP_TextUtilities.FindIntersectingWord(m_TextMeshPro, Input.mousePosition, m_Camera);
if (m_TextPopup_RectTransform != null && m_selectedWord != -1 && (num3 == -1 || num3 != m_selectedWord))
{
TMP_WordInfo tMP_WordInfo = m_TextMeshPro.textInfo.wordInfo[m_selectedWord];
for (int i = 0; i < tMP_WordInfo.characterCount; i++)
{
int num4 = tMP_WordInfo.firstCharacterIndex + i;
int materialReferenceIndex2 = m_TextMeshPro.textInfo.characterInfo[num4].materialReferenceIndex;
int vertexIndex2 = m_TextMeshPro.textInfo.characterInfo[num4].vertexIndex;
Color32[] colors2 = m_TextMeshPro.textInfo.meshInfo[materialReferenceIndex2].colors32;
colors2[vertexIndex2 + 3] = (colors2[vertexIndex2 + 2] = (colors2[vertexIndex2 + 1] = (colors2[vertexIndex2] = colors2[vertexIndex2].Tint(1.33333f))));
}
m_TextMeshPro.UpdateVertexData(TMP_VertexDataUpdateFlags.All);
m_selectedWord = -1;
}
if (num3 != -1 && num3 != m_selectedWord && !Input.GetKey(KeyCode.LeftShift) && !Input.GetKey(KeyCode.RightShift))
{
m_selectedWord = num3;
TMP_WordInfo tMP_WordInfo2 = m_TextMeshPro.textInfo.wordInfo[num3];
for (int j = 0; j < tMP_WordInfo2.characterCount; j++)
{
int num5 = tMP_WordInfo2.firstCharacterIndex + j;
int materialReferenceIndex3 = m_TextMeshPro.textInfo.characterInfo[num5].materialReferenceIndex;
int vertexIndex3 = m_TextMeshPro.textInfo.characterInfo[num5].vertexIndex;
Color32[] colors3 = m_TextMeshPro.textInfo.meshInfo[materialReferenceIndex3].colors32;
colors3[vertexIndex3 + 3] = (colors3[vertexIndex3 + 2] = (colors3[vertexIndex3 + 1] = (colors3[vertexIndex3] = colors3[vertexIndex3].Tint(0.75f))));
}
m_TextMeshPro.UpdateVertexData(TMP_VertexDataUpdateFlags.All);
}
int num6 = TMP_TextUtilities.FindIntersectingLink(m_TextMeshPro, Input.mousePosition, m_Camera);
if ((num6 == -1 && m_selectedLink != -1) || num6 != m_selectedLink)
{
m_TextPopup_RectTransform.gameObject.SetActive(value: false);
m_selectedLink = -1;
}
if (num6 == -1 || num6 == m_selectedLink)
{
return;
}
m_selectedLink = num6;
TMP_LinkInfo tMP_LinkInfo = m_TextMeshPro.textInfo.linkInfo[num6];
RectTransformUtility.ScreenPointToWorldPointInRectangle(m_TextMeshPro.rectTransform, Input.mousePosition, m_Camera, out var worldPoint);
string linkID = tMP_LinkInfo.GetLinkID();
if (!(linkID == "id_01"))
{
if (linkID == "id_02")
{
m_TextPopup_RectTransform.position = worldPoint;
m_TextPopup_RectTransform.gameObject.SetActive(value: true);
m_TextPopup_TMPComponent.text = "You have selected link <#ffff00> ID 02";
}
}
else
{
m_TextPopup_RectTransform.position = worldPoint;
m_TextPopup_RectTransform.gameObject.SetActive(value: true);
m_TextPopup_TMPComponent.text = "You have selected link <#ffff00> ID 01";
}
}
else if (m_lastIndex != -1)
{
RestoreCachedVertexAttributes(m_lastIndex);
m_lastIndex = -1;
}
}
public void OnPointerEnter(PointerEventData eventData)
{
isHoveringObject = true;
}
public void OnPointerExit(PointerEventData eventData)
{
isHoveringObject = false;
}
public void OnPointerClick(PointerEventData eventData)
{
}
public void OnPointerUp(PointerEventData eventData)
{
}
private void RestoreCachedVertexAttributes(int index)
{
if (index != -1 && index <= m_TextMeshPro.textInfo.characterCount - 1)
{
int materialReferenceIndex = m_TextMeshPro.textInfo.characterInfo[index].materialReferenceIndex;
int vertexIndex = m_TextMeshPro.textInfo.characterInfo[index].vertexIndex;
Vector3[] vertices = m_cachedMeshInfoVertexData[materialReferenceIndex].vertices;
Vector3[] vertices2 = m_TextMeshPro.textInfo.meshInfo[materialReferenceIndex].vertices;
vertices2[vertexIndex] = vertices[vertexIndex];
vertices2[vertexIndex + 1] = vertices[vertexIndex + 1];
vertices2[vertexIndex + 2] = vertices[vertexIndex + 2];
vertices2[vertexIndex + 3] = vertices[vertexIndex + 3];
Color32[] colors = m_TextMeshPro.textInfo.meshInfo[materialReferenceIndex].colors32;
Color32[] colors2 = m_cachedMeshInfoVertexData[materialReferenceIndex].colors32;
colors[vertexIndex] = colors2[vertexIndex];
colors[vertexIndex + 1] = colors2[vertexIndex + 1];
colors[vertexIndex + 2] = colors2[vertexIndex + 2];
colors[vertexIndex + 3] = colors2[vertexIndex + 3];
Vector2[] uvs = m_cachedMeshInfoVertexData[materialReferenceIndex].uvs0;
Vector2[] uvs2 = m_TextMeshPro.textInfo.meshInfo[materialReferenceIndex].uvs0;
uvs2[vertexIndex] = uvs[vertexIndex];
uvs2[vertexIndex + 1] = uvs[vertexIndex + 1];
uvs2[vertexIndex + 2] = uvs[vertexIndex + 2];
uvs2[vertexIndex + 3] = uvs[vertexIndex + 3];
Vector2[] uvs3 = m_cachedMeshInfoVertexData[materialReferenceIndex].uvs2;
Vector2[] uvs4 = m_TextMeshPro.textInfo.meshInfo[materialReferenceIndex].uvs2;
uvs4[vertexIndex] = uvs3[vertexIndex];
uvs4[vertexIndex + 1] = uvs3[vertexIndex + 1];
uvs4[vertexIndex + 2] = uvs3[vertexIndex + 2];
uvs4[vertexIndex + 3] = uvs3[vertexIndex + 3];
int num = (vertices.Length / 4 - 1) * 4;
vertices2[num] = vertices[num];
vertices2[num + 1] = vertices[num + 1];
vertices2[num + 2] = vertices[num + 2];
vertices2[num + 3] = vertices[num + 3];
colors2 = m_cachedMeshInfoVertexData[materialReferenceIndex].colors32;
Color32[] colors3 = m_TextMeshPro.textInfo.meshInfo[materialReferenceIndex].colors32;
colors3[num] = colors2[num];
colors3[num + 1] = colors2[num + 1];
colors3[num + 2] = colors2[num + 2];
colors3[num + 3] = colors2[num + 3];
uvs = m_cachedMeshInfoVertexData[materialReferenceIndex].uvs0;
Vector2[] uvs5 = m_TextMeshPro.textInfo.meshInfo[materialReferenceIndex].uvs0;
uvs5[num] = uvs[num];
uvs5[num + 1] = uvs[num + 1];
uvs5[num + 2] = uvs[num + 2];
uvs5[num + 3] = uvs[num + 3];
uvs3 = m_cachedMeshInfoVertexData[materialReferenceIndex].uvs2;
Vector2[] uvs6 = m_TextMeshPro.textInfo.meshInfo[materialReferenceIndex].uvs2;
uvs6[num] = uvs3[num];
uvs6[num + 1] = uvs3[num + 1];
uvs6[num + 2] = uvs3[num + 2];
uvs6[num + 3] = uvs3[num + 3];
m_TextMeshPro.UpdateVertexData(TMP_VertexDataUpdateFlags.All);
}
}
}
}
@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 47f3637b1b0879c2e0568c83b87d1d8f
timeCreated: 1754265943
licenseType: Free
MonoImporter:
serializedVersion: 2
externalObjects: {}
defaultReferences: []
executionOrder: 0
icon: {fileID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,124 @@
using UnityEngine;
namespace TMPro.Examples
{
public class TMP_UiFrameRateCounter : MonoBehaviour
{
public enum FpsCounterAnchorPositions
{
TopLeft = 0,
BottomLeft = 1,
TopRight = 2,
BottomRight = 3
}
public float UpdateInterval = 5f;
private float m_LastInterval;
private int m_Frames;
public FpsCounterAnchorPositions AnchorPosition = FpsCounterAnchorPositions.TopRight;
private string htmlColorTag;
private const string fpsLabel = "{0:2}</color> <#8080ff>FPS \n<#FF8000>{1:2} <#8080ff>MS";
private TextMeshProUGUI m_TextMeshPro;
private RectTransform m_frameCounter_transform;
private FpsCounterAnchorPositions last_AnchorPosition;
private void Awake()
{
if (base.enabled)
{
Application.targetFrameRate = 1000;
GameObject gameObject = new GameObject("Frame Counter");
m_frameCounter_transform = gameObject.AddComponent<RectTransform>();
m_frameCounter_transform.SetParent(base.transform, worldPositionStays: false);
m_TextMeshPro = gameObject.AddComponent<TextMeshProUGUI>();
m_TextMeshPro.font = Resources.Load<TMP_FontAsset>("Fonts & Materials/LiberationSans SDF");
m_TextMeshPro.fontSharedMaterial = Resources.Load<Material>("Fonts & Materials/LiberationSans SDF - Overlay");
m_TextMeshPro.enableWordWrapping = false;
m_TextMeshPro.fontSize = 36f;
m_TextMeshPro.isOverlay = true;
Set_FrameCounter_Position(AnchorPosition);
last_AnchorPosition = AnchorPosition;
}
}
private void Start()
{
m_LastInterval = Time.realtimeSinceStartup;
m_Frames = 0;
}
private void Update()
{
if (AnchorPosition != last_AnchorPosition)
{
Set_FrameCounter_Position(AnchorPosition);
}
last_AnchorPosition = AnchorPosition;
m_Frames++;
float realtimeSinceStartup = Time.realtimeSinceStartup;
if (realtimeSinceStartup > m_LastInterval + UpdateInterval)
{
float num = (float)m_Frames / (realtimeSinceStartup - m_LastInterval);
float arg = 1000f / Mathf.Max(num, 1E-05f);
if (num < 30f)
{
htmlColorTag = "<color=yellow>";
}
else if (num < 10f)
{
htmlColorTag = "<color=red>";
}
else
{
htmlColorTag = "<color=green>";
}
m_TextMeshPro.SetText(htmlColorTag + "{0:2}</color> <#8080ff>FPS \n<#FF8000>{1:2} <#8080ff>MS", num, arg);
m_Frames = 0;
m_LastInterval = realtimeSinceStartup;
}
}
private void Set_FrameCounter_Position(FpsCounterAnchorPositions anchor_position)
{
switch (anchor_position)
{
case FpsCounterAnchorPositions.TopLeft:
m_TextMeshPro.alignment = TextAlignmentOptions.TopLeft;
m_frameCounter_transform.pivot = new Vector2(0f, 1f);
m_frameCounter_transform.anchorMin = new Vector2(0.01f, 0.99f);
m_frameCounter_transform.anchorMax = new Vector2(0.01f, 0.99f);
m_frameCounter_transform.anchoredPosition = new Vector2(0f, 1f);
break;
case FpsCounterAnchorPositions.BottomLeft:
m_TextMeshPro.alignment = TextAlignmentOptions.BottomLeft;
m_frameCounter_transform.pivot = new Vector2(0f, 0f);
m_frameCounter_transform.anchorMin = new Vector2(0.01f, 0.01f);
m_frameCounter_transform.anchorMax = new Vector2(0.01f, 0.01f);
m_frameCounter_transform.anchoredPosition = new Vector2(0f, 0f);
break;
case FpsCounterAnchorPositions.TopRight:
m_TextMeshPro.alignment = TextAlignmentOptions.TopRight;
m_frameCounter_transform.pivot = new Vector2(1f, 1f);
m_frameCounter_transform.anchorMin = new Vector2(0.99f, 0.99f);
m_frameCounter_transform.anchorMax = new Vector2(0.99f, 0.99f);
m_frameCounter_transform.anchoredPosition = new Vector2(1f, 1f);
break;
case FpsCounterAnchorPositions.BottomRight:
m_TextMeshPro.alignment = TextAlignmentOptions.BottomRight;
m_frameCounter_transform.pivot = new Vector2(1f, 0f);
m_frameCounter_transform.anchorMin = new Vector2(0.99f, 0.01f);
m_frameCounter_transform.anchorMax = new Vector2(0.99f, 0.01f);
m_frameCounter_transform.anchoredPosition = new Vector2(1f, 0f);
break;
}
}
}
}
@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 7cba422eb7c134d053003a658c5b837c
timeCreated: 1754265943
licenseType: Free
MonoImporter:
serializedVersion: 2
externalObjects: {}
defaultReferences: []
executionOrder: 0
icon: {fileID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,70 @@
using UnityEngine;
namespace TMPro.Examples
{
public class TMPro_InstructionOverlay : MonoBehaviour
{
public enum FpsCounterAnchorPositions
{
TopLeft = 0,
BottomLeft = 1,
TopRight = 2,
BottomRight = 3
}
public FpsCounterAnchorPositions AnchorPosition = FpsCounterAnchorPositions.BottomLeft;
private const string instructions = "Camera Control - <#ffff00>Shift + RMB\n</color>Zoom - <#ffff00>Mouse wheel.";
private TextMeshPro m_TextMeshPro;
private TextContainer m_textContainer;
private Transform m_frameCounter_transform;
private Camera m_camera;
private void Awake()
{
if (base.enabled)
{
m_camera = Camera.main;
GameObject gameObject = new GameObject("Frame Counter");
m_frameCounter_transform = gameObject.transform;
m_frameCounter_transform.parent = m_camera.transform;
m_frameCounter_transform.localRotation = Quaternion.identity;
m_TextMeshPro = gameObject.AddComponent<TextMeshPro>();
m_TextMeshPro.font = Resources.Load<TMP_FontAsset>("Fonts & Materials/LiberationSans SDF");
m_TextMeshPro.fontSharedMaterial = Resources.Load<Material>("Fonts & Materials/LiberationSans SDF - Overlay");
m_TextMeshPro.fontSize = 30f;
m_TextMeshPro.isOverlay = true;
m_textContainer = gameObject.GetComponent<TextContainer>();
Set_FrameCounter_Position(AnchorPosition);
m_TextMeshPro.text = "Camera Control - <#ffff00>Shift + RMB\n</color>Zoom - <#ffff00>Mouse wheel.";
}
}
private void Set_FrameCounter_Position(FpsCounterAnchorPositions anchor_position)
{
switch (anchor_position)
{
case FpsCounterAnchorPositions.TopLeft:
m_textContainer.anchorPosition = TextContainerAnchors.TopLeft;
m_frameCounter_transform.position = m_camera.ViewportToWorldPoint(new Vector3(0f, 1f, 100f));
break;
case FpsCounterAnchorPositions.BottomLeft:
m_textContainer.anchorPosition = TextContainerAnchors.BottomLeft;
m_frameCounter_transform.position = m_camera.ViewportToWorldPoint(new Vector3(0f, 0f, 100f));
break;
case FpsCounterAnchorPositions.TopRight:
m_textContainer.anchorPosition = TextContainerAnchors.TopRight;
m_frameCounter_transform.position = m_camera.ViewportToWorldPoint(new Vector3(1f, 1f, 100f));
break;
case FpsCounterAnchorPositions.BottomRight:
m_textContainer.anchorPosition = TextContainerAnchors.BottomRight;
m_frameCounter_transform.position = m_camera.ViewportToWorldPoint(new Vector3(1f, 0f, 100f));
break;
}
}
}
}
@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 168af457cec814b549454fdc5db6358c
timeCreated: 1754265943
licenseType: Free
MonoImporter:
serializedVersion: 2
externalObjects: {}
defaultReferences: []
executionOrder: 0
icon: {fileID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,44 @@
using System.Collections;
using UnityEngine;
namespace TMPro.Examples
{
public class TeleType : MonoBehaviour
{
private string label01 = "Example <sprite=2> of using <sprite=7> <#ffa000>Graphics Inline</color> <sprite=5> with Text in <font=\"Bangers SDF\" material=\"Bangers SDF - Drop Shadow\">TextMesh<#40a0ff>Pro</color></font><sprite=0> and Unity<sprite=1>";
private string label02 = "Example <sprite=2> of using <sprite=7> <#ffa000>Graphics Inline</color> <sprite=5> with Text in <font=\"Bangers SDF\" material=\"Bangers SDF - Drop Shadow\">TextMesh<#40a0ff>Pro</color></font><sprite=0> and Unity<sprite=2>";
private TMP_Text m_textMeshPro;
private void Awake()
{
m_textMeshPro = GetComponent<TMP_Text>();
m_textMeshPro.text = label01;
m_textMeshPro.enableWordWrapping = true;
m_textMeshPro.alignment = TextAlignmentOptions.Top;
}
private IEnumerator Start()
{
m_textMeshPro.ForceMeshUpdate();
int totalVisibleCharacters = m_textMeshPro.textInfo.characterCount;
int counter = 0;
while (true)
{
int num = counter % (totalVisibleCharacters + 1);
m_textMeshPro.maxVisibleCharacters = num;
if (num >= totalVisibleCharacters)
{
yield return new WaitForSeconds(1f);
m_textMeshPro.text = label02;
yield return new WaitForSeconds(1f);
m_textMeshPro.text = label01;
yield return new WaitForSeconds(1f);
}
counter++;
yield return new WaitForSeconds(0.05f);
}
}
}
}
@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 460dc54e55fd2bb3558ca6f3a91d534f
timeCreated: 1754265943
licenseType: Free
MonoImporter:
serializedVersion: 2
externalObjects: {}
defaultReferences: []
executionOrder: 0
icon: {fileID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,93 @@
using System.Collections;
using UnityEngine;
namespace TMPro.Examples
{
public class TextConsoleSimulator : MonoBehaviour
{
private TMP_Text m_TextComponent;
private bool hasTextChanged;
private void Awake()
{
m_TextComponent = base.gameObject.GetComponent<TMP_Text>();
}
private void Start()
{
StartCoroutine(RevealCharacters(m_TextComponent));
}
private void OnEnable()
{
TMPro_EventManager.TEXT_CHANGED_EVENT.Add(ON_TEXT_CHANGED);
}
private void OnDisable()
{
TMPro_EventManager.TEXT_CHANGED_EVENT.Remove(ON_TEXT_CHANGED);
}
private void ON_TEXT_CHANGED(Object obj)
{
hasTextChanged = true;
}
private IEnumerator RevealCharacters(TMP_Text textComponent)
{
textComponent.ForceMeshUpdate();
TMP_TextInfo textInfo = textComponent.textInfo;
int totalVisibleCharacters = textInfo.characterCount;
int visibleCount = 0;
while (true)
{
if (hasTextChanged)
{
totalVisibleCharacters = textInfo.characterCount;
hasTextChanged = false;
}
if (visibleCount > totalVisibleCharacters)
{
yield return new WaitForSeconds(1f);
visibleCount = 0;
}
textComponent.maxVisibleCharacters = visibleCount;
visibleCount++;
yield return null;
}
}
private IEnumerator RevealWords(TMP_Text textComponent)
{
textComponent.ForceMeshUpdate();
int totalWordCount = textComponent.textInfo.wordCount;
int totalVisibleCharacters = textComponent.textInfo.characterCount;
int counter = 0;
int visibleCount = 0;
while (true)
{
int num = counter % (totalWordCount + 1);
if (num == 0)
{
visibleCount = 0;
}
else if (num < totalWordCount)
{
visibleCount = textComponent.textInfo.wordInfo[num - 1].lastCharacterIndex + 1;
}
else if (num == totalWordCount)
{
visibleCount = totalVisibleCharacters;
}
textComponent.maxVisibleCharacters = visibleCount;
if (visibleCount >= totalVisibleCharacters)
{
yield return new WaitForSeconds(1f);
}
counter++;
yield return new WaitForSeconds(0.1f);
}
}
}
}
@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 38f8f54f1c44bd37a1174b9112fc8015
timeCreated: 1754265943
licenseType: Free
MonoImporter:
serializedVersion: 2
externalObjects: {}
defaultReferences: []
executionOrder: 0
icon: {fileID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,166 @@
using System.Collections;
using UnityEngine;
namespace TMPro.Examples
{
public class TextMeshProFloatingText : MonoBehaviour
{
public Font TheFont;
private GameObject m_floatingText;
private TextMeshPro m_textMeshPro;
private TextMesh m_textMesh;
private Transform m_transform;
private Transform m_floatingText_Transform;
private Transform m_cameraTransform;
private Vector3 lastPOS = Vector3.zero;
private Quaternion lastRotation = Quaternion.identity;
public int SpawnType;
public bool IsTextObjectScaleStatic;
private static WaitForEndOfFrame k_WaitForEndOfFrame = new WaitForEndOfFrame();
private static WaitForSeconds[] k_WaitForSecondsRandom = new WaitForSeconds[20]
{
new WaitForSeconds(0.05f),
new WaitForSeconds(0.1f),
new WaitForSeconds(0.15f),
new WaitForSeconds(0.2f),
new WaitForSeconds(0.25f),
new WaitForSeconds(0.3f),
new WaitForSeconds(0.35f),
new WaitForSeconds(0.4f),
new WaitForSeconds(0.45f),
new WaitForSeconds(0.5f),
new WaitForSeconds(0.55f),
new WaitForSeconds(0.6f),
new WaitForSeconds(0.65f),
new WaitForSeconds(0.7f),
new WaitForSeconds(0.75f),
new WaitForSeconds(0.8f),
new WaitForSeconds(0.85f),
new WaitForSeconds(0.9f),
new WaitForSeconds(0.95f),
new WaitForSeconds(1f)
};
private void Awake()
{
m_transform = base.transform;
m_floatingText = new GameObject(base.name + " floating text");
m_cameraTransform = Camera.main.transform;
}
private void Start()
{
if (SpawnType == 0)
{
m_textMeshPro = m_floatingText.AddComponent<TextMeshPro>();
m_textMeshPro.rectTransform.sizeDelta = new Vector2(3f, 3f);
m_floatingText_Transform = m_floatingText.transform;
m_floatingText_Transform.position = m_transform.position + new Vector3(0f, 15f, 0f);
m_textMeshPro.alignment = TextAlignmentOptions.Center;
m_textMeshPro.color = new Color32((byte)Random.Range(0, 255), (byte)Random.Range(0, 255), (byte)Random.Range(0, 255), byte.MaxValue);
m_textMeshPro.fontSize = 24f;
m_textMeshPro.enableKerning = false;
m_textMeshPro.text = string.Empty;
m_textMeshPro.isTextObjectScaleStatic = IsTextObjectScaleStatic;
StartCoroutine(DisplayTextMeshProFloatingText());
}
else if (SpawnType == 1)
{
m_floatingText_Transform = m_floatingText.transform;
m_floatingText_Transform.position = m_transform.position + new Vector3(0f, 15f, 0f);
m_textMesh = m_floatingText.AddComponent<TextMesh>();
m_textMesh.font = Resources.Load<Font>("Fonts/ARIAL");
m_textMesh.GetComponent<Renderer>().sharedMaterial = m_textMesh.font.material;
m_textMesh.color = new Color32((byte)Random.Range(0, 255), (byte)Random.Range(0, 255), (byte)Random.Range(0, 255), byte.MaxValue);
m_textMesh.anchor = TextAnchor.LowerCenter;
m_textMesh.fontSize = 24;
StartCoroutine(DisplayTextMeshFloatingText());
}
else
{
_ = SpawnType;
_ = 2;
}
}
public IEnumerator DisplayTextMeshProFloatingText()
{
float CountDuration = 2f;
float starting_Count = Random.Range(5f, 20f);
float current_Count = starting_Count;
Vector3 start_pos = m_floatingText_Transform.position;
Color32 start_color = m_textMeshPro.color;
float alpha = 255f;
float fadeDuration = 3f / starting_Count * CountDuration;
while (current_Count > 0f)
{
current_Count -= Time.deltaTime / CountDuration * starting_Count;
if (current_Count <= 3f)
{
alpha = Mathf.Clamp(alpha - Time.deltaTime / fadeDuration * 255f, 0f, 255f);
}
m_textMeshPro.text = ((int)current_Count).ToString();
m_textMeshPro.color = new Color32(start_color.r, start_color.g, start_color.b, (byte)alpha);
m_floatingText_Transform.position += new Vector3(0f, starting_Count * Time.deltaTime, 0f);
if (!lastPOS.Compare(m_cameraTransform.position, 1000) || !lastRotation.Compare(m_cameraTransform.rotation, 1000))
{
lastPOS = m_cameraTransform.position;
lastRotation = m_cameraTransform.rotation;
m_floatingText_Transform.rotation = lastRotation;
Vector3 vector = m_transform.position - lastPOS;
m_transform.forward = new Vector3(vector.x, 0f, vector.z);
}
yield return k_WaitForEndOfFrame;
}
yield return k_WaitForSecondsRandom[Random.Range(0, 19)];
m_floatingText_Transform.position = start_pos;
StartCoroutine(DisplayTextMeshProFloatingText());
}
public IEnumerator DisplayTextMeshFloatingText()
{
float CountDuration = 2f;
float starting_Count = Random.Range(5f, 20f);
float current_Count = starting_Count;
Vector3 start_pos = m_floatingText_Transform.position;
Color32 start_color = m_textMesh.color;
float alpha = 255f;
float fadeDuration = 3f / starting_Count * CountDuration;
while (current_Count > 0f)
{
current_Count -= Time.deltaTime / CountDuration * starting_Count;
if (current_Count <= 3f)
{
alpha = Mathf.Clamp(alpha - Time.deltaTime / fadeDuration * 255f, 0f, 255f);
}
m_textMesh.text = ((int)current_Count).ToString();
m_textMesh.color = new Color32(start_color.r, start_color.g, start_color.b, (byte)alpha);
m_floatingText_Transform.position += new Vector3(0f, starting_Count * Time.deltaTime, 0f);
if (!lastPOS.Compare(m_cameraTransform.position, 1000) || !lastRotation.Compare(m_cameraTransform.rotation, 1000))
{
lastPOS = m_cameraTransform.position;
lastRotation = m_cameraTransform.rotation;
m_floatingText_Transform.rotation = lastRotation;
Vector3 vector = m_transform.position - lastPOS;
m_transform.forward = new Vector3(vector.x, 0f, vector.z);
}
yield return k_WaitForEndOfFrame;
}
yield return k_WaitForSecondsRandom[Random.Range(0, 20)];
m_floatingText_Transform.position = start_pos;
StartCoroutine(DisplayTextMeshFloatingText());
}
}
}
@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 427e65ebb2d527aa189759da011906d8
timeCreated: 1754265943
licenseType: Free
MonoImporter:
serializedVersion: 2
externalObjects: {}
defaultReferences: []
executionOrder: 0
icon: {fileID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,51 @@
using UnityEngine;
namespace TMPro.Examples
{
public class TextMeshSpawner : MonoBehaviour
{
public int SpawnType;
public int NumberOfNPC = 12;
public Font TheFont;
private TextMeshProFloatingText floatingText_Script;
private void Awake()
{
}
private void Start()
{
for (int i = 0; i < NumberOfNPC; i++)
{
if (SpawnType == 0)
{
GameObject gameObject = new GameObject();
gameObject.transform.position = new Vector3(Random.Range(-95f, 95f), 0.5f, Random.Range(-95f, 95f));
TextMeshPro textMeshPro = gameObject.AddComponent<TextMeshPro>();
textMeshPro.fontSize = 96f;
textMeshPro.text = "!";
textMeshPro.color = new Color32(byte.MaxValue, byte.MaxValue, 0, byte.MaxValue);
floatingText_Script = gameObject.AddComponent<TextMeshProFloatingText>();
floatingText_Script.SpawnType = 0;
}
else
{
GameObject gameObject2 = new GameObject();
gameObject2.transform.position = new Vector3(Random.Range(-95f, 95f), 0.5f, Random.Range(-95f, 95f));
TextMesh textMesh = gameObject2.AddComponent<TextMesh>();
textMesh.GetComponent<Renderer>().sharedMaterial = TheFont.material;
textMesh.font = TheFont;
textMesh.anchor = TextAnchor.LowerCenter;
textMesh.fontSize = 96;
textMesh.color = new Color32(byte.MaxValue, byte.MaxValue, 0, byte.MaxValue);
textMesh.text = "!";
floatingText_Script = gameObject2.AddComponent<TextMeshProFloatingText>();
floatingText_Script.SpawnType = 1;
}
}
}
}
}
@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 53fcee8fb819807aa678e32685ac3630
timeCreated: 1754265943
licenseType: Free
MonoImporter:
serializedVersion: 2
externalObjects: {}
defaultReferences: []
executionOrder: 0
icon: {fileID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,47 @@
using System.Collections;
using UnityEngine;
namespace TMPro.Examples
{
public class VertexColorCycler : MonoBehaviour
{
private TMP_Text m_TextComponent;
private void Awake()
{
m_TextComponent = GetComponent<TMP_Text>();
}
private void Start()
{
StartCoroutine(AnimateVertexColors());
}
private IEnumerator AnimateVertexColors()
{
m_TextComponent.ForceMeshUpdate();
TMP_TextInfo textInfo = m_TextComponent.textInfo;
int currentCharacter = 0;
_ = (Color32)m_TextComponent.color;
while (true)
{
int characterCount = textInfo.characterCount;
if (characterCount == 0)
{
yield return new WaitForSeconds(0.25f);
continue;
}
int materialReferenceIndex = textInfo.characterInfo[currentCharacter].materialReferenceIndex;
Color32[] colors = textInfo.meshInfo[materialReferenceIndex].colors32;
int vertexIndex = textInfo.characterInfo[currentCharacter].vertexIndex;
if (textInfo.characterInfo[currentCharacter].isVisible)
{
colors[vertexIndex + 3] = (colors[vertexIndex + 2] = (colors[vertexIndex + 1] = (colors[vertexIndex] = new Color32((byte)Random.Range(0, 255), (byte)Random.Range(0, 255), (byte)Random.Range(0, 255), byte.MaxValue))));
m_TextComponent.UpdateVertexData(TMP_VertexDataUpdateFlags.Colors32);
}
currentCharacter = (currentCharacter + 1) % characterCount;
yield return new WaitForSeconds(0.05f);
}
}
}
}
@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: f15a49c655e724fde939390b55b5dd92
timeCreated: 1754265943
licenseType: Free
MonoImporter:
serializedVersion: 2
externalObjects: {}
defaultReferences: []
executionOrder: 0
icon: {fileID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,118 @@
using System.Collections;
using UnityEngine;
namespace TMPro.Examples
{
public class VertexJitter : MonoBehaviour
{
private struct VertexAnim
{
public float angleRange;
public float angle;
public float speed;
}
public float AngleMultiplier = 1f;
public float SpeedMultiplier = 1f;
public float CurveScale = 1f;
private TMP_Text m_TextComponent;
private bool hasTextChanged;
private void Awake()
{
m_TextComponent = GetComponent<TMP_Text>();
}
private void OnEnable()
{
TMPro_EventManager.TEXT_CHANGED_EVENT.Add(ON_TEXT_CHANGED);
}
private void OnDisable()
{
TMPro_EventManager.TEXT_CHANGED_EVENT.Remove(ON_TEXT_CHANGED);
}
private void Start()
{
StartCoroutine(AnimateVertexColors());
}
private void ON_TEXT_CHANGED(Object obj)
{
if (obj == m_TextComponent)
{
hasTextChanged = true;
}
}
private IEnumerator AnimateVertexColors()
{
m_TextComponent.ForceMeshUpdate();
TMP_TextInfo textInfo = m_TextComponent.textInfo;
int loopCount = 0;
hasTextChanged = true;
VertexAnim[] vertexAnim = new VertexAnim[1024];
for (int i = 0; i < 1024; i++)
{
vertexAnim[i].angleRange = Random.Range(10f, 25f);
vertexAnim[i].speed = Random.Range(1f, 3f);
}
TMP_MeshInfo[] cachedMeshInfo = textInfo.CopyMeshInfoVertexData();
while (true)
{
if (hasTextChanged)
{
cachedMeshInfo = textInfo.CopyMeshInfoVertexData();
hasTextChanged = false;
}
int characterCount = textInfo.characterCount;
if (characterCount == 0)
{
yield return new WaitForSeconds(0.25f);
continue;
}
for (int j = 0; j < characterCount; j++)
{
if (textInfo.characterInfo[j].isVisible)
{
VertexAnim vertexAnim2 = vertexAnim[j];
int materialReferenceIndex = textInfo.characterInfo[j].materialReferenceIndex;
int vertexIndex = textInfo.characterInfo[j].vertexIndex;
Vector3[] vertices = cachedMeshInfo[materialReferenceIndex].vertices;
Vector3 vector = (Vector2)((vertices[vertexIndex] + vertices[vertexIndex + 2]) / 2f);
Vector3[] vertices2 = textInfo.meshInfo[materialReferenceIndex].vertices;
vertices2[vertexIndex] = vertices[vertexIndex] - vector;
vertices2[vertexIndex + 1] = vertices[vertexIndex + 1] - vector;
vertices2[vertexIndex + 2] = vertices[vertexIndex + 2] - vector;
vertices2[vertexIndex + 3] = vertices[vertexIndex + 3] - vector;
vertexAnim2.angle = Mathf.SmoothStep(0f - vertexAnim2.angleRange, vertexAnim2.angleRange, Mathf.PingPong((float)loopCount / 25f * vertexAnim2.speed, 1f));
Matrix4x4 matrix4x = Matrix4x4.TRS(new Vector3(Random.Range(-0.25f, 0.25f), Random.Range(-0.25f, 0.25f), 0f) * CurveScale, Quaternion.Euler(0f, 0f, Random.Range(-5f, 5f) * AngleMultiplier), Vector3.one);
vertices2[vertexIndex] = matrix4x.MultiplyPoint3x4(vertices2[vertexIndex]);
vertices2[vertexIndex + 1] = matrix4x.MultiplyPoint3x4(vertices2[vertexIndex + 1]);
vertices2[vertexIndex + 2] = matrix4x.MultiplyPoint3x4(vertices2[vertexIndex + 2]);
vertices2[vertexIndex + 3] = matrix4x.MultiplyPoint3x4(vertices2[vertexIndex + 3]);
vertices2[vertexIndex] += vector;
vertices2[vertexIndex + 1] += vector;
vertices2[vertexIndex + 2] += vector;
vertices2[vertexIndex + 3] += vector;
vertexAnim[j] = vertexAnim2;
}
}
for (int k = 0; k < textInfo.meshInfo.Length; k++)
{
textInfo.meshInfo[k].mesh.vertices = textInfo.meshInfo[k].vertices;
m_TextComponent.UpdateGeometry(textInfo.meshInfo[k].mesh, k);
}
loopCount++;
yield return new WaitForSeconds(0.1f);
}
}
}
}
@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 2bae53bce5ebb1df3e08cbf70e12e1da
timeCreated: 1754265943
licenseType: Free
MonoImporter:
serializedVersion: 2
externalObjects: {}
defaultReferences: []
executionOrder: 0
icon: {fileID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,114 @@
using System.Collections;
using UnityEngine;
namespace TMPro.Examples
{
public class VertexShakeA : MonoBehaviour
{
public float AngleMultiplier = 1f;
public float SpeedMultiplier = 1f;
public float ScaleMultiplier = 1f;
public float RotationMultiplier = 1f;
private TMP_Text m_TextComponent;
private bool hasTextChanged;
private void Awake()
{
m_TextComponent = GetComponent<TMP_Text>();
}
private void OnEnable()
{
TMPro_EventManager.TEXT_CHANGED_EVENT.Add(ON_TEXT_CHANGED);
}
private void OnDisable()
{
TMPro_EventManager.TEXT_CHANGED_EVENT.Remove(ON_TEXT_CHANGED);
}
private void Start()
{
StartCoroutine(AnimateVertexColors());
}
private void ON_TEXT_CHANGED(Object obj)
{
if ((bool)(obj = m_TextComponent))
{
hasTextChanged = true;
}
}
private IEnumerator AnimateVertexColors()
{
m_TextComponent.ForceMeshUpdate();
TMP_TextInfo textInfo = m_TextComponent.textInfo;
Vector3[][] copyOfVertices = new Vector3[0][];
hasTextChanged = true;
while (true)
{
if (hasTextChanged)
{
if (copyOfVertices.Length < textInfo.meshInfo.Length)
{
copyOfVertices = new Vector3[textInfo.meshInfo.Length][];
}
for (int i = 0; i < textInfo.meshInfo.Length; i++)
{
int num = textInfo.meshInfo[i].vertices.Length;
copyOfVertices[i] = new Vector3[num];
}
hasTextChanged = false;
}
if (textInfo.characterCount == 0)
{
yield return new WaitForSeconds(0.25f);
continue;
}
int lineCount = textInfo.lineCount;
for (int j = 0; j < lineCount; j++)
{
int firstCharacterIndex = textInfo.lineInfo[j].firstCharacterIndex;
int lastCharacterIndex = textInfo.lineInfo[j].lastCharacterIndex;
Vector3 vector = (textInfo.characterInfo[firstCharacterIndex].bottomLeft + textInfo.characterInfo[lastCharacterIndex].topRight) / 2f;
Quaternion q = Quaternion.Euler(0f, 0f, Random.Range(-0.25f, 0.25f) * RotationMultiplier);
for (int k = firstCharacterIndex; k <= lastCharacterIndex; k++)
{
if (textInfo.characterInfo[k].isVisible)
{
int materialReferenceIndex = textInfo.characterInfo[k].materialReferenceIndex;
int vertexIndex = textInfo.characterInfo[k].vertexIndex;
Vector3[] vertices = textInfo.meshInfo[materialReferenceIndex].vertices;
copyOfVertices[materialReferenceIndex][vertexIndex] = vertices[vertexIndex] - vector;
copyOfVertices[materialReferenceIndex][vertexIndex + 1] = vertices[vertexIndex + 1] - vector;
copyOfVertices[materialReferenceIndex][vertexIndex + 2] = vertices[vertexIndex + 2] - vector;
copyOfVertices[materialReferenceIndex][vertexIndex + 3] = vertices[vertexIndex + 3] - vector;
float num2 = Random.Range(0.995f - 0.001f * ScaleMultiplier, 1.005f + 0.001f * ScaleMultiplier);
Matrix4x4 matrix4x = Matrix4x4.TRS(Vector3.one, q, Vector3.one * num2);
copyOfVertices[materialReferenceIndex][vertexIndex] = matrix4x.MultiplyPoint3x4(copyOfVertices[materialReferenceIndex][vertexIndex]);
copyOfVertices[materialReferenceIndex][vertexIndex + 1] = matrix4x.MultiplyPoint3x4(copyOfVertices[materialReferenceIndex][vertexIndex + 1]);
copyOfVertices[materialReferenceIndex][vertexIndex + 2] = matrix4x.MultiplyPoint3x4(copyOfVertices[materialReferenceIndex][vertexIndex + 2]);
copyOfVertices[materialReferenceIndex][vertexIndex + 3] = matrix4x.MultiplyPoint3x4(copyOfVertices[materialReferenceIndex][vertexIndex + 3]);
copyOfVertices[materialReferenceIndex][vertexIndex] += vector;
copyOfVertices[materialReferenceIndex][vertexIndex + 1] += vector;
copyOfVertices[materialReferenceIndex][vertexIndex + 2] += vector;
copyOfVertices[materialReferenceIndex][vertexIndex + 3] += vector;
}
}
}
for (int l = 0; l < textInfo.meshInfo.Length; l++)
{
textInfo.meshInfo[l].mesh.vertices = copyOfVertices[l];
m_TextComponent.UpdateGeometry(textInfo.meshInfo[l].mesh, l);
}
yield return new WaitForSeconds(0.1f);
}
}
}
}
@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 6fc005c7e23ff6c2592fcc6544ac9c8a
timeCreated: 1754265943
licenseType: Free
MonoImporter:
serializedVersion: 2
externalObjects: {}
defaultReferences: []
executionOrder: 0
icon: {fileID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,126 @@
using System.Collections;
using UnityEngine;
namespace TMPro.Examples
{
public class VertexShakeB : MonoBehaviour
{
public float AngleMultiplier = 1f;
public float SpeedMultiplier = 1f;
public float CurveScale = 1f;
private TMP_Text m_TextComponent;
private bool hasTextChanged;
private void Awake()
{
m_TextComponent = GetComponent<TMP_Text>();
}
private void OnEnable()
{
TMPro_EventManager.TEXT_CHANGED_EVENT.Add(ON_TEXT_CHANGED);
}
private void OnDisable()
{
TMPro_EventManager.TEXT_CHANGED_EVENT.Remove(ON_TEXT_CHANGED);
}
private void Start()
{
StartCoroutine(AnimateVertexColors());
}
private void ON_TEXT_CHANGED(Object obj)
{
if ((bool)(obj = m_TextComponent))
{
hasTextChanged = true;
}
}
private IEnumerator AnimateVertexColors()
{
m_TextComponent.ForceMeshUpdate();
TMP_TextInfo textInfo = m_TextComponent.textInfo;
Vector3[][] copyOfVertices = new Vector3[0][];
hasTextChanged = true;
while (true)
{
if (hasTextChanged)
{
if (copyOfVertices.Length < textInfo.meshInfo.Length)
{
copyOfVertices = new Vector3[textInfo.meshInfo.Length][];
}
for (int i = 0; i < textInfo.meshInfo.Length; i++)
{
int num = textInfo.meshInfo[i].vertices.Length;
copyOfVertices[i] = new Vector3[num];
}
hasTextChanged = false;
}
if (textInfo.characterCount == 0)
{
yield return new WaitForSeconds(0.25f);
continue;
}
int lineCount = textInfo.lineCount;
for (int j = 0; j < lineCount; j++)
{
int firstCharacterIndex = textInfo.lineInfo[j].firstCharacterIndex;
int lastCharacterIndex = textInfo.lineInfo[j].lastCharacterIndex;
Vector3 vector = (textInfo.characterInfo[firstCharacterIndex].bottomLeft + textInfo.characterInfo[lastCharacterIndex].topRight) / 2f;
Quaternion q = Quaternion.Euler(0f, 0f, Random.Range(-0.25f, 0.25f));
for (int k = firstCharacterIndex; k <= lastCharacterIndex; k++)
{
if (textInfo.characterInfo[k].isVisible)
{
int materialReferenceIndex = textInfo.characterInfo[k].materialReferenceIndex;
int vertexIndex = textInfo.characterInfo[k].vertexIndex;
Vector3[] vertices = textInfo.meshInfo[materialReferenceIndex].vertices;
Vector3 vector2 = (vertices[vertexIndex] + vertices[vertexIndex + 2]) / 2f;
copyOfVertices[materialReferenceIndex][vertexIndex] = vertices[vertexIndex] - vector2;
copyOfVertices[materialReferenceIndex][vertexIndex + 1] = vertices[vertexIndex + 1] - vector2;
copyOfVertices[materialReferenceIndex][vertexIndex + 2] = vertices[vertexIndex + 2] - vector2;
copyOfVertices[materialReferenceIndex][vertexIndex + 3] = vertices[vertexIndex + 3] - vector2;
float num2 = Random.Range(0.95f, 1.05f);
Matrix4x4 matrix4x = Matrix4x4.TRS(Vector3.one, Quaternion.identity, Vector3.one * num2);
copyOfVertices[materialReferenceIndex][vertexIndex] = matrix4x.MultiplyPoint3x4(copyOfVertices[materialReferenceIndex][vertexIndex]);
copyOfVertices[materialReferenceIndex][vertexIndex + 1] = matrix4x.MultiplyPoint3x4(copyOfVertices[materialReferenceIndex][vertexIndex + 1]);
copyOfVertices[materialReferenceIndex][vertexIndex + 2] = matrix4x.MultiplyPoint3x4(copyOfVertices[materialReferenceIndex][vertexIndex + 2]);
copyOfVertices[materialReferenceIndex][vertexIndex + 3] = matrix4x.MultiplyPoint3x4(copyOfVertices[materialReferenceIndex][vertexIndex + 3]);
copyOfVertices[materialReferenceIndex][vertexIndex] += vector2;
copyOfVertices[materialReferenceIndex][vertexIndex + 1] += vector2;
copyOfVertices[materialReferenceIndex][vertexIndex + 2] += vector2;
copyOfVertices[materialReferenceIndex][vertexIndex + 3] += vector2;
copyOfVertices[materialReferenceIndex][vertexIndex] -= vector;
copyOfVertices[materialReferenceIndex][vertexIndex + 1] -= vector;
copyOfVertices[materialReferenceIndex][vertexIndex + 2] -= vector;
copyOfVertices[materialReferenceIndex][vertexIndex + 3] -= vector;
matrix4x = Matrix4x4.TRS(Vector3.one, q, Vector3.one);
copyOfVertices[materialReferenceIndex][vertexIndex] = matrix4x.MultiplyPoint3x4(copyOfVertices[materialReferenceIndex][vertexIndex]);
copyOfVertices[materialReferenceIndex][vertexIndex + 1] = matrix4x.MultiplyPoint3x4(copyOfVertices[materialReferenceIndex][vertexIndex + 1]);
copyOfVertices[materialReferenceIndex][vertexIndex + 2] = matrix4x.MultiplyPoint3x4(copyOfVertices[materialReferenceIndex][vertexIndex + 2]);
copyOfVertices[materialReferenceIndex][vertexIndex + 3] = matrix4x.MultiplyPoint3x4(copyOfVertices[materialReferenceIndex][vertexIndex + 3]);
copyOfVertices[materialReferenceIndex][vertexIndex] += vector;
copyOfVertices[materialReferenceIndex][vertexIndex + 1] += vector;
copyOfVertices[materialReferenceIndex][vertexIndex + 2] += vector;
copyOfVertices[materialReferenceIndex][vertexIndex + 3] += vector;
}
}
}
for (int l = 0; l < textInfo.meshInfo.Length; l++)
{
textInfo.meshInfo[l].mesh.vertices = copyOfVertices[l];
m_TextComponent.UpdateGeometry(textInfo.meshInfo[l].mesh, l);
}
yield return new WaitForSeconds(0.1f);
}
}
}
}
@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: e7b927fab84054fe0ef0f4c6efbe00b1
timeCreated: 1754265943
licenseType: Free
MonoImporter:
serializedVersion: 2
externalObjects: {}
defaultReferences: []
executionOrder: 0
icon: {fileID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,122 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace TMPro.Examples
{
public class VertexZoom : MonoBehaviour
{
public float AngleMultiplier = 1f;
public float SpeedMultiplier = 1f;
public float CurveScale = 1f;
private TMP_Text m_TextComponent;
private bool hasTextChanged;
private void Awake()
{
m_TextComponent = GetComponent<TMP_Text>();
}
private void OnEnable()
{
TMPro_EventManager.TEXT_CHANGED_EVENT.Add(ON_TEXT_CHANGED);
}
private void OnDisable()
{
TMPro_EventManager.TEXT_CHANGED_EVENT.Remove(ON_TEXT_CHANGED);
}
private void Start()
{
StartCoroutine(AnimateVertexColors());
}
private void ON_TEXT_CHANGED(Object obj)
{
if (obj == m_TextComponent)
{
hasTextChanged = true;
}
}
private IEnumerator AnimateVertexColors()
{
m_TextComponent.ForceMeshUpdate();
TMP_TextInfo textInfo = m_TextComponent.textInfo;
TMP_MeshInfo[] cachedMeshInfoVertexData = textInfo.CopyMeshInfoVertexData();
List<float> modifiedCharScale = new List<float>();
List<int> scaleSortingOrder = new List<int>();
hasTextChanged = true;
while (true)
{
if (hasTextChanged)
{
cachedMeshInfoVertexData = textInfo.CopyMeshInfoVertexData();
hasTextChanged = false;
}
int characterCount = textInfo.characterCount;
if (characterCount == 0)
{
yield return new WaitForSeconds(0.25f);
continue;
}
modifiedCharScale.Clear();
scaleSortingOrder.Clear();
for (int i = 0; i < characterCount; i++)
{
if (textInfo.characterInfo[i].isVisible)
{
int materialReferenceIndex = textInfo.characterInfo[i].materialReferenceIndex;
int vertexIndex = textInfo.characterInfo[i].vertexIndex;
Vector3[] vertices = cachedMeshInfoVertexData[materialReferenceIndex].vertices;
Vector3 vector = (Vector2)((vertices[vertexIndex] + vertices[vertexIndex + 2]) / 2f);
Vector3[] vertices2 = textInfo.meshInfo[materialReferenceIndex].vertices;
vertices2[vertexIndex] = vertices[vertexIndex] - vector;
vertices2[vertexIndex + 1] = vertices[vertexIndex + 1] - vector;
vertices2[vertexIndex + 2] = vertices[vertexIndex + 2] - vector;
vertices2[vertexIndex + 3] = vertices[vertexIndex + 3] - vector;
float num = Random.Range(1f, 1.5f);
modifiedCharScale.Add(num);
scaleSortingOrder.Add(modifiedCharScale.Count - 1);
Matrix4x4 matrix4x = Matrix4x4.TRS(new Vector3(0f, 0f, 0f), Quaternion.identity, Vector3.one * num);
vertices2[vertexIndex] = matrix4x.MultiplyPoint3x4(vertices2[vertexIndex]);
vertices2[vertexIndex + 1] = matrix4x.MultiplyPoint3x4(vertices2[vertexIndex + 1]);
vertices2[vertexIndex + 2] = matrix4x.MultiplyPoint3x4(vertices2[vertexIndex + 2]);
vertices2[vertexIndex + 3] = matrix4x.MultiplyPoint3x4(vertices2[vertexIndex + 3]);
vertices2[vertexIndex] += vector;
vertices2[vertexIndex + 1] += vector;
vertices2[vertexIndex + 2] += vector;
vertices2[vertexIndex + 3] += vector;
Vector2[] uvs = cachedMeshInfoVertexData[materialReferenceIndex].uvs0;
Vector2[] uvs2 = textInfo.meshInfo[materialReferenceIndex].uvs0;
uvs2[vertexIndex] = uvs[vertexIndex];
uvs2[vertexIndex + 1] = uvs[vertexIndex + 1];
uvs2[vertexIndex + 2] = uvs[vertexIndex + 2];
uvs2[vertexIndex + 3] = uvs[vertexIndex + 3];
Color32[] colors = cachedMeshInfoVertexData[materialReferenceIndex].colors32;
Color32[] colors2 = textInfo.meshInfo[materialReferenceIndex].colors32;
colors2[vertexIndex] = colors[vertexIndex];
colors2[vertexIndex + 1] = colors[vertexIndex + 1];
colors2[vertexIndex + 2] = colors[vertexIndex + 2];
colors2[vertexIndex + 3] = colors[vertexIndex + 3];
}
}
for (int j = 0; j < textInfo.meshInfo.Length; j++)
{
scaleSortingOrder.Sort((int a, int b) => modifiedCharScale[a].CompareTo(modifiedCharScale[b]));
textInfo.meshInfo[j].SortGeometry(scaleSortingOrder);
textInfo.meshInfo[j].mesh.vertices = textInfo.meshInfo[j].vertices;
textInfo.meshInfo[j].mesh.uv = textInfo.meshInfo[j].uvs0;
textInfo.meshInfo[j].mesh.colors32 = textInfo.meshInfo[j].colors32;
m_TextComponent.UpdateGeometry(textInfo.meshInfo[j].mesh, j);
}
yield return new WaitForSeconds(0.1f);
}
}
}
}
@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: fbfbeba88a7f8386c1e84804ac5497e2
timeCreated: 1754265943
licenseType: Free
MonoImporter:
serializedVersion: 2
externalObjects: {}
defaultReferences: []
executionOrder: 0
icon: {fileID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,98 @@
using System.Collections;
using UnityEngine;
namespace TMPro.Examples
{
public class WarpTextExample : MonoBehaviour
{
private TMP_Text m_TextComponent;
public AnimationCurve VertexCurve = new AnimationCurve(new Keyframe(0f, 0f), new Keyframe(0.25f, 2f), new Keyframe(0.5f, 0f), new Keyframe(0.75f, 2f), new Keyframe(1f, 0f));
public float AngleMultiplier = 1f;
public float SpeedMultiplier = 1f;
public float CurveScale = 1f;
private void Awake()
{
m_TextComponent = base.gameObject.GetComponent<TMP_Text>();
}
private void Start()
{
StartCoroutine(WarpText());
}
private AnimationCurve CopyAnimationCurve(AnimationCurve curve)
{
return new AnimationCurve
{
keys = curve.keys
};
}
private IEnumerator WarpText()
{
VertexCurve.preWrapMode = WrapMode.Once;
VertexCurve.postWrapMode = WrapMode.Once;
m_TextComponent.havePropertiesChanged = true;
CurveScale *= 10f;
float old_CurveScale = CurveScale;
AnimationCurve old_curve = CopyAnimationCurve(VertexCurve);
while (true)
{
if (!m_TextComponent.havePropertiesChanged && old_CurveScale == CurveScale && old_curve.keys[1].value == VertexCurve.keys[1].value)
{
yield return null;
continue;
}
old_CurveScale = CurveScale;
old_curve = CopyAnimationCurve(VertexCurve);
m_TextComponent.ForceMeshUpdate();
TMP_TextInfo textInfo = m_TextComponent.textInfo;
int characterCount = textInfo.characterCount;
if (characterCount == 0)
{
continue;
}
float x = m_TextComponent.bounds.min.x;
float x2 = m_TextComponent.bounds.max.x;
for (int i = 0; i < characterCount; i++)
{
if (textInfo.characterInfo[i].isVisible)
{
int vertexIndex = textInfo.characterInfo[i].vertexIndex;
int materialReferenceIndex = textInfo.characterInfo[i].materialReferenceIndex;
Vector3[] vertices = textInfo.meshInfo[materialReferenceIndex].vertices;
Vector3 vector = new Vector2((vertices[vertexIndex].x + vertices[vertexIndex + 2].x) / 2f, textInfo.characterInfo[i].baseLine);
vertices[vertexIndex] += -vector;
vertices[vertexIndex + 1] += -vector;
vertices[vertexIndex + 2] += -vector;
vertices[vertexIndex + 3] += -vector;
float num = (vector.x - x) / (x2 - x);
float num2 = num + 0.0001f;
float y = VertexCurve.Evaluate(num) * CurveScale;
float y2 = VertexCurve.Evaluate(num2) * CurveScale;
Vector3 lhs = new Vector3(1f, 0f, 0f);
Vector3 rhs = new Vector3(num2 * (x2 - x) + x, y2) - new Vector3(vector.x, y);
float num3 = Mathf.Acos(Vector3.Dot(lhs, rhs.normalized)) * 57.29578f;
float z = ((Vector3.Cross(lhs, rhs).z > 0f) ? num3 : (360f - num3));
Matrix4x4 matrix4x = Matrix4x4.TRS(new Vector3(0f, y, 0f), Quaternion.Euler(0f, 0f, z), Vector3.one);
vertices[vertexIndex] = matrix4x.MultiplyPoint3x4(vertices[vertexIndex]);
vertices[vertexIndex + 1] = matrix4x.MultiplyPoint3x4(vertices[vertexIndex + 1]);
vertices[vertexIndex + 2] = matrix4x.MultiplyPoint3x4(vertices[vertexIndex + 2]);
vertices[vertexIndex + 3] = matrix4x.MultiplyPoint3x4(vertices[vertexIndex + 3]);
vertices[vertexIndex] += vector;
vertices[vertexIndex + 1] += vector;
vertices[vertexIndex + 2] += vector;
vertices[vertexIndex + 3] += vector;
}
}
m_TextComponent.UpdateVertexData();
yield return new WaitForSeconds(0.025f);
}
}
}
}
@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 7cd06716c7951d3df214b96b05d6b44c
timeCreated: 1754265943
licenseType: Free
MonoImporter:
serializedVersion: 2
externalObjects: {}
defaultReferences: []
executionOrder: 0
icon: {fileID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,19 @@
using System;
namespace TMPro
{
[Serializable]
public class TMP_DigitValidator : TMP_InputValidator
{
public override char Validate(ref string text, ref int pos, char ch)
{
if (ch >= '0' && ch <= '9')
{
text += ch;
pos++;
return ch;
}
return '\0';
}
}
}
@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: e4ffb2f7ab803735689198c4bee849c6
timeCreated: 1754265943
licenseType: Free
MonoImporter:
serializedVersion: 2
externalObjects: {}
defaultReferences: []
executionOrder: 0
icon: {fileID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,124 @@
using System;
using UnityEngine;
namespace TMPro
{
[Serializable]
public class TMP_PhoneNumberValidator : TMP_InputValidator
{
public override char Validate(ref string text, ref int pos, char ch)
{
Debug.Log("Trying to validate...");
if (ch < '0' && ch > '9')
{
return '\0';
}
int length = text.Length;
for (int i = 0; i < length + 1; i++)
{
switch (i)
{
case 0:
if (i == length)
{
text = "(" + ch;
}
pos = 2;
break;
case 1:
if (i == length)
{
text += ch;
}
pos = 2;
break;
case 2:
if (i == length)
{
text += ch;
}
pos = 3;
break;
case 3:
if (i == length)
{
text = text + ch + ") ";
}
pos = 6;
break;
case 4:
if (i == length)
{
text = text + ") " + ch;
}
pos = 7;
break;
case 5:
if (i == length)
{
text = text + " " + ch;
}
pos = 7;
break;
case 6:
if (i == length)
{
text += ch;
}
pos = 7;
break;
case 7:
if (i == length)
{
text += ch;
}
pos = 8;
break;
case 8:
if (i == length)
{
text = text + ch + "-";
}
pos = 10;
break;
case 9:
if (i == length)
{
text = text + "-" + ch;
}
pos = 11;
break;
case 10:
if (i == length)
{
text += ch;
}
pos = 11;
break;
case 11:
if (i == length)
{
text += ch;
}
pos = 12;
break;
case 12:
if (i == length)
{
text += ch;
}
pos = 13;
break;
case 13:
if (i == length)
{
text += ch;
}
pos = 14;
break;
}
}
return ch;
}
}
}
@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: ef463a078c3091e4533b2fbdcc487a4f
timeCreated: 1754265943
licenseType: Free
MonoImporter:
serializedVersion: 2
externalObjects: {}
defaultReferences: []
executionOrder: 0
icon: {fileID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,251 @@
using System;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
namespace TMPro
{
public class TMP_TextEventHandler : MonoBehaviour, IPointerEnterHandler, IEventSystemHandler, IPointerExitHandler
{
[Serializable]
public class CharacterSelectionEvent : UnityEvent<char, int>
{
}
[Serializable]
public class SpriteSelectionEvent : UnityEvent<char, int>
{
}
[Serializable]
public class WordSelectionEvent : UnityEvent<string, int, int>
{
}
[Serializable]
public class LineSelectionEvent : UnityEvent<string, int, int>
{
}
[Serializable]
public class LinkSelectionEvent : UnityEvent<string, string, int>
{
}
[SerializeField]
private CharacterSelectionEvent m_OnCharacterSelection = new CharacterSelectionEvent();
[SerializeField]
private SpriteSelectionEvent m_OnSpriteSelection = new SpriteSelectionEvent();
[SerializeField]
private WordSelectionEvent m_OnWordSelection = new WordSelectionEvent();
[SerializeField]
private LineSelectionEvent m_OnLineSelection = new LineSelectionEvent();
[SerializeField]
private LinkSelectionEvent m_OnLinkSelection = new LinkSelectionEvent();
private TMP_Text m_TextComponent;
private Camera m_Camera;
private Canvas m_Canvas;
private int m_selectedLink = -1;
private int m_lastCharIndex = -1;
private int m_lastWordIndex = -1;
private int m_lastLineIndex = -1;
public CharacterSelectionEvent onCharacterSelection
{
get
{
return m_OnCharacterSelection;
}
set
{
m_OnCharacterSelection = value;
}
}
public SpriteSelectionEvent onSpriteSelection
{
get
{
return m_OnSpriteSelection;
}
set
{
m_OnSpriteSelection = value;
}
}
public WordSelectionEvent onWordSelection
{
get
{
return m_OnWordSelection;
}
set
{
m_OnWordSelection = value;
}
}
public LineSelectionEvent onLineSelection
{
get
{
return m_OnLineSelection;
}
set
{
m_OnLineSelection = value;
}
}
public LinkSelectionEvent onLinkSelection
{
get
{
return m_OnLinkSelection;
}
set
{
m_OnLinkSelection = value;
}
}
private void Awake()
{
m_TextComponent = base.gameObject.GetComponent<TMP_Text>();
if (m_TextComponent.GetType() == typeof(TextMeshProUGUI))
{
m_Canvas = base.gameObject.GetComponentInParent<Canvas>();
if (m_Canvas != null)
{
if (m_Canvas.renderMode == RenderMode.ScreenSpaceOverlay)
{
m_Camera = null;
}
else
{
m_Camera = m_Canvas.worldCamera;
}
}
}
else
{
m_Camera = Camera.main;
}
}
private void LateUpdate()
{
if (TMP_TextUtilities.IsIntersectingRectTransform(m_TextComponent.rectTransform, Input.mousePosition, m_Camera))
{
int num = TMP_TextUtilities.FindIntersectingCharacter(m_TextComponent, Input.mousePosition, m_Camera, visibleOnly: true);
if (num != -1 && num != m_lastCharIndex)
{
m_lastCharIndex = num;
switch (m_TextComponent.textInfo.characterInfo[num].elementType)
{
case TMP_TextElementType.Character:
SendOnCharacterSelection(m_TextComponent.textInfo.characterInfo[num].character, num);
break;
case TMP_TextElementType.Sprite:
SendOnSpriteSelection(m_TextComponent.textInfo.characterInfo[num].character, num);
break;
}
}
int num2 = TMP_TextUtilities.FindIntersectingWord(m_TextComponent, Input.mousePosition, m_Camera);
if (num2 != -1 && num2 != m_lastWordIndex)
{
m_lastWordIndex = num2;
TMP_WordInfo tMP_WordInfo = m_TextComponent.textInfo.wordInfo[num2];
SendOnWordSelection(tMP_WordInfo.GetWord(), tMP_WordInfo.firstCharacterIndex, tMP_WordInfo.characterCount);
}
int num3 = TMP_TextUtilities.FindIntersectingLine(m_TextComponent, Input.mousePosition, m_Camera);
if (num3 != -1 && num3 != m_lastLineIndex)
{
m_lastLineIndex = num3;
TMP_LineInfo tMP_LineInfo = m_TextComponent.textInfo.lineInfo[num3];
char[] array = new char[tMP_LineInfo.characterCount];
for (int i = 0; i < tMP_LineInfo.characterCount && i < m_TextComponent.textInfo.characterInfo.Length; i++)
{
array[i] = m_TextComponent.textInfo.characterInfo[i + tMP_LineInfo.firstCharacterIndex].character;
}
string line = new string(array);
SendOnLineSelection(line, tMP_LineInfo.firstCharacterIndex, tMP_LineInfo.characterCount);
}
int num4 = TMP_TextUtilities.FindIntersectingLink(m_TextComponent, Input.mousePosition, m_Camera);
if (num4 != -1 && num4 != m_selectedLink)
{
m_selectedLink = num4;
TMP_LinkInfo tMP_LinkInfo = m_TextComponent.textInfo.linkInfo[num4];
SendOnLinkSelection(tMP_LinkInfo.GetLinkID(), tMP_LinkInfo.GetLinkText(), num4);
}
}
else
{
m_selectedLink = -1;
m_lastCharIndex = -1;
m_lastWordIndex = -1;
m_lastLineIndex = -1;
}
}
public void OnPointerEnter(PointerEventData eventData)
{
}
public void OnPointerExit(PointerEventData eventData)
{
}
private void SendOnCharacterSelection(char character, int characterIndex)
{
if (onCharacterSelection != null)
{
onCharacterSelection.Invoke(character, characterIndex);
}
}
private void SendOnSpriteSelection(char character, int characterIndex)
{
if (onSpriteSelection != null)
{
onSpriteSelection.Invoke(character, characterIndex);
}
}
private void SendOnWordSelection(string word, int charIndex, int length)
{
if (onWordSelection != null)
{
onWordSelection.Invoke(word, charIndex, length);
}
}
private void SendOnLineSelection(string line, int charIndex, int length)
{
if (onLineSelection != null)
{
onLineSelection.Invoke(line, charIndex, length);
}
}
private void SendOnLinkSelection(string linkID, string linkText, int linkIndex)
{
if (onLinkSelection != null)
{
onLinkSelection.Invoke(linkID, linkText, linkIndex);
}
}
}
}
@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 2744e1a639fc99f1ff213a39e8340251
timeCreated: 1754265943
licenseType: Free
MonoImporter:
serializedVersion: 2
externalObjects: {}
defaultReferences: []
executionOrder: 0
icon: {fileID: 0}
userData:
assetBundleName:
assetBundleVariant: