最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Unity3d實(shí)現(xiàn)跑馬燈廣播效果

 更新時(shí)間:2022年01月05日 14:28:43   作者:心林相夕  
這篇文章主要為大家詳細(xì)介紹了Unity3d實(shí)現(xiàn)跑馬燈廣播效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了Unity3d實(shí)現(xiàn)跑馬燈廣播效果的具體代碼,供大家參考,具體內(nèi)容如下

廢話不多說,直接上代碼

using DG.Tweening;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using Utils;
//掛在UI上面
public class BroadcastUI : MonoBehaviour
{
? ? private bool inited = false;
? ? private BroadcastMan bm;
? ? public Transform parent;
? ? public GameObject prefab;
? ? public float parentWith = 0f;
? ? private Queue<GameObject> textList = new Queue<GameObject>();
? ? public string curPlayMsg;
? ? private int curPlayTime = 0;
? ? public float moveTime = 5f;
? ? private int curWaitMsgNum = 0;
? ? private int curEndIndex = 0;
? ? private void Init()
? ? {
? ? ? ? bm = this.gameObject.AddComponent<BroadcastMan>();
? ? ? ? parentWith = parent.GetComponent<RectTransform>().rect.width;
? ? ? ? moveTime = moveTime * Screen.width / 812f;
? ? ? ? Debug.LogError("move speed ==" + moveTime);
? ? ? ? inited = true;
? ? }
? ? // Start is called before the first frame update
? ? private void Awake()
? ? {
? ? ? ? if (!inited) Init();
? ? }

? ? private IEnumerator ScrollMsg()
? ? {
? ? ? ? curWaitMsgNum = bm.MsgCount;
? ? ? ? parent.gameObject.SetActiveFast(true);
? ? ? ? while (bm.MsgCount > 0 || curPlayTime < bm.repetTime)
? ? ? ? {
? ? ? ? ? ? if (curPlayMsg == "")
? ? ? ? ? ? {
? ? ? ? ? ? ? ? curPlayMsg = bm.GetAMsgFromQueue();
? ? ? ? ? ? ? ? curPlayTime = 1;
? ? ? ? ? ? }
? ? ? ? ? ? else
? ? ? ? ? ? {
? ? ? ? ? ? ? ? if (bm.repetTime > 1)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? if (curPlayTime >= bm.repetTime)
? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? curPlayTime = 1;
? ? ? ? ? ? ? ? ? ? ? ? curPlayMsg = bm.GetAMsgFromQueue();
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? else
? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? curPlayTime++;
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? else
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? curPlayMsg = bm.GetAMsgFromQueue();
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? ? ? Debug.LogError("msg:" + curPlayMsg);
? ? ? ? ? ? GameObject text = GetAText();
? ? ? ? ? ? text.GetComponent<Text>().text = curPlayMsg;
? ? ? ? ? ? text.transform.SetParent(parent, false);
? ? ? ? ? ? text.transform.localPosition = prefab.transform.localPosition;
? ? ? ? ? ? yield return new WaitForEndOfFrame();
? ? ? ? ? ? float textWith = text.GetComponent<RectTransform>().rect.width;
? ? ? ? ? ? float moveDis = textWith + parentWith;
? ? ? ? ? ? float curMoveTime = moveTime * moveDis / parentWith;
? ? ? ? ? ? //Debug.LogError("當(dāng)前移動(dòng)時(shí)間,當(dāng)前播放字越多,時(shí)間越長(zhǎng)"+curMoveTime);

? ? ? ? ? ? Tweener tweener = text.transform.DOLocalMove(new Vector3(text.transform.localPosition.x - moveDis, text.transform.localPosition.y, 0), curMoveTime).SetEase(Ease.Linear)
? ? ? ? ? ? .OnComplete(() =>
? ? ? ? ? ? {
? ? ? ? ? ? ? ? curEndIndex++;
? ? ? ? ? ? ? ? textList.Enqueue(text);
? ? ? ? ? ? ? ? if (bm.MsgCount == 0 && curEndIndex == curWaitMsgNum * bm.repetTime)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? parent.gameObject.SetActiveFast(false);
? ? ? ? ? ? ? ? }
? ? ? ? ? ? });
? ? ? ? ? ? //Debug.LogError("下一條等待時(shí)間,當(dāng)前字越多,等待時(shí)間越長(zhǎng)"+ (0.5f * parentWith + textWith) / (moveDis / curMoveTime));
? ? ? ? ? ? yield return new WaitForSeconds((0.5f * parentWith + textWith) / (moveDis / curMoveTime));
? ? ? ? }
? ? }

? ? private void AddMsg()
? ? {
? ? ? ? List<string> msgs = new List<string>();
? ? ? ? msgs.Add("<color=#C0FF35>測(cè)試一下這個(gè)跑馬燈的效果>>>>>>>>>>></color>");
? ? ? ? msgs.Add("<color=#C14848>中國(guó)第七金!祝賀龐偉、姜冉馨</color>");
? ? ? ? msgs.Add("<color=#6BEE5B>第10金!中國(guó)組合獲得東京奧運(yùn)會(huì)女子四人雙槳金牌</color>");
? ? ? ? msgs.Add("<color=#EE5BBB>臺(tái)風(fēng)“煙花”</color>");
? ? ? ? msgs.Add("<color=#DB2136>把鯨魚送回大海!七米長(zhǎng)須鯨擱淺 多方力量開展救援</color>");
? ? ? ? bm.AddMsgToQueue(msgs);
? ? }

? ? private void OnDestory()
? ? {
? ? ? ? inited = false;

? ? }

? ? private void Update()
? ? {
? ? ? ? if (Input.GetKeyDown(KeyCode.A) && bm.MsgCount == 0)
? ? ? ? {
? ? ? ? ? ? AddMsg();
? ? ? ? ? ? StartCoroutine(ScrollMsg());
? ? ? ? }
? ? }

? ? private GameObject GetAText()
? ? {
? ? ? ? if (textList.Count > 0)
? ? ? ? {
? ? ? ? ? ? return textList.Dequeue();
? ? ? ? }
? ? ? ? return GameObject.Instantiate(prefab);
? ? }
}
using System.Collections.Generic;
using UnityEngine;?
//這個(gè)放收到的消息
public class BroadcastMan : MonoBehaviour
{
? ? private bool inited = false;
? ? private Queue<string> msgQueue;//燈隊(duì)列.
? ? public int repetTime = 2;//廣播重復(fù)次數(shù)
? ? private void Init()
? ? {
? ? ? ? msgQueue = new Queue<string>();
? ? ? ? inited = true;
? ? }
? ? // Start is called before the first frame update
? ? private void Awake()
? ? {
? ? ? ? if (!inited) Init();?
? ? }

? ? public void AddMsgToQueue(List<string> msgs)
? ? {
? ? ? ? for (int i = 0; i < msgs.Count; i++)
? ? ? ? {
? ? ? ? ? ? msgQueue.Enqueue(msgs[i]);
? ? ? ? }
? ? }

? ? public string GetAMsgFromQueue()
? ? {
? ? ? ? if (msgQueue.Count > 0)
? ? ? ? {
? ? ? ? ? ? return msgQueue.Dequeue();
? ? ? ? }
? ? ? ? return "";
? ? }

? ? public int MsgCount
? ? {
? ? ? ? get => msgQueue.Count;
? ? }

? ? private void OnDestory()
? ? {
? ? ? ? inited = false;
? ? }
}

界面

好了,就這樣

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論

库尔勒市| 千阳县| 马公市| 包头市| 通州市| 延津县| 凌源市| 津市市| 大城县| 新宁县| 台北县| 呼玛县| 吉安县| 湘西| 溆浦县| 吴旗县| 无棣县| 临湘市| 江津市| 邻水| 中宁县| 林周县| 呈贡县| 雷波县| 宁都县| 阿拉善右旗| 鹤壁市| 商都县| 南郑县| 博爱县| 安吉县| 苏尼特左旗| 绥滨县| 罗定市| 清水河县| 柯坪县| 南岸区| 修武县| 琼结县| 民县| 民勤县|