UGUI—动态省略号效果

作者:追风剑情 发布于:2020-11-12 11:02 分类:Unity3d

示例:动态省略号效果

using UnityEngine;
using UnityEngine.UI;
using TMPro;
/// <summary>
/// 在字符串后面追加动态省略号效果...
/// </summary>
public class UIWaitEllipsisEffect : MonoBehaviour
{
    public TMP_Text TMPText;
    public Text text;
    public string loadingContent;
    public string normalContent;
    public float interval = 0.3f;

    private float lastTime = 0;
    private int i = 0;
    private string[] ellips = new string[] { "", ".", "..", "..." };

    private void Update()
    {
        if (Time.time - lastTime < interval)
            return;
        lastTime = Time.time;
        SetText(loadingContent + ellips[i]);
        i = (i + 1) % ellips.Length;
    }

    private void OnDisable()
    {
        if (!string.IsNullOrEmpty(normalContent))
            SetText(normalContent);
    }

    private void SetText(string value)
    {
        if (text != null)
            text.text = value;
        else if (TMPText != null)
            TMPText.text = value;
    }
}


运行效果
3335.gif

标签: Unity3d

Powered by emlog  蜀ICP备18021003号-1   sitemap

川公网安备 51019002001593号