Skip to content

Commit b083d82

Browse files
committed
InputField対応
1 parent a6b346a commit b083d82

File tree

2 files changed

+40
-20
lines changed

2 files changed

+40
-20
lines changed

Scripts/Runtime/TextMeshProGeometryAnimator.cs

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ public class TextMeshProGeometryAnimator : MonoBehaviour
3434
[SerializeField]
3535
private bool playByProgress = false;
3636

37+
/// <summary>
38+
/// ループするかどうか
39+
/// </summary>
40+
[SerializeField]
41+
private bool isLoop = false;
42+
3743
/// <summary>
3844
/// アニメーション中かどうか
3945
/// </summary>
@@ -65,6 +71,8 @@ public class TextMeshProGeometryAnimator : MonoBehaviour
6571
private Vector3[][] animatedVertices = default;
6672
/// <summary>頂点カラーのアニメーション後</summary>
6773
private Color32[][] animatedColors = default;
74+
/// <summary>表示している文字数(のキャッシュ)</summary>
75+
private int characterCount = 0;
6876

6977

7078
#if UNITY_EDITOR
@@ -131,8 +139,16 @@ private void Update()
131139
}
132140
else
133141
{
134-
if (maxTime <= time) { return; }
135-
if (maxTime <= 0.0f) { return; }
142+
if (isLoop)
143+
{
144+
if (maxTime <= time) { time = 0.0f; }
145+
}
146+
else
147+
{
148+
if (maxTime <= time) { return; }
149+
if (maxTime <= 0.0f) { return; }
150+
}
151+
136152
time += Time.deltaTime * animationData.speed;
137153
}
138154

@@ -142,7 +158,8 @@ private void Update()
142158
}
143159

144160
#if UNITY_EDITOR
145-
progress = time / maxTime;
161+
if(maxTime > 0.0f)
162+
progress = time / maxTime;
146163
#endif
147164

148165
UpdateAnimation();
@@ -224,21 +241,21 @@ private bool UpdateCachedVertex()
224241
{
225242
// 頂点キャッシュの確保
226243
if (this.baseVertices == null)
227-
this.baseVertices = new Vector3[textInfo.materialCount][];
244+
this.baseVertices = new Vector3[this.textInfo.materialCount][];
228245

229246
if (this.baseColors == null)
230-
this.baseColors = new Color32[textInfo.materialCount][];
247+
this.baseColors = new Color32[this.textInfo.materialCount][];
231248

232249
if (this.animatedVertices == null)
233-
this.animatedVertices = new Vector3[textInfo.materialCount][];
250+
this.animatedVertices = new Vector3[this.textInfo.materialCount][];
234251

235252
if (this.animatedColors == null)
236-
this.animatedColors = new Color32[textInfo.materialCount][];
253+
this.animatedColors = new Color32[this.textInfo.materialCount][];
237254

238255
// 頂点キャッシュの内容更新
239-
for (int i = 0; i < textInfo.materialCount; i++)
256+
for (int i = 0; i < this.textInfo.materialCount; i++)
240257
{
241-
TMP_MeshInfo meshInfo = textInfo.meshInfo[i];
258+
TMP_MeshInfo meshInfo = this.textInfo.meshInfo[i];
242259

243260
if (meshInfo.vertices == null || meshInfo.colors32 == null)
244261
return false;
@@ -251,13 +268,13 @@ private bool UpdateCachedVertex()
251268
this.animatedColors[i] = new Color32[meshInfo.colors32.Length];
252269

253270
// MeshInfo 内の配列がごっそり変わった場合は参照切り替え & コピー
254-
if (this.baseVertices[i] != meshInfo.vertices)
271+
if (this.baseVertices[i] != meshInfo.vertices || this.characterCount != this.textInfo.characterCount)
255272
{
256273
this.baseVertices[i] = meshInfo.vertices;
257274
System.Array.Copy(meshInfo.vertices, this.animatedVertices[i], meshInfo.vertices.Length);
258275
}
259276

260-
if (this.baseColors[i] != meshInfo.colors32)
277+
if (this.baseColors[i] != meshInfo.colors32 || this.characterCount != this.textInfo.characterCount)
261278
{
262279
this.baseColors[i] = meshInfo.colors32;
263280
System.Array.Copy(meshInfo.colors32, this.animatedColors[i], meshInfo.colors32.Length);
@@ -293,6 +310,9 @@ private void UpdateAnimation()
293310
if (!UpdateCachedVertex())
294311
return;
295312

313+
// 文字数の保存
314+
this.characterCount = this.textInfo.characterCount;
315+
296316
// 開始時等MeshInfoの生成が遅れるケースがあったため小さい数値をforに使用
297317
var count = Mathf.Min(this.textInfo.characterCount, this.textInfo.characterInfo.Length);
298318
for (int i = 0; i < count; i++)

Scripts/Runtime/TextMeshProSimpleAnimator.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,6 @@ public class TextMeshProSimpleAnimator : MonoBehaviour
1919
/// </summary>
2020
public bool isAnimating { get; private set; } = false;
2121

22-
/// <summary>
23-
/// ループするかどうか
24-
/// </summary>
25-
public bool isLoop = false;
26-
2722
/// <summary>
2823
/// 1文字あたりの表示速度
2924
/// </summary>
@@ -33,8 +28,13 @@ public class TextMeshProSimpleAnimator : MonoBehaviour
3328
/// 自動再生
3429
/// </summary>
3530
[SerializeField]
36-
private bool isAuto = false;
37-
31+
private bool playOnEnable = false;
32+
33+
/// <summary>
34+
/// ループするかどうか
35+
/// </summary>
36+
public bool isLoop = false;
37+
3838
/// <summary>
3939
/// TextMeshPro
4040
/// </summary>
@@ -59,15 +59,15 @@ private void Awake()
5959
/// </summary>
6060
private void Start()
6161
{
62-
if (this.isAuto) { Play(); }
62+
if (this.playOnEnable) { Play(); }
6363
}
6464

6565
/// <summary>
6666
/// Override Unity Function
6767
/// </summary>
6868
private void OnEnable()
6969
{
70-
if (this.isAuto) { Play(); }
70+
if (this.playOnEnable) { Play(); }
7171
}
7272

7373
/// <summary>

0 commit comments

Comments
 (0)