分享一个简单的跑马灯

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using CUI.View;
using UnityEngine.UI;
using DG.Tweening;
using DG.Tweening.Core;
using System;

public class MarqueeTop : BasePop
{
    public Text text;

    protected override void Preprocessing()
    {
        isClick = false;
        UIType = UIType.NonPush;
        PrefabName = gameObject.name;
        ParentNode = UINodesManager.TopUIRoot;
        isMask = false;
    }

    public Queue marqueeList = new Queue();

    ///后期做一个权重排列
    /////
    public void ShowInfo(string str)
    {
        marqueeList.Enqueue(str);
        if(tweener == null)
        {
            ShowUI();
        }
    }

    private Vector3 BeginPos = new Vector3(700,0,0);
    private Vector3 EndPos = new Vector3(-700,0,0);
    private Tweener tweener;
    private void ShowUI()
    {
        if(marqueeList.Count == 0)
        {
            tweener = null;
            Hide();
            return;
        }
        string str = marqueeList.Dequeue();

        text.text = str;
        text.transform.localPosition = BeginPos;

        tweener = text.transform.DOLocalMove(EndPos, 12f);
        tweener.onComplete = MoveComplete;
    }

    private void MoveComplete()
    {
        ShowUI();
    }
}

你可能感兴趣的:(分享一个简单的跑马灯)