当前位置:网站首页>Unity-Text上标平方表示形式+text判断文本是否为空
Unity-Text上标平方表示形式+text判断文本是否为空
2022-07-04 07:43:00 【小太阳每天都要很努力】
代码
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class textTest : MonoBehaviour
{
public Text text;
public Text aText;
public Text bText;
public Text cText;
public Text dText;
private string valueOfAText;
private string valueOfBText;
private string valueOfCText;
private string valueOfDText;
private double aValue=0;
private double bValue =0;
private double cValue =0;
private double dValue =0;
private double resultValue=0;
// Start is called before the first frame update
void Start()
{
text.text = "D(1)=189.65+69.01A-4.91B+19.99C+5.22D-3.08AB+20.62AC+1.57AD+3.75BC+2.67BD-1.57CD-36.32A" + "\u00B2" + "+0.25B" + "\u00B2" + "-15.8C" + "\u00B2" + "-24.38D" + "\u00B2";
}
public bool JudgeValue()
{
//判断输入值是否为空
valueOfAText = aText.GetComponent<Text>().text.ToString();
valueOfBText = bText.GetComponent<Text>().text.ToString();
valueOfCText = cText.GetComponent<Text>().text.ToString();
valueOfDText = dText.GetComponent<Text>().text.ToString();
if (IsSpace(valueOfAText))
{
Debug.Log("A编辑为空");
}
else if (!valueOfAText.Equals(""))
{
Debug.Log("A编辑不为空");
}
if (IsSpace(valueOfBText))
{
Debug.Log("B编辑为空");
}
else if (!valueOfBText.Equals(""))
{
Debug.Log("B编辑不为空");
}
if (IsSpace(valueOfCText))
{
Debug.Log("C编辑为空");
}
else if (!valueOfCText.Equals(""))
{
Debug.Log("C编辑不为空");
}
if (IsSpace(valueOfDText))
{
Debug.Log("D编辑为空");
}
else if (!valueOfDText.Equals(""))
{
Debug.Log("D编辑不为空");
}
if(!IsSpace(valueOfAText)&& !IsSpace(valueOfBText) && !IsSpace(valueOfCText) && !IsSpace(valueOfDText))
{
return true;
}else
{
return false;
}
}
public void clickComputeBtn()
{
//判断数值是否为空
if(JudgeValue())
{ //计算
ComputeValue();
}
}
public void ComputeValue()
{
aValue = Convert.ToSingle(aText.text.ToString());
bValue = Convert.ToSingle(bText.text.ToString());
cValue = Convert.ToSingle(cText.text.ToString());
dValue = Convert.ToSingle(dText.text.ToString());
if (double.TryParse(aText.text.ToString(), out aValue))
{
aValue = Double.Parse(aText.text.ToString());
}
if (double.TryParse(bText.text.ToString(), out bValue))
{
bValue = Double.Parse(bText.text.ToString());
}
if (double.TryParse(cText.text.ToString(), out cValue))
{
cValue = Double.Parse(cText.text.ToString());
}
if (double.TryParse(dText.text.ToString(), out dValue))
{
dValue = Double.Parse(dText.text.ToString());
}
resultValue = 189.65 + 69.01 * aValue - 4.91 * bValue + 19.99 * cValue + 5.22 * dValue
- 3.08 * aValue * bValue + 20.62 * aValue * cValue + 1.57 * aValue * dValue
+ 3.75 * bValue * cValue + 2.67 * bValue * dValue - 1.57 * cValue * dValue
- 36.32 * aValue * aValue + 0.25 * bValue * bValue - 15.8 * cValue * cValue - 24.38 * dValue * dValue;
Debug.Log(aValue);
Debug.Log(bValue);
Debug.Log(cValue);
Debug.Log(dValue);
Debug.Log(resultValue);
}
//检测空格
private bool IsSpace(string textValue)
{
if (textValue.Trim().Length == 0)//去掉字符串头尾的空格
{
return true;
}
return false;
}
}
演示图片
边栏推荐
- Would you like to go? Go! Don't hesitate if you like it
- JVM -- class loading process and runtime data area
- [Flink] temporal semantics and watermark
- How to reset IntelliSense in vs Code- How to reset intellisense in VS Code?
- Div hidden in IE 67 shows blank problem IE 8 is normal
- [gurobi] establishment of simple model
- L1-022 odd even split (10 points)
- socket inet_ pton() inet_ Ntop() function (a new network address translation function, which converts the expression format and numerical format to each other. The old ones are inet_aton(), INET_ ntoa
- This monitoring system can monitor the turnover intention and fishing all, and the product page has 404 after the dispute appears
- zabbix监控系统部署
猜你喜欢
Zephyr Learning note 2, Scheduling
How to improve your system architecture?
Routing decorator of tornado project
Rhcsa the next day
Do you know about autorl in intensive learning? A summary of articles written by more than ten scholars including Oxford University and Google
socket inet_ pton() inet_ Ntop() function (a new network address translation function, which converts the expression format and numerical format to each other. The old ones are inet_aton(), INET_ ntoa
大学阶段总结
zabbix監控系統自定義監控內容
zabbix监控系统邮件报警配置
Improve the accuracy of 3D reconstruction of complex scenes | segmentation of UAV Remote Sensing Images Based on paddleseg
随机推荐
How to use MOS tube to realize the anti reverse connection circuit of power supply
Advanced MySQL: Basics (5-8 Lectures)
[C language] open the door of C
User login function: simple but difficult
Blue Bridge Cup Quick sort (code completion)
Scanf read in data type symbol table
Devops Practice Guide - reading notes (long text alarm)
zabbix监控系统自定义监控内容
L1-027 rental (20 points)
Detailed introduction to the big changes of Xcode 14
Email alarm configuration of ZABBIX monitoring system
Directory of tornado
L1-024 the day after tomorrow (5 points)
Experience installing VMware esxi 6.7 under VMware Workstation 16
Routing decorator of tornado project
Flask 常用组件
Literature collation and thesis reading methods
I was pressed for the draft, so let's talk about how long links can be as efficient as short links in the development of mobile terminals
Introduction to sap commerce cloud B2B organization function
Practice (9-12 Lectures)