@@ -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 ++ )
0 commit comments