unity 中让Text的文字动态刷新形式
第一种刷新文字形式
- using UnityEngine;
- using System.Collections;
- using UnityEngine.UI;
- public class SensorTextRefresh2
- {
- // Use this for initialization
- string showstring;
- public Text _text;
- public string otherName = "normal";
- string current;
- RefreshState refreshState;
- int index = ;
- public void Init(Text _t, string _s, int _index, string _otherName)
- {
- refreshState = RefreshState.start;
- _s = float.Parse(_s).ToString("0.00");
- if (index == )
- {
- showstring = _s;
- current = _s;
- }
- else if (index == )
- {
- //if (_text.transform.parent.name == "transmitter" || _text.transform.parent.name == "temperature1")
- {
- showstring = _s;
- current = _s;
- }
- //else
- //{
- // showstring = _s + "℃";
- // current = _s + "℃";
- //}
- }
- else
- {
- }
- _text = _t;
- index = _index;
- otherName = _otherName;
- //Debug.LogError( " " + _text.transform.parent.parent.parent.name);
- }
- public void SetString(string _s)
- {
- //if (refreshState == RefreshState.start)
- {
- _s = float.Parse(_s).ToString("0.00");
- if (index == )
- {
- current = _s;
- _text.text = "";
- _text.text = current;
- }
- else if (index == )
- {
- current = _s;
- _text.text = "";
- //if (otherName.Contains("PP"))
- //{
- // Debug.LogError(" " + _text.text);
- //}
- //if (otherName.Contains("TP"))
- //{
- // Debug.LogError(" " + _text.text);
- //}
- //if (otherName.Contains("LP"))
- //{
- // Debug.LogError(" " + _text.text);
- //}
- //if (otherName.Contains("JP"))
- //{
- // Debug.LogError(" " + _text.text);
- //}
- //if (otherName.Contains("YP"))
- //{
- // Debug.LogError(" " + _text.text);
- //}
- }
- else
- {
- }
- }
- }
- // Update is called once per frame
- float timer = 1.0f;
- float stringLength = ;
- float speed = 1.0f;
- int i = ;
- public void Update()
- {
- if (_text == null)
- return;
- if (refreshState == RefreshState.start)
- {
- _text.text = "";
- refreshState = RefreshState.show;
- }
- if (refreshState == RefreshState.show)
- {
- stringLength += Time.deltaTime * speed;
- if (stringLength <= )
- {
- string temp = showstring.Substring(, showstring.Length);
- //_text.text = temp.Substring(0, (int)stringLength - 1);
- //_text.text += "<color=#E7E7E9FF>" + temp.Substring((int)stringLength - 1, 1) + "</color>";
- if (otherName.Contains("TP") || otherName.Contains("TF") || otherName.Contains("温度"))
- {
- _text.text = ("<color=#E7E7E9FF>" + temp.Substring(, showstring.Length) + "</color>" + "℃");
- }
- else if (otherName.Contains("PP") || otherName.Contains("PF") || otherName.Contains("压力"))
- {
- _text.text = "<color=#E7E7E9FF>" + temp.Substring(, showstring.Length) + "</color>" + "Mpa";
- }
- else if (otherName.Contains("JP") || otherName.Contains("YP") || otherName.Contains("LP") || otherName.Contains("JF") || otherName.Contains("YF") || otherName.Contains("LF") || otherName.Contains("计量泵") || otherName.Contains("油剂泵") || otherName.Contains("挤压机频率"))
- {
- _text.text = "<color=#E7E7E9FF>" + temp.Substring(, showstring.Length) + "</color>" + "Hz";
- }
- else if (otherName.Contains("电流"))
- {
- _text.text = "<color=#E7E7E9FF>" + temp.Substring(, showstring.Length) + "</color>" + "A";
- }
- }
- else if (stringLength > && stringLength <= )
- {
- if (otherName.Contains("TP") || otherName.Contains("TF") || otherName.Contains("温度"))
- {
- _text.text = "℃";
- }
- else if (otherName.Contains("PP") || otherName.Contains("PF") || otherName.Contains("压力"))
- {
- _text.text = "Mpa";
- }
- else if (otherName.Contains("JP") || otherName.Contains("YP") || otherName.Contains("LP") || otherName.Contains("JF") || otherName.Contains("YF") || otherName.Contains("LF") || otherName.Contains("计量泵") || otherName.Contains("油剂泵") || otherName.Contains("挤压机频率"))
- {
- _text.text = "Hz";
- }
- else if (otherName.Contains("电流"))
- {
- _text.text = "A";
- }
- }
- else
- {
- if (otherName.Contains("TP") || otherName.Contains("TF") || otherName.Contains("温度"))
- {
- _text.text = showstring.Substring(, (int)showstring.Length) + "℃"; ;
- }
- else if (otherName.Contains("PP") || otherName.Contains("PF") || otherName.Contains("压力"))
- {
- _text.text = showstring.Substring(, (int)showstring.Length) + "Mpa";
- }
- else if (otherName.Contains("JP") || otherName.Contains("YP") || otherName.Contains("LP") || otherName.Contains("JF") || otherName.Contains("YF") || otherName.Contains("LF") || otherName.Contains("计量泵") || otherName.Contains("油剂泵") || otherName.Contains("挤压机频率"))
- {
- _text.text = showstring.Substring(, (int)showstring.Length) + "Hz";
- }
- else if (otherName.Contains("电流"))
- {
- _text.text = showstring.Substring(, (int)showstring.Length) + "A";
- }
- }
- if (stringLength > 3.0f)
- {
- //结束
- stringLength = ;
- refreshState = RefreshState.end;
- }
- }
- if (refreshState == RefreshState.delay)
- {
- _text.text = "";
- stringLength += Time.deltaTime;
- if (stringLength >= timer)
- {
- refreshState = RefreshState.end;
- }
- }
- if (refreshState == RefreshState.end)
- {
- stringLength = ;
- if (!showstring.Equals(current))
- {
- showstring = current;
- }
- refreshState = RefreshState.start;
- }
- }
- enum RefreshState
- {
- start,
- show,
- delay,
- end
- }
- }
第二种刷新文字形式
- using UnityEngine;
- using System.Collections;
- using UnityEngine.UI;
- public class SensorTextRefresh1
- {
- // Use this for initialization
- string showstring;
- public Text _text;
- string current;
- RefreshState refreshState;
- int index = ;
- public void Init(Text _t, string _s)
- {
- refreshState = RefreshState.start;
- {
- showstring = _s + "℃";
- current = _s + "℃";
- }
- _text = _t;
- }
- public void SetString(string _s)
- {
- if (refreshState == RefreshState.start)
- {
- {
- current = _s + "℃";
- _text.text = "";
- }
- }
- }
- // Update is called once per frame
- float timer = 0.3f;
- float stringLength = ;
- float speed = 4.0f;
- public void Update()
- {
- if (_text == null)
- return;
- if (refreshState == RefreshState.start)
- {
- _text.text = "";
- refreshState = RefreshState.show;
- }
- if (refreshState == RefreshState.show)
- {
- stringLength += Time.deltaTime * speed;
- int a = (int)(stringLength / 0.5f);
- if (a % == )
- {
- //_text.text = showstring.Substring(0, (int)stringLength) + "█";
- //_text.text = showstring.Substring(0, (int)stringLength) + "<color=#c6ff00ff>█</color>";
- string temp = showstring.Substring(, (int)stringLength);
- _text.text = temp.Substring(, (int)stringLength - );
- _text.text += "<color=#E7E7E9FF>" + temp.Substring((int)stringLength - , ) + "</color>";
- }
- else
- {
- _text.text = showstring.Substring(, (int)stringLength);
- }
- //_text.text = showstring.Substring(0, (int)stringLength);
- if(_text.text.Equals(showstring))
- {
- //结束
- stringLength = ;
- refreshState = RefreshState.delay;
- }
- }
- if (refreshState == RefreshState.delay)
- {
- stringLength += Time.deltaTime;
- if(stringLength>=timer)
- {
- refreshState = RefreshState.end;
- }
- }
- if(refreshState == RefreshState.end)
- {
- stringLength = ;
- if(!showstring.Equals(current))
- {
- showstring = current;
- }
- refreshState = RefreshState.start;
- }
- }
- enum RefreshState
- {
- start,
- show,
- delay,
- end
- }
- }
unity 中让Text的文字动态刷新形式的更多相关文章
- 3D语音天气球(源码分享)——在Unity中使用Android语音服务
转载请注明本文出自大苞米的博客(http://blog.csdn.net/a396901990),谢谢支持! 开篇废话: 这个项目准备分四部分介绍: 一:创建可旋转的"3D球":3 ...
- Unity中的万能对象池
本文为博主原创文章,欢迎转载.请保留博主链接http://blog.csdn.net/andrewfan Unity编程标准导引-3.4 Unity中的万能对象池 本节通过一个简单的射击子弹的示例来介 ...
- Unity中的GC以及优化
[简介] 常见的 Unity GC 知识点总结出来的思维导图 Unity 官方文档,正巧在博客园发现了已经有位大神(zblade)把原文翻译出来了,而且质量很高~,译文地址 在这里.下面我就可耻地把译 ...
- 关于Unity中的Bmpfont的使用
系统字体,不占空间,效果一般. 自己拖的.TTF文件形成的字体,占空间很大,有特殊效果.一个TTF字库差不多占用3M左右,之所以这么大,是因为里面包含了所有的字,就像一本字典一样,所以字符都在里面. ...
- 浅谈Unity中的GC以及优化
介绍: 在游戏运行的时候,数据主要存储在内存中,当游戏的数据不在需要的时候,存储当前数据的内存就可以被回收再次使用.内存垃圾是指当前废弃数据所占用的内存,垃圾回收(GC)是指将废弃的内存重新回收再次使 ...
- Unity中对SQL数据库的操作
在Unity中,我们有时候需要连接数据库来达到数据的读取与储存.而在.NET平台下,ADO.NET为我们提供了公开数据访问服务的类.客户端应用程序可以使用ADO.NET来连接到数据源,并查询,添加,删 ...
- 关于Unity中的UGUI优化,你可能遇到这些问题
https://blog.uwa4d.com/archives/QA_UGUI-1.html 关于Unity中的UGUI优化,你可能遇到这些问题 作者:admin / 时间:2016年11月08日 / ...
- 解读Unity中的CG编写Shader系列3——表面剔除与剪裁模式
在上一个样例中,我们得到了由mesh组件传递的信息经过数学转换至合适的颜色区间以颜色的形式着色到物体上. 这篇文章将要在此基础上研究片段的擦除(discarding fragments)和前面剪裁.后 ...
- Unity TextMeshPro替代Text组件创建简体中文字体纹理集
Unity原生的Text组件有一个毛病,只要文本放大字体放大就会有毛边或锯齿,一个更好的解决方案是用TextMeshPro替代ugui中的Text组件. TMPro采用SDF文字渲染技术,可以使文字放 ...
随机推荐
- HTTP 400错误--请求无效
在发送请求后台数据时会报出来HTTP400错误,请求无效,出现这个请求无效报错说明请求没有进入到后台服务里 原因:1.前端提交数据的字段名称或者是字段类型和后台的实体类不一致.导致无法封装 2.前端提 ...
- cv2.getRotationMatrix2D函数
- Docker Swarm Mode 学习笔记 (部署服务)
使用 docker service 命令来管理 Swarm 集群中的服务,该命令只能在管理节点上执行. 新建服务 docker service create --replicas 3 -p 80:80 ...
- Eclipse使用Maven,创建项目出现:Could not calculate build plan: Plugin org.apache.maven.plugins:maven-resour
使用maven创建简单的项目时候经常会遇到 Could not calculate build plan: Plugin org.apache.maven.plugins:maven-resource ...
- Go 参数传递是传值还是传引用
什么是传值(值传递)? 传值的意思是:函数传递的总是原来这个东西的一个副本.一个副拷贝.比如我们传递一个 int 类型的参数,传递 的其实这个参数的一个副本:传递一个指针类型的参数,其实传递的是这个指 ...
- JS及相关控件
1.radio 1)不选中任何值 2)获取选中的值 3)让某个选项选中 4)发生改变时的事件 5)让某个选项不能选 2.CheckBox 1)选中 2)取消 3.select 1)获取下拉框选中项的显 ...
- 使用VSCode调试Jest
0. 环境 Node版本:8.12.0 操作系统:windows10 1. 配置launch.json { "version": "0.2.0", " ...
- tomcat中显示本地图片①(已解决)
解决方案 我直接放源码了. 原理就是:我虽然调用的是虚拟目录,但是会映射到对应路径的实际 第一步:(在tomcat的 server.xml中创建一个虚拟目录) 虚拟目录创建方式: <Contex ...
- kubernetes1.13.5安装部署
Kubernetes 一. Kubernetes介绍 各节点所需组件 Master:docker,kubeadm,kubelet, 组件 版本 备注 Kubelet 1.13.5 组件 Kube ...
- Project Euler 66: Diophantine equation
题目链接 思路: 连分数求佩尔方程最小特解 参考博客 模板: LL a[]; bool min_pell(LL d, LL &x, LL &y) { LL m = floor(sqrt ...