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
}
}