首页 > 作文

Unity3d实现跑马灯广播效果

更新时间:2023-04-04 12:46:20 阅读: 评论:0

本文实例为大家分享了unity3d实现跑马灯广播效果的具体代码,供大家参考,具体内容如下

废话不多说,直接上代码

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 = fal;  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.tactivefast(true);    while (bm.msgcount > 0 || curplaytime < bm.repettime)    {      if (curplaymsg == "")      {        curplaymsg = bm.getamsgfromqueue();        curplaytime = 1;      }      el      {        if (bm.repettime > 1)        {          if (curplaytime >= bm.repettime)          {            curplaytime = 1;            curplaymsg = bm.getamsgfromqueue();          }          el          {            curplaytime+脚踏实地的素材+;          }        }        el        {          curplaymsg = bm.getamsgfromqueue();        }      }      debug.logerror("msg:" + curplaymsg);      gameobject text = getatext();      text.getcomponent<text>().text = curplaymsg;      text.transform.tparent(parent, fal);      text.transform.localposition = prefab.transform.localposition;      y企业策划书ield return new waitforendofframe();      float textwith = text.getcomponent<recttransform>().rect.width;      float movedis = textwith 高一语文必修一知识点总结+ parentwith;      float curmovetime = movetime * movedis / parentwith;      //debug.logerror("当前移动时间,当前播放字越多,时间越长"+curmovetime);      tweener tweener = text.transform.dolocalmove(new vector3(text.transform.localposition.x - movedis, text.transform.localposition.y, 0), curmovetime).tea(ea.linear)      .oncomplete(() =>      {        curendindex++;        textlist.enqueue(text);        if (bm.msgcount == 0 && curendindex == curwaitmsgnum * bm.repettime)        {          parent.gameobject.tactivefast(fal);        }      });      //debug.logerror("下一条等待时间,当前字越多,等待时间越长"+ (0.5f * parentwith + textwith) / (movedis / curmovetime));      yield return new waitforconds((0.5f * parentwith + textwith) / (movedis / curmovetime));    }  }  private void addmsg()  {    list<string> msgs = new list<string>();    msgs.add("<color=#c0ff35>测试一下这个跑马灯的效果>>>>>>>>>>></color>");    msgs.add("<color=#c14848>中国第七金!祝贺庞伟、姜冉馨</color>");    msgs.add("<color=#6bee5b>第10金!中国组合获得东京奥运会女子四人双桨金牌</color>");    msgs.add("<color=#ee5bbb>台风“烟花”</color>");    msgs.add("<color=#db2136>把鲸鱼送回大海!七米长须鲸搁浅 多方力量开展救援</color>");    bm.addmsgtoqueue(msgs);  }  private void ondestory()  {    inited = fal;  }  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.col洛克王国邪恶玄武lections.generic;using unityengine;//这个放收到的消息public class broadcastman : monobehaviour{  private bool inited = fal;  private queue<string> msgqueue;//灯队列.  public int repettime = 2;//广播重复次数  private void init()  {    msgqueue = new queue<string>();    inited = true;  }  // start is called before the first frame upda团课思想汇报te  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 = fal;  }}

界面

好了,就这样

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持www.887551.com。

本文发布于:2023-04-04 12:46:19,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/zuowen/07a4a4dc0504412a4edd51b70e1bc555.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

本文word下载地址:Unity3d实现跑马灯广播效果.doc

本文 PDF 下载地址:Unity3d实现跑马灯广播效果.pdf

标签:时间   越多   中国   洛克
相关文章
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图