游戏中广播消息公告(测试)
来源:互联网 发布:五行量化指标源码 编辑:程序博客网 时间:2024/06/06 07:19
只是测试用,有很多bug,以后用到这个功能在完善吧
public GameObject RollingParent;
public int index = 0;
public string []aa;
void Start ()
{
RollingParent = GameObject.Find ("Canvas/Panel");
aa = new string[3]{"无形之刃,最为致命","我用双手,成就你的梦想","断剑重铸之日,骑士归来之时"};//模拟服务器发送的消息列表
var button = transform.gameObject.GetComponent<Button>();
if (button != null)
{
button.onClick.RemoveAllListeners();
button.onClick.AddListener(SetDateTxt);
}
}
public void SetDateTxt()
{
if (index > aa.Length) {
return;
}
RollingParent.transform.FindChild("Rolling").gameObject.SetActive (true);
Text text = RollingParent.transform.FindChild ("Rolling/Text").GetComponent<Text> () ;
if (text)
text.gameObject.GetComponent<Text>().text = aa[index];
text.gameObject.gameObject.AddComponent<RollingTest> ();
index ++;
}
------------------------
上面的代码只是用来测试模拟服务器发送字符串列表 在Rolling的子物体挂载RollingTest.cs脚本
思路很简单:就是获取开始和终点坐标 ,然后如果坐标不想等就让文本移动而已。
代码如下:
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class RollingTest : MonoBehaviour {
public float mSpeed=50.0f;
public Transform targetTransform;
public Transform startTransform;
public float time;
void Awake ()
{
transform.parent.transform.gameObject.SetActive (true);
targetTransform = transform.parent.Find ("End");
startTransform = transform.parent.Find ("Start");
}
void Start ()
{
time = Mathf.Abs (startTransform.position.x - targetTransform.position.x) / mSpeed;
Invoke ("setCurRollingState",time);
}
void Update ()
{
transform.Translate (Vector3.left * Time.deltaTime * mSpeed);
if (transform.position.x <= targetTransform.position.x) {
transform.position = startTransform.position;
}
}
void setCurRollingState(){
transform.parent.transform.gameObject.SetActive (false);
Destroy (transform.GetComponent<RollingTest> ());
}
}
蛮牛已经有更好的办法,是用Dotween处理动画,并动态加载列表。。
- 游戏中广播消息公告(测试)
- 观察者 (广播消息)
- Network:UDP广播消息的测试
- Rocketmq消息队列广播消费测试
- <Android>游戏中简单的WebView公告适配
- Android中接收系统广播消息
- Unity3D 发送广播与消息、利用脚本控制游戏
- 广播消息
- 公告:消息系统停站维护公告
- 广播游戏
- Android 以太网测试(广播)
- 【公告】新版空间测试地址公告
- MFC学习(18)MFC中利用HWND_BROADCAST 向其它所有窗口广播消息
- CSDN网站消息系统升级公告
- 自制弹出框--公告消息
- IOS消息分发(广播)机制
- Android消息推送(广播机制)+通知
- UDP局域网内广播消息(转载)
- 华为机试---投篮游戏
- Linux下高效编写Shell——shell特殊字符汇总
- 将 Google Analytics(分析)添加到 Android 应用中
- daterangepicker日期选择控件
- ACL工具备份和恢复Linux的文件权限
- 游戏中广播消息公告(测试)
- hadoop2.6.4分布式配置安装
- C#中和Java中读取二进制数字时的不同之处
- /**切控件圆角 设置边框*/
- 地图与定位(七)高德定位服务
- 移动端web页面知识小结之meta部分
- ajaxFileUpload+SpringMVC框架+maven 实现文件上传
- jsp及servlet分别实现简单的计算器
- Format —— Java & Android