2 using System.Collections;
7 public enum CaretPosition { None, Left, Right }
15 public CaretPosition position;
17 public CaretInfo(
int index, CaretPosition position)
20 this.position = position;
24 public static class TMP_TextUtilities
26 private static Vector3[] m_rectWorldCorners =
new Vector3[4];
71 public static int GetCursorIndexFromPosition(
TMP_Text textComponent, Vector3 position, Camera camera)
73 int index = TMP_TextUtilities.FindNearestCharacter(textComponent, position, camera,
false);
78 ScreenPointToWorldPointInRectangle(rectTransform, position, camera, out position);
83 Vector3 bl = rectTransform.TransformPoint(cInfo.bottomLeft);
84 Vector3 tr = rectTransform.TransformPoint(cInfo.topRight);
86 float insertPosition = (position.x - bl.x) / (tr.x - bl.x);
88 if (insertPosition < 0.5f)
142 public static int GetCursorIndexFromPosition(TMP_Text textComponent, Vector3 position, Camera camera, out CaretPosition cursor)
144 int line = TMP_TextUtilities.FindNearestLine(textComponent, position, camera);
146 int index = FindNearestCharacterOnLine(textComponent, position, line, camera,
false);
149 if (textComponent.textInfo.lineInfo[line].characterCount == 1)
151 cursor = CaretPosition.Left;
155 RectTransform rectTransform = textComponent.rectTransform;
158 ScreenPointToWorldPointInRectangle(rectTransform, position, camera, out position);
160 TMP_CharacterInfo cInfo = textComponent.textInfo.characterInfo[index];
163 Vector3 bl = rectTransform.TransformPoint(cInfo.bottomLeft);
164 Vector3 tr = rectTransform.TransformPoint(cInfo.topRight);
166 float insertPosition = (position.x - bl.x) / (tr.x - bl.x);
168 if (insertPosition < 0.5f)
170 cursor = CaretPosition.Left;
175 cursor = CaretPosition.Right;
188 public static int FindNearestLine(TMP_Text text, Vector3 position, Camera camera)
190 RectTransform rectTransform = text.rectTransform;
192 float distance = Mathf.Infinity;
196 ScreenPointToWorldPointInRectangle(rectTransform, position, camera, out position);
198 for (
int i = 0; i < text.textInfo.lineCount; i++)
200 TMP_LineInfo lineInfo = text.textInfo.lineInfo[i];
202 float ascender = rectTransform.TransformPoint(
new Vector3(0, lineInfo.ascender, 0)).y;
203 float descender = rectTransform.TransformPoint(
new Vector3(0, lineInfo.descender, 0)).y;
205 if (ascender > position.y && descender < position.y)
211 float d0 = Mathf.Abs(ascender - position.y);
212 float d1 = Mathf.Abs(descender - position.y);
214 float d = Mathf.Min(d0, d1);
235 public static int FindNearestCharacterOnLine(TMP_Text text, Vector3 position,
int line, Camera camera,
bool visibleOnly)
237 RectTransform rectTransform = text.rectTransform;
240 ScreenPointToWorldPointInRectangle(rectTransform, position, camera, out position);
242 int firstCharacter = text.textInfo.lineInfo[line].firstCharacterIndex;
243 int lastCharacter = text.textInfo.lineInfo[line].lastCharacterIndex;
245 float distanceSqr = Mathf.Infinity;
246 int closest = lastCharacter;
248 for (
int i = firstCharacter; i < lastCharacter; i++)
251 TMP_CharacterInfo cInfo = text.textInfo.characterInfo[i];
252 if (visibleOnly && !cInfo.isVisible)
continue;
255 Vector3 bl = rectTransform.TransformPoint(cInfo.bottomLeft);
256 Vector3 tl = rectTransform.TransformPoint(
new Vector3(cInfo.bottomLeft.x, cInfo.topRight.y, 0));
257 Vector3 tr = rectTransform.TransformPoint(cInfo.topRight);
258 Vector3 br = rectTransform.TransformPoint(
new Vector3(cInfo.topRight.x, cInfo.bottomLeft.y, 0));
260 if (PointIntersectRectangle(position, bl, tl, tr, br))
267 float dbl = DistanceToLine(bl, tl, position);
268 float dtl = DistanceToLine(tl, tr, position);
269 float dtr = DistanceToLine(tr, br, position);
270 float dbr = DistanceToLine(br, bl, position);
272 float d = dbl < dtl ? dbl : dtl;
273 d = d < dtr ? d : dtr;
274 d = d < dbr ? d : dbr;
293 public static bool IsIntersectingRectTransform(RectTransform rectTransform, Vector3 position, Camera camera)
296 ScreenPointToWorldPointInRectangle(rectTransform, position, camera, out position);
298 rectTransform.GetWorldCorners(m_rectWorldCorners);
300 if (PointIntersectRectangle(position, m_rectWorldCorners[0], m_rectWorldCorners[1], m_rectWorldCorners[2], m_rectWorldCorners[3]))
319 public static int FindIntersectingCharacter(TMP_Text text, Vector3 position, Camera camera,
bool visibleOnly)
321 RectTransform rectTransform = text.rectTransform;
324 ScreenPointToWorldPointInRectangle(rectTransform, position, camera, out position);
326 for (
int i = 0; i < text.textInfo.characterCount; i++)
329 TMP_CharacterInfo cInfo = text.textInfo.characterInfo[i];
330 if (visibleOnly && !cInfo.isVisible)
continue;
333 Vector3 bl = rectTransform.TransformPoint(cInfo.bottomLeft);
334 Vector3 tl = rectTransform.TransformPoint(
new Vector3(cInfo.bottomLeft.x, cInfo.topRight.y, 0));
335 Vector3 tr = rectTransform.TransformPoint(cInfo.topRight);
336 Vector3 br = rectTransform.TransformPoint(
new Vector3(cInfo.topRight.x, cInfo.bottomLeft.y, 0));
338 if (PointIntersectRectangle(position, bl, tl, tr, br))
391 public static int FindNearestCharacter(TMP_Text text, Vector3 position, Camera camera,
bool visibleOnly)
393 RectTransform rectTransform = text.rectTransform;
395 float distanceSqr = Mathf.Infinity;
399 ScreenPointToWorldPointInRectangle(rectTransform, position, camera, out position);
401 for (
int i = 0; i < text.textInfo.characterCount; i++)
404 TMP_CharacterInfo cInfo = text.textInfo.characterInfo[i];
405 if (visibleOnly && !cInfo.isVisible)
continue;
408 Vector3 bl = rectTransform.TransformPoint(cInfo.bottomLeft);
409 Vector3 tl = rectTransform.TransformPoint(
new Vector3(cInfo.bottomLeft.x, cInfo.topRight.y, 0));
410 Vector3 tr = rectTransform.TransformPoint(cInfo.topRight);
411 Vector3 br = rectTransform.TransformPoint(
new Vector3(cInfo.topRight.x, cInfo.bottomLeft.y, 0));
413 if (PointIntersectRectangle(position, bl, tl, tr, br))
417 float dbl = DistanceToLine(bl, tl, position);
418 float dtl = DistanceToLine(tl, tr, position);
419 float dtr = DistanceToLine(tr, br, position);
420 float dbr = DistanceToLine(br, bl, position);
422 float d = dbl < dtl ? dbl : dtl;
423 d = d < dtr ? d : dtr;
424 d = d < dbr ? d : dbr;
559 public static int FindIntersectingWord(TMP_Text text, Vector3 position, Camera camera)
561 RectTransform rectTransform = text.rectTransform;
564 ScreenPointToWorldPointInRectangle(rectTransform, position, camera, out position);
566 for (
int i = 0; i < text.textInfo.wordCount; i++)
568 TMP_WordInfo wInfo = text.textInfo.wordInfo[i];
570 bool isBeginRegion =
false;
572 Vector3 bl = Vector3.zero;
573 Vector3 tl = Vector3.zero;
574 Vector3 br = Vector3.zero;
575 Vector3 tr = Vector3.zero;
577 float maxAscender = -Mathf.Infinity;
578 float minDescender = Mathf.Infinity;
581 for (
int j = 0; j < wInfo.characterCount; j++)
583 int characterIndex = wInfo.firstCharacterIndex + j;
584 TMP_CharacterInfo currentCharInfo = text.textInfo.characterInfo[characterIndex];
585 int currentLine = currentCharInfo.lineNumber;
587 bool isCharacterVisible = currentCharInfo.isVisible;
590 maxAscender = Mathf.Max(maxAscender, currentCharInfo.ascender);
591 minDescender = Mathf.Min(minDescender, currentCharInfo.descender);
593 if (isBeginRegion ==
false && isCharacterVisible)
595 isBeginRegion =
true;
597 bl =
new Vector3(currentCharInfo.bottomLeft.x, currentCharInfo.descender, 0);
598 tl =
new Vector3(currentCharInfo.bottomLeft.x, currentCharInfo.ascender, 0);
603 if (wInfo.characterCount == 1)
605 isBeginRegion =
false;
607 br =
new Vector3(currentCharInfo.topRight.x, currentCharInfo.descender, 0);
608 tr =
new Vector3(currentCharInfo.topRight.x, currentCharInfo.ascender, 0);
611 bl = rectTransform.TransformPoint(
new Vector3(bl.x, minDescender, 0));
612 tl = rectTransform.TransformPoint(
new Vector3(tl.x, maxAscender, 0));
613 tr = rectTransform.TransformPoint(
new Vector3(tr.x, maxAscender, 0));
614 br = rectTransform.TransformPoint(
new Vector3(br.x, minDescender, 0));
617 if (PointIntersectRectangle(position, bl, tl, tr, br))
625 if (isBeginRegion && j == wInfo.characterCount - 1)
627 isBeginRegion =
false;
629 br =
new Vector3(currentCharInfo.topRight.x, currentCharInfo.descender, 0);
630 tr =
new Vector3(currentCharInfo.topRight.x, currentCharInfo.ascender, 0);
633 bl = rectTransform.TransformPoint(
new Vector3(bl.x, minDescender, 0));
634 tl = rectTransform.TransformPoint(
new Vector3(tl.x, maxAscender, 0));
635 tr = rectTransform.TransformPoint(
new Vector3(tr.x, maxAscender, 0));
636 br = rectTransform.TransformPoint(
new Vector3(br.x, minDescender, 0));
639 if (PointIntersectRectangle(position, bl, tl, tr, br))
645 else if (isBeginRegion && currentLine != text.textInfo.characterInfo[characterIndex + 1].lineNumber)
647 isBeginRegion =
false;
649 br =
new Vector3(currentCharInfo.topRight.x, currentCharInfo.descender, 0);
650 tr =
new Vector3(currentCharInfo.topRight.x, currentCharInfo.ascender, 0);
653 bl = rectTransform.TransformPoint(
new Vector3(bl.x, minDescender, 0));
654 tl = rectTransform.TransformPoint(
new Vector3(tl.x, maxAscender, 0));
655 tr = rectTransform.TransformPoint(
new Vector3(tr.x, maxAscender, 0));
656 br = rectTransform.TransformPoint(
new Vector3(br.x, minDescender, 0));
658 maxAscender = -Mathf.Infinity;
659 minDescender = Mathf.Infinity;
662 if (PointIntersectRectangle(position, bl, tl, tr, br))
936 public static int FindNearestWord(TMP_Text text, Vector3 position, Camera camera)
938 RectTransform rectTransform = text.rectTransform;
940 float distanceSqr = Mathf.Infinity;
944 ScreenPointToWorldPointInRectangle(rectTransform, position, camera, out position);
946 for (
int i = 0; i < text.textInfo.wordCount; i++)
948 TMP_WordInfo wInfo = text.textInfo.wordInfo[i];
950 bool isBeginRegion =
false;
952 Vector3 bl = Vector3.zero;
953 Vector3 tl = Vector3.zero;
954 Vector3 br = Vector3.zero;
955 Vector3 tr = Vector3.zero;
958 for (
int j = 0; j < wInfo.characterCount; j++)
960 int characterIndex = wInfo.firstCharacterIndex + j;
961 TMP_CharacterInfo currentCharInfo = text.textInfo.characterInfo[characterIndex];
962 int currentLine = currentCharInfo.lineNumber;
964 bool isCharacterVisible = currentCharInfo.isVisible;
966 if (isBeginRegion ==
false && isCharacterVisible)
968 isBeginRegion =
true;
970 bl = rectTransform.TransformPoint(
new Vector3(currentCharInfo.bottomLeft.x, currentCharInfo.descender, 0));
971 tl = rectTransform.TransformPoint(
new Vector3(currentCharInfo.bottomLeft.x, currentCharInfo.ascender, 0));
976 if (wInfo.characterCount == 1)
978 isBeginRegion =
false;
980 br = rectTransform.TransformPoint(
new Vector3(currentCharInfo.topRight.x, currentCharInfo.descender, 0));
981 tr = rectTransform.TransformPoint(
new Vector3(currentCharInfo.topRight.x, currentCharInfo.ascender, 0));
984 if (PointIntersectRectangle(position, bl, tl, tr, br))
988 float dbl = DistanceToLine(bl, tl, position);
989 float dtl = DistanceToLine(tl, tr, position);
990 float dtr = DistanceToLine(tr, br, position);
991 float dbr = DistanceToLine(br, bl, position);
993 float d = dbl < dtl ? dbl : dtl;
994 d = d < dtr ? d : dtr;
995 d = d < dbr ? d : dbr;
1006 if (isBeginRegion && j == wInfo.characterCount - 1)
1008 isBeginRegion =
false;
1010 br = rectTransform.TransformPoint(
new Vector3(currentCharInfo.topRight.x, currentCharInfo.descender, 0));
1011 tr = rectTransform.TransformPoint(
new Vector3(currentCharInfo.topRight.x, currentCharInfo.ascender, 0));
1014 if (PointIntersectRectangle(position, bl, tl, tr, br))
1018 float dbl = DistanceToLine(bl, tl, position);
1019 float dtl = DistanceToLine(tl, tr, position);
1020 float dtr = DistanceToLine(tr, br, position);
1021 float dbr = DistanceToLine(br, bl, position);
1023 float d = dbl < dtl ? dbl : dtl;
1024 d = d < dtr ? d : dtr;
1025 d = d < dbr ? d : dbr;
1027 if (distanceSqr > d)
1034 else if (isBeginRegion && currentLine != text.textInfo.characterInfo[characterIndex + 1].lineNumber)
1036 isBeginRegion =
false;
1038 br = rectTransform.TransformPoint(
new Vector3(currentCharInfo.topRight.x, currentCharInfo.descender, 0));
1039 tr = rectTransform.TransformPoint(
new Vector3(currentCharInfo.topRight.x, currentCharInfo.ascender, 0));
1042 if (PointIntersectRectangle(position, bl, tl, tr, br))
1046 float dbl = DistanceToLine(bl, tl, position);
1047 float dtl = DistanceToLine(tl, tr, position);
1048 float dtr = DistanceToLine(tr, br, position);
1049 float dbr = DistanceToLine(br, bl, position);
1051 float d = dbl < dtl ? dbl : dtl;
1052 d = d < dtr ? d : dtr;
1053 d = d < dbr ? d : dbr;
1055 if (distanceSqr > d)
1311 public static int FindIntersectingLine(TMP_Text text, Vector3 position, Camera camera)
1313 RectTransform rectTransform = text.rectTransform;
1318 ScreenPointToWorldPointInRectangle(rectTransform, position, camera, out position);
1320 for (
int i = 0; i < text.textInfo.lineCount; i++)
1322 TMP_LineInfo lineInfo = text.textInfo.lineInfo[i];
1324 float ascender = rectTransform.TransformPoint(
new Vector3(0, lineInfo.ascender, 0)).y;
1325 float descender = rectTransform.TransformPoint(
new Vector3(0, lineInfo.descender, 0)).y;
1327 if (ascender > position.y && descender < position.y)
1346 public static int FindIntersectingLink(TMP_Text text, Vector3 position, Camera camera)
1348 Transform rectTransform = text.transform;
1351 ScreenPointToWorldPointInRectangle(rectTransform, position, camera, out position);
1353 for (
int i = 0; i < text.textInfo.linkCount; i++)
1355 TMP_LinkInfo linkInfo = text.textInfo.linkInfo[i];
1357 bool isBeginRegion =
false;
1359 Vector3 bl = Vector3.zero;
1360 Vector3 tl = Vector3.zero;
1361 Vector3 br = Vector3.zero;
1362 Vector3 tr = Vector3.zero;
1365 for (
int j = 0; j < linkInfo.linkTextLength; j++)
1367 int characterIndex = linkInfo.linkTextfirstCharacterIndex + j;
1368 TMP_CharacterInfo currentCharInfo = text.textInfo.characterInfo[characterIndex];
1369 int currentLine = currentCharInfo.lineNumber;
1372 if (text.overflowMode == TextOverflowModes.Page && currentCharInfo.pageNumber + 1 != text.pageToDisplay)
continue;
1374 if (isBeginRegion ==
false)
1376 isBeginRegion =
true;
1378 bl = rectTransform.TransformPoint(
new Vector3(currentCharInfo.bottomLeft.x, currentCharInfo.descender, 0));
1379 tl = rectTransform.TransformPoint(
new Vector3(currentCharInfo.bottomLeft.x, currentCharInfo.ascender, 0));
1384 if (linkInfo.linkTextLength == 1)
1386 isBeginRegion =
false;
1388 br = rectTransform.TransformPoint(
new Vector3(currentCharInfo.topRight.x, currentCharInfo.descender, 0));
1389 tr = rectTransform.TransformPoint(
new Vector3(currentCharInfo.topRight.x, currentCharInfo.ascender, 0));
1392 if (PointIntersectRectangle(position, bl, tl, tr, br))
1400 if (isBeginRegion && j == linkInfo.linkTextLength - 1)
1402 isBeginRegion =
false;
1404 br = rectTransform.TransformPoint(
new Vector3(currentCharInfo.topRight.x, currentCharInfo.descender, 0));
1405 tr = rectTransform.TransformPoint(
new Vector3(currentCharInfo.topRight.x, currentCharInfo.ascender, 0));
1408 if (PointIntersectRectangle(position, bl, tl, tr, br))
1414 else if (isBeginRegion && currentLine != text.textInfo.characterInfo[characterIndex + 1].lineNumber)
1416 isBeginRegion =
false;
1418 br = rectTransform.TransformPoint(
new Vector3(currentCharInfo.topRight.x, currentCharInfo.descender, 0));
1419 tr = rectTransform.TransformPoint(
new Vector3(currentCharInfo.topRight.x, currentCharInfo.ascender, 0));
1422 if (PointIntersectRectangle(position, bl, tl, tr, br))
1639 public static int FindNearestLink(TMP_Text text, Vector3 position, Camera camera)
1641 RectTransform rectTransform = text.rectTransform;
1644 ScreenPointToWorldPointInRectangle(rectTransform, position, camera, out position);
1646 float distanceSqr = Mathf.Infinity;
1649 for (
int i = 0; i < text.textInfo.linkCount; i++)
1651 TMP_LinkInfo linkInfo = text.textInfo.linkInfo[i];
1653 bool isBeginRegion =
false;
1655 Vector3 bl = Vector3.zero;
1656 Vector3 tl = Vector3.zero;
1657 Vector3 br = Vector3.zero;
1658 Vector3 tr = Vector3.zero;
1661 for (
int j = 0; j < linkInfo.linkTextLength; j++)
1663 int characterIndex = linkInfo.linkTextfirstCharacterIndex + j;
1664 TMP_CharacterInfo currentCharInfo = text.textInfo.characterInfo[characterIndex];
1665 int currentLine = currentCharInfo.lineNumber;
1668 if (text.overflowMode == TextOverflowModes.Page && currentCharInfo.pageNumber + 1 != text.pageToDisplay)
continue;
1670 if (isBeginRegion ==
false)
1672 isBeginRegion =
true;
1676 bl = rectTransform.TransformPoint(
new Vector3(currentCharInfo.bottomLeft.x, currentCharInfo.descender, 0));
1677 tl = rectTransform.TransformPoint(
new Vector3(currentCharInfo.bottomLeft.x, currentCharInfo.ascender, 0));
1680 if (linkInfo.linkTextLength == 1)
1682 isBeginRegion =
false;
1684 br = rectTransform.TransformPoint(
new Vector3(currentCharInfo.topRight.x, currentCharInfo.descender, 0));
1685 tr = rectTransform.TransformPoint(
new Vector3(currentCharInfo.topRight.x, currentCharInfo.ascender, 0));
1688 if (PointIntersectRectangle(position, bl, tl, tr, br))
1692 float dbl = DistanceToLine(bl, tl, position);
1693 float dtl = DistanceToLine(tl, tr, position);
1694 float dtr = DistanceToLine(tr, br, position);
1695 float dbr = DistanceToLine(br, bl, position);
1697 float d = dbl < dtl ? dbl : dtl;
1698 d = d < dtr ? d : dtr;
1699 d = d < dbr ? d : dbr;
1701 if (distanceSqr > d)
1711 if (isBeginRegion && j == linkInfo.linkTextLength - 1)
1713 isBeginRegion =
false;
1715 br = rectTransform.TransformPoint(
new Vector3(currentCharInfo.topRight.x, currentCharInfo.descender, 0));
1716 tr = rectTransform.TransformPoint(
new Vector3(currentCharInfo.topRight.x, currentCharInfo.ascender, 0));
1719 if (PointIntersectRectangle(position, bl, tl, tr, br))
1723 float dbl = DistanceToLine(bl, tl, position);
1724 float dtl = DistanceToLine(tl, tr, position);
1725 float dtr = DistanceToLine(tr, br, position);
1726 float dbr = DistanceToLine(br, bl, position);
1728 float d = dbl < dtl ? dbl : dtl;
1729 d = d < dtr ? d : dtr;
1730 d = d < dbr ? d : dbr;
1732 if (distanceSqr > d)
1740 else if (isBeginRegion && currentLine != text.textInfo.characterInfo[characterIndex + 1].lineNumber)
1742 isBeginRegion =
false;
1744 br = rectTransform.TransformPoint(
new Vector3(currentCharInfo.topRight.x, currentCharInfo.descender, 0));
1745 tr = rectTransform.TransformPoint(
new Vector3(currentCharInfo.topRight.x, currentCharInfo.ascender, 0));
1748 if (PointIntersectRectangle(position, bl, tl, tr, br))
1752 float dbl = DistanceToLine(bl, tl, position);
1753 float dtl = DistanceToLine(tl, tr, position);
1754 float dtr = DistanceToLine(tr, br, position);
1755 float dbr = DistanceToLine(br, bl, position);
1757 float d = dbl < dtl ? dbl : dtl;
1758 d = d < dtr ? d : dtr;
1759 d = d < dbr ? d : dbr;
1761 if (distanceSqr > d)
2012 private static bool PointIntersectRectangle(Vector3 m, Vector3 a, Vector3 b, Vector3 c, Vector3 d)
2019 float abamDot = Vector3.Dot(ab, am);
2020 float bcbmDot = Vector3.Dot(bc, bm);
2022 return 0 <= abamDot && abamDot <= Vector3.Dot(ab, ab) && 0 <= bcbmDot && bcbmDot <= Vector3.Dot(bc, bc);
2034 public static bool ScreenPointToWorldPointInRectangle(Transform transform, Vector2 screenPoint, Camera cam, out Vector3 worldPoint)
2036 worldPoint = (Vector3)Vector2.zero;
2037 Ray ray = RectTransformUtility.ScreenPointToRay(cam, screenPoint);
2039 if (!
new Plane(transform.rotation * Vector3.back, transform.position).Raycast(ray, out enter))
2041 worldPoint = ray.GetPoint(enter);
2048 public Vector3 Point1;
2049 public Vector3 Point2;
2067 private static bool IntersectLinePlane(
LineSegment line, Vector3 point, Vector3 normal, out Vector3 intersectingPoint)
2069 intersectingPoint = Vector3.zero;
2070 Vector3 u = line.Point2 - line.Point1;
2071 Vector3 w = line.Point1 - point;
2073 float D = Vector3.Dot(normal, u);
2074 float N = -Vector3.Dot(normal, w);
2076 if (Mathf.Abs(D) < Mathf.Epsilon)
2086 if (sI < 0 || sI > 1)
2089 intersectingPoint = line.Point1 + sI * u;
2102 public static float DistanceToLine(Vector3 a, Vector3 b, Vector3 point)
2105 Vector3 pa = a - point;
2107 float c = Vector3.Dot( n, pa );
2111 return Vector3.Dot( pa, pa );
2113 Vector3 bp = point - b;
2116 if (Vector3.Dot( n, bp ) > 0.0f )
2117 return Vector3.Dot( bp, bp );
2120 Vector3 e = pa - n * (c / Vector3.Dot( n, n ));
2122 return Vector3.Dot( e, e );
2164 const string k_lookupStringL =
"-------------------------------- !-#$%&-()*+,-./0123456789:;<=>?@abcdefghijklmnopqrstuvwxyz[-]^_`abcdefghijklmnopqrstuvwxyz{|}~-";
2169 const string k_lookupStringU =
"-------------------------------- !-#$%&-()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[-]^_`ABCDEFGHIJKLMNOPQRSTUVWXYZ{|}~-";
2175 public static char ToLowerFast(
char c)
2177 if (c > k_lookupStringL.Length - 1)
2180 return k_lookupStringL[c];
2186 public static char ToUpperFast(
char c)
2188 if (c > k_lookupStringU.Length - 1)
2191 return k_lookupStringU[c];
2198 public static int GetSimpleHashCode(
string s)
2202 for (
int i = 0; i < s.Length; i++)
2203 hashCode = (hashCode << 5) + hashCode ^ s[i];
2212 public static uint GetSimpleHashCodeLowercase(
string s)
2214 uint hashCode = 5381;
2216 for (
int i = 0; i < s.Length; i++)
2217 hashCode = (hashCode << 5) + hashCode ^ ToLowerFast(s[i]);
2228 public static int HexToInt(
char hex)
2242 case 'A':
return 10;
2243 case 'B':
return 11;
2244 case 'C':
return 12;
2245 case 'D':
return 13;
2246 case 'E':
return 14;
2247 case 'F':
return 15;
2248 case 'a':
return 10;
2249 case 'b':
return 11;
2250 case 'c':
return 12;
2251 case 'd':
return 13;
2252 case 'e':
return 14;
2253 case 'f':
return 15;
2264 public static int StringToInt(
string s)
2268 for (
int i = 0; i < s.Length; i++)
2270 value += HexToInt(s[i]) * (int)Mathf.Pow(16, (s.Length - 1) - i);
Structure which contains the character index and position of caret relative to the character.
Base class which contains common properties and functions shared between the TextMeshPro and TextMesh...
new RectTransform rectTransform
Returns are reference to the RectTransform
TMP custom data type to represent 32 bit characters.
TMP_TextInfo textInfo
Returns data about the text object which includes information about each character,...