最新国产好看的视频,伊人天堂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í)間越長"+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í)間越長"+ (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>測試一下這個(gè)跑馬燈的效果>>>>>>>>>>></color>");
? ? ? ? msgs.Add("<color=#C14848>中國第七金!祝賀龐偉、姜冉馨</color>");
? ? ? ? msgs.Add("<color=#6BEE5B>第10金!中國組合獲得東京奧運(yùn)會(huì)女子四人雙槳金牌</color>");
? ? ? ? msgs.Add("<color=#EE5BBB>臺風(fēng)“煙花”</color>");
? ? ? ? msgs.Add("<color=#DB2136>把鯨魚送回大海!七米長須鯨擱淺 多方力量開展救援</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;
? ? }
}

界面

好了,就這樣

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

相關(guān)文章

最新評論

察隅县| 泊头市| 华阴市| 青川县| 扎兰屯市| 隆尧县| 田阳县| 千阳县| 富阳市| 梅河口市| 南雄市| 和硕县| 富宁县| 天等县| 常州市| 郧西县| 乌拉特后旗| 太和县| 白城市| 古交市| 潍坊市| 晋中市| 河间市| 丰镇市| 黄浦区| 锦州市| 晋中市| 徐州市| 博爱县| 高安市| 开封县| 阿拉善右旗| 恭城| 师宗县| 上虞市| 梁河县| 宜兰县| 陆丰市| 宽城| 汝州市| 务川|