- using UnityEngine;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- namespace TMPro
- {
-
-
-
- [Serializable]
- public class TMP_TextInfo
- {
- internal static Vector2 k_InfinityVectorPositive = new Vector2(32767, 32767);
- internal static Vector2 k_InfinityVectorNegative = new Vector2(-32767, -32767);
- public TMP_Text textComponent;
- public int characterCount;
- public int spriteCount;
- public int spaceCount;
- public int wordCount;
- public int linkCount;
- public int lineCount;
- public int pageCount;
- public int materialCount;
- public TMP_CharacterInfo[] characterInfo;
- public TMP_WordInfo[] wordInfo;
- public TMP_LinkInfo[] linkInfo;
- public TMP_LineInfo[] lineInfo;
- public TMP_PageInfo[] pageInfo;
- public TMP_MeshInfo[] meshInfo;
- private TMP_MeshInfo[] m_CachedMeshInfo;
-
- public TMP_TextInfo()
- {
- characterInfo = new TMP_CharacterInfo[8];
- wordInfo = new TMP_WordInfo[16];
- linkInfo = new TMP_LinkInfo[0];
- lineInfo = new TMP_LineInfo[2];
- pageInfo = new TMP_PageInfo[4];
- meshInfo = new TMP_MeshInfo[1];
- }
- internal TMP_TextInfo(int characterCount)
- {
- characterInfo = new TMP_CharacterInfo[characterCount];
- wordInfo = new TMP_WordInfo[16];
- linkInfo = new TMP_LinkInfo[0];
- lineInfo = new TMP_LineInfo[2];
- pageInfo = new TMP_PageInfo[4];
- meshInfo = new TMP_MeshInfo[1];
- }
- public TMP_TextInfo(TMP_Text textComponent)
- {
- this.textComponent = textComponent;
- characterInfo = new TMP_CharacterInfo[8];
- wordInfo = new TMP_WordInfo[4];
- linkInfo = new TMP_LinkInfo[0];
- lineInfo = new TMP_LineInfo[2];
- pageInfo = new TMP_PageInfo[4];
- meshInfo = new TMP_MeshInfo[1];
- meshInfo[0].mesh = textComponent.mesh;
- materialCount = 1;
- }
-
-
-
- public void Clear()
- {
- characterCount = 0;
- spaceCount = 0;
- wordCount = 0;
- linkCount = 0;
- lineCount = 0;
- pageCount = 0;
- spriteCount = 0;
- for (int i = 0; i < this.meshInfo.Length; i++)
- {
- this.meshInfo[i].vertexCount = 0;
- }
- }
-
-
-
- internal void ClearAllData()
- {
- characterCount = 0;
- spaceCount = 0;
- wordCount = 0;
- linkCount = 0;
- lineCount = 0;
- pageCount = 0;
- spriteCount = 0;
- this.characterInfo = new TMP_CharacterInfo[4];
- this.wordInfo = new TMP_WordInfo[1];
- this.lineInfo = new TMP_LineInfo[1];
- this.pageInfo = new TMP_PageInfo[1];
- this.linkInfo = new TMP_LinkInfo[0];
- materialCount = 0;
- this.meshInfo = new TMP_MeshInfo[1];
- }
-
-
-
- public void ClearMeshInfo(bool updateMesh)
- {
- for (int i = 0; i < this.meshInfo.Length; i++)
- this.meshInfo[i].Clear(updateMesh);
- }
-
-
-
- public void ClearAllMeshInfo()
- {
- for (int i = 0; i < this.meshInfo.Length; i++)
- this.meshInfo[i].Clear(true);
- }
-
-
-
- public void ResetVertexLayout(bool isVolumetric)
- {
- for (int i = 0; i < this.meshInfo.Length; i++)
- this.meshInfo[i].ResizeMeshInfo(0, isVolumetric);
- }
-
-
-
-
- public void ClearUnusedVertices(MaterialReference[] materials)
- {
- for (int i = 0; i < meshInfo.Length; i++)
- {
- int start = 0;
- meshInfo[i].ClearUnusedVertices(start);
- }
- }
-
-
-
- public void ClearLineInfo()
- {
- if (this.lineInfo == null)
- this.lineInfo = new TMP_LineInfo[2];
- int length = this.lineInfo.Length;
- for (int i = 0; i < length; i++)
- {
- this.lineInfo[i].characterCount = 0;
- this.lineInfo[i].spaceCount = 0;
- this.lineInfo[i].wordCount = 0;
- this.lineInfo[i].controlCharacterCount = 0;
- this.lineInfo[i].width = 0;
- this.lineInfo[i].ascender = k_InfinityVectorNegative.x;
- this.lineInfo[i].descender = k_InfinityVectorPositive.x;
- this.lineInfo[i].marginLeft = 0;
- this.lineInfo[i].marginRight = 0;
- this.lineInfo[i].lineExtents.min = k_InfinityVectorPositive;
- this.lineInfo[i].lineExtents.max = k_InfinityVectorNegative;
- this.lineInfo[i].maxAdvance = 0;
-
- }
- }
- internal void ClearPageInfo()
- {
- if (this.pageInfo == null)
- this.pageInfo = new TMP_PageInfo[2];
- int length = this.pageInfo.Length;
- for (int i = 0; i < length; i++)
- {
- this.pageInfo[i].firstCharacterIndex = 0;
- this.pageInfo[i].lastCharacterIndex = 0;
- this.pageInfo[i].ascender = -32767;
- this.pageInfo[i].baseLine = 0;
- this.pageInfo[i].descender = 32767;
- }
- }
-
-
-
-
- public TMP_MeshInfo[] CopyMeshInfoVertexData()
- {
- if (m_CachedMeshInfo == null || m_CachedMeshInfo.Length != meshInfo.Length)
- {
- m_CachedMeshInfo = new TMP_MeshInfo[meshInfo.Length];
-
- for (int i = 0; i < m_CachedMeshInfo.Length; i++)
- {
- int length = meshInfo[i].vertices.Length;
- m_CachedMeshInfo[i].vertices = new Vector3[length];
- m_CachedMeshInfo[i].uvs0 = new Vector2[length];
- m_CachedMeshInfo[i].uvs2 = new Vector2[length];
- m_CachedMeshInfo[i].colors32 = new Color32[length];
-
-
-
- }
- }
- for (int i = 0; i < m_CachedMeshInfo.Length; i++)
- {
- int length = meshInfo[i].vertices.Length;
- if (m_CachedMeshInfo[i].vertices.Length != length)
- {
- m_CachedMeshInfo[i].vertices = new Vector3[length];
- m_CachedMeshInfo[i].uvs0 = new Vector2[length];
- m_CachedMeshInfo[i].uvs2 = new Vector2[length];
- m_CachedMeshInfo[i].colors32 = new Color32[length];
-
-
-
- }
-
- Array.Copy(meshInfo[i].vertices, m_CachedMeshInfo[i].vertices, length);
- Array.Copy(meshInfo[i].uvs0, m_CachedMeshInfo[i].uvs0, length);
- Array.Copy(meshInfo[i].uvs2, m_CachedMeshInfo[i].uvs2, length);
- Array.Copy(meshInfo[i].colors32, m_CachedMeshInfo[i].colors32, length);
-
-
-
- }
- return m_CachedMeshInfo;
- }
-
-
-
-
-
-
- public static void Resize<T> (ref T[] array, int size)
- {
-
- int newSize = size > 1024 ? size + 256 : Mathf.NextPowerOfTwo(size);
- Array.Resize(ref array, newSize);
- }
-
-
-
-
-
-
-
- public static void Resize<T>(ref T[] array, int size, bool isBlockAllocated)
- {
- if (isBlockAllocated) size = size > 1024 ? size + 256 : Mathf.NextPowerOfTwo(size);
- if (size == array.Length) return;
-
- Array.Resize(ref array, size);
- }
- }
- }