unity怎么在文本中修改字体_unity 中让Text的文字动态刷新形式

usingUnityEngine;usingSystem.Collections;usingUnityEngine.UI;public classSensorTextRefresh2

{//Use this for initialization

stringshowstring;publicText _text;public string otherName = "normal";stringcurrent;

RefreshState refreshState;int index = 0;public void Init(Text _t, string _s, int _index, string_otherName)

{

refreshState=RefreshState.start;

_s= float.Parse(_s).ToString("0.00");if (index == 0)

{

showstring=_s;

current=_s;

}else if (index == 1)

{//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 == 0)

{

current=_s;

_text.text= "";

_text.text=current;

}else if (index == 1)

{

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 = 0;float speed = 1.0f;int i = 0;public voidUpdate()

{if (_text == null)return;if (refreshState ==RefreshState.start)

{

_text.text= "";

refreshState=RefreshState.show;

}if (refreshState ==RefreshState.show)

{

stringLength+= Time.deltaTime *speed;if (stringLength <= 1)

{string temp = showstring.Substring(0, showstring.Length);//_text.text = temp.Substring(0, (int)stringLength - 1);//_text.text += "" + temp.Substring((int)stringLength - 1, 1) + "";

if (otherName.Contains("TP") || otherName.Contains("TF") || otherName.Contains("温度"))

{

_text.text= ("" + temp.Substring(0, showstring.Length) + "" + "℃");

}else if (otherName.Contains("PP") || otherName.Contains("PF") || otherName.Contains("压力"))

{

_text.text= "" + temp.Substring(0, 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= "" + temp.Substring(0, showstring.Length) + "" + "Hz";

}else if (otherName.Contains("电流"))

{

_text.text= "" + temp.Substring(0, showstring.Length) + "" + "A";

}

}else if (stringLength > 1 && stringLength <= 2)

{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(0, (int)showstring.Length) + "℃"; ;

}else if (otherName.Contains("PP") || otherName.Contains("PF") || otherName.Contains("压力"))

{

_text.text= showstring.Substring(0, (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(0, (int)showstring.Length) + "Hz";

}else if (otherName.Contains("电流"))

{

_text.text= showstring.Substring(0, (int)showstring.Length) + "A";

}

}if (stringLength > 3.0f)

{//结束

stringLength = 0;

refreshState=RefreshState.end;

}

}if (refreshState ==RefreshState.delay)

{

_text.text= "";

stringLength+=Time.deltaTime;if (stringLength >=timer)

{

refreshState=RefreshState.end;

}

}if (refreshState ==RefreshState.end)

{

stringLength= 0;if (!showstring.Equals(current))

{

showstring=current;

}

refreshState=RefreshState.start;

}

}enumRefreshState

{

start,

show,

delay,

end

}

}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值