Skip to content

Commit acab209

Browse files
committed
V 1.0 Release
1 parent 77b0b5e commit acab209

13 files changed

Lines changed: 481 additions & 39 deletions
Lines changed: 457 additions & 6 deletions
Large diffs are not rendered by default.
File renamed without changes.
Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class DynamicText : MonoBehaviour
1414
void Start()
1515
{
1616
text = GetComponent<TMP_Text>();
17-
//Kinda gross workaround to get the text to update
17+
//Text mesh pro text doesn't like being passed as a reference
1818
string parsedText = text.text;
1919
effectRanges = ParseText(ref parsedText);
2020
text.text = parsedText;
@@ -28,6 +28,7 @@ void Update()
2828

2929
Vector3[][] textVertices = new Vector3[textInfo.characterCount][];
3030

31+
//Get the vertices of the text
3132
for(int i = 0; i < textInfo.characterCount; i++){
3233
TMP_CharacterInfo charInfo = textInfo.characterInfo[i];
3334
textVertices[i] = new Vector3[4];
@@ -39,6 +40,15 @@ void Update()
3940
void UpdateMesh() {
4041
for(int i = 0; i < textInfo.characterCount; i++){
4142
TMP_CharacterInfo charInfo = textInfo.characterInfo[i];
43+
44+
/*
45+
For some reason text mesh pro decides to use quantum entaglement when dealing with whitespace characters so we just ignore changes made to them
46+
(for some reason the vertices for a space character are both not real and actually just references to the first character in the text????)
47+
*/
48+
if(charInfo.character == ' ' || charInfo.character == '\n' || charInfo.character == '\t') {
49+
continue;
50+
}
51+
4252
for(int j = 0; j < 4; j++) {
4353
textInfo.meshInfo[charInfo.materialReferenceIndex].vertices[charInfo.vertexIndex + j] = textVertices[i][j];
4454
}
@@ -48,7 +58,6 @@ void UpdateMesh() {
4858

4959

5060
foreach(EffectRange effectRange in effectRanges) {
51-
print(effectRange.effect + " " + effectRange.startIndex + " " + effectRange.endIndex + " " + effectRange.input);
5261
effectRange.effect.UpdateText(textVertices, effectRange.startIndex, effectRange.endIndex, effectRange.input);
5362
UpdateMesh();
5463
}

Assets/Scripts/Effects/TextCharacterShakeEffect.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,13 @@ public class TextCharacterShakeEffect : TextVertexEffect
66

77
public override void UpdateText(Vector3[][] textVertices, int start, int end, float input) {
88
for (int i = start; i < end; i++) {
9-
109
float shakeX = Random.Range(-input, input);
1110
float shakeY = Random.Range(-input, input);
1211

1312
for (int j = 0; j < 4; j++) {
1413
Vector3 orig = textVertices[i][j];
1514
textVertices[i][j] = orig + new Vector3(shakeX, shakeY);
16-
1715
}
18-
1916
}
2017
}
2118
}

Assets/Scripts/Effects/TextWaveEffect.cs

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,11 @@ public class TextWaveEffect : TextVertexEffect
88
static float waveSpeed = 4f;
99

1010
public override void UpdateText(Vector3[][] textVertices, int start, int end, float input) {
11-
for (int i = start; i < end; i++) {
11+
for (int i = start; i < end; i++) {
1212

13-
float charX = getFurthestLeftPoint(textVertices[i]);
14-
15-
//Debug.DrawRay(textVertices[i][0], Vector3.right + Vector3.up * wave, Color.red);
1613
for (int j = 0; j < 4; j++) {
1714
Vector3 orig = textVertices[i][j];
1815

19-
2016
textVertices[i][j] = orig + getSin(orig.x) * (Vector3.up * input);
2117
}
2218

@@ -27,14 +23,4 @@ public override void UpdateText(Vector3[][] textVertices, int start, int end, fl
2723
static float getSin(float x) {
2824
return Mathf.Sin(x * waveFrequency + Time.time * waveSpeed);
2925
}
30-
31-
static float getFurthestLeftPoint(Vector3[] vertices) {
32-
float furthestLeft = float.MaxValue;
33-
for (int i = 0; i < vertices.Length; i++) {
34-
if (vertices[i].x < furthestLeft) {
35-
furthestLeft = vertices[i].x;
36-
}
37-
}
38-
return furthestLeft;
39-
}
4026
}
Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
using System;
22
using System.Collections;
33
using System.Collections.Generic;
4+
using System.Linq;
45
using System.Text.RegularExpressions;
5-
using Unity.Mathematics;
6-
using Unity.VisualScripting;
76
using UnityEngine;
87

98
public class TextParser : MonoBehaviour
@@ -13,7 +12,7 @@ public class TextParser : MonoBehaviour
1312
private const string REMAINDER_REGEX = "(.*?((?=>)|(/|$)))";
1413

1514
//Because text mesh pro parses it's own tags, we need to find them
16-
private static readonly Regex richTagRegex = new Regex("<.*?>");
15+
private static readonly Regex richTagRegex = new Regex("<" + REMAINDER_REGEX + ">");
1716

1817
static readonly TextRegex[] textRegexes = {
1918
new("shake", new TextCharacterShakeEffect()),
@@ -57,7 +56,6 @@ void UpdateRanges(int index, int length) {
5756
float input = float.Parse(startMatch.Groups["input"].Value);
5857
int startIndex = startMatch.Index;
5958
int endIndex = text.Length; //Because there can be no end tag, the default end index is the end of the text
60-
//Removes the tags from the text
6159

6260
//If an end tag exists
6361
if(endMatch != null) {
@@ -70,7 +68,7 @@ void UpdateRanges(int index, int length) {
7068
}
7169
}
7270

73-
//Fixing the indexes and removing tags
71+
//Fixing the removing tags and fixing indexes for the preceding tags
7472
for(int i = 0; i < effectRanges.Count; i++) {
7573

7674

@@ -87,11 +85,12 @@ void UpdateRanges(int index, int length) {
8785

8886
//Modifying the indexes to account for the removed non custom rich tags
8987
MatchCollection nonCustomTagMatches = richTagRegex.Matches(text);
88+
nonCustomTagMatches.OrderBy(match => match.Index);
89+
int offset = 0;
9090
for(int i = 0; i < nonCustomTagMatches.Count; i++) {
9191
Match match = nonCustomTagMatches[i];
92-
if(match.Success) {
93-
UpdateRanges(match.Index, match.Length);
94-
}
92+
UpdateRanges(match.Index - offset, match.Length);
93+
offset += match.Length;
9594
}
9695

9796
return effectRanges;

0 commit comments

Comments
 (0)