Skip to content

Commit

Permalink
InputField対応
Browse files Browse the repository at this point in the history
  • Loading branch information
coposuke committed Jun 28, 2020
1 parent a6b346a commit b083d82
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 20 deletions.
42 changes: 31 additions & 11 deletions Scripts/Runtime/TextMeshProGeometryAnimator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ public class TextMeshProGeometryAnimator : MonoBehaviour
[SerializeField]
private bool playByProgress = false;

/// <summary>
/// ループするかどうか
/// </summary>
[SerializeField]
private bool isLoop = false;

/// <summary>
/// アニメーション中かどうか
/// </summary>
Expand Down Expand Up @@ -65,6 +71,8 @@ public class TextMeshProGeometryAnimator : MonoBehaviour
private Vector3[][] animatedVertices = default;
/// <summary>頂点カラーのアニメーション後</summary>
private Color32[][] animatedColors = default;
/// <summary>表示している文字数(のキャッシュ)</summary>
private int characterCount = 0;


#if UNITY_EDITOR
Expand Down Expand Up @@ -131,8 +139,16 @@ private void Update()
}
else
{
if (maxTime <= time) { return; }
if (maxTime <= 0.0f) { return; }
if (isLoop)
{
if (maxTime <= time) { time = 0.0f; }
}
else
{
if (maxTime <= time) { return; }
if (maxTime <= 0.0f) { return; }
}

time += Time.deltaTime * animationData.speed;
}

Expand All @@ -142,7 +158,8 @@ private void Update()
}

#if UNITY_EDITOR
progress = time / maxTime;
if(maxTime > 0.0f)
progress = time / maxTime;
#endif

UpdateAnimation();
Expand Down Expand Up @@ -224,21 +241,21 @@ private bool UpdateCachedVertex()
{
// 頂点キャッシュの確保
if (this.baseVertices == null)
this.baseVertices = new Vector3[textInfo.materialCount][];
this.baseVertices = new Vector3[this.textInfo.materialCount][];

if (this.baseColors == null)
this.baseColors = new Color32[textInfo.materialCount][];
this.baseColors = new Color32[this.textInfo.materialCount][];

if (this.animatedVertices == null)
this.animatedVertices = new Vector3[textInfo.materialCount][];
this.animatedVertices = new Vector3[this.textInfo.materialCount][];

if (this.animatedColors == null)
this.animatedColors = new Color32[textInfo.materialCount][];
this.animatedColors = new Color32[this.textInfo.materialCount][];

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

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

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

if (this.baseColors[i] != meshInfo.colors32)
if (this.baseColors[i] != meshInfo.colors32 || this.characterCount != this.textInfo.characterCount)
{
this.baseColors[i] = meshInfo.colors32;
System.Array.Copy(meshInfo.colors32, this.animatedColors[i], meshInfo.colors32.Length);
Expand Down Expand Up @@ -293,6 +310,9 @@ private void UpdateAnimation()
if (!UpdateCachedVertex())
return;

// 文字数の保存
this.characterCount = this.textInfo.characterCount;

// 開始時等MeshInfoの生成が遅れるケースがあったため小さい数値をforに使用
var count = Mathf.Min(this.textInfo.characterCount, this.textInfo.characterInfo.Length);
for (int i = 0; i < count; i++)
Expand Down
18 changes: 9 additions & 9 deletions Scripts/Runtime/TextMeshProSimpleAnimator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@ public class TextMeshProSimpleAnimator : MonoBehaviour
/// </summary>
public bool isAnimating { get; private set; } = false;

/// <summary>
/// ループするかどうか
/// </summary>
public bool isLoop = false;

/// <summary>
/// 1文字あたりの表示速度
/// </summary>
Expand All @@ -33,8 +28,13 @@ public class TextMeshProSimpleAnimator : MonoBehaviour
/// 自動再生
/// </summary>
[SerializeField]
private bool isAuto = false;

private bool playOnEnable = false;

/// <summary>
/// ループするかどうか
/// </summary>
public bool isLoop = false;

/// <summary>
/// TextMeshPro
/// </summary>
Expand All @@ -59,15 +59,15 @@ private void Awake()
/// </summary>
private void Start()
{
if (this.isAuto) { Play(); }
if (this.playOnEnable) { Play(); }
}

/// <summary>
/// Override Unity Function
/// </summary>
private void OnEnable()
{
if (this.isAuto) { Play(); }
if (this.playOnEnable) { Play(); }
}

/// <summary>
Expand Down

0 comments on commit b083d82

Please sign in to comment.