当前位置:网站首页>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;
}
}
演示图片



边栏推荐
- 论文学习——基于极值点特征的时间序列相似性查询方法
- window上用.bat文件启动项目
- Common components of flask
- Introduction to sap commerce cloud B2B organization function
- L1-021 important words three times (5 points)
- Unity opens the explorer from the inspector interface, selects and records the file path
- MySQL中的文本处理函数整理,收藏速查
- [web security] nodejs prototype chain pollution analysis
- JVM -- class loading process and runtime data area
- Jianmu continuous integration platform v2.2.2 release
猜你喜欢

Système de surveillance zabbix contenu de surveillance personnalisé

Chrome is set to pure black

How to improve your system architecture?

ZABBIX monitoring system custom monitoring content

window上用.bat文件启动项目

Node foundation ~ node operation

It's healthy to drink medicinal wine like this. Are you drinking it right

BUUCTF(3)
![[network security] what is emergency response? What indicators should you pay attention to in emergency response?](/img/2e/96da79d82ae2c49a3a0ab9909467ac.jpg)
[network security] what is emergency response? What indicators should you pay attention to in emergency response?

博客停更声明
随机推荐
墨者学院-phpMyAdmin后台文件包含分析溯源
Flask 常用组件
[network security] what is emergency response? What indicators should you pay attention to in emergency response?
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
It's healthy to drink medicinal wine like this. Are you drinking it right
BUUCTF(3)
Introduction to sap commerce cloud B2B organization function
zabbix监控系统部署
OKR vs. KPI figure out these two concepts at once!
Introduction to rce in attack and defense world
JVM中堆概念
Used on windows Bat file startup project
L1-024 the day after tomorrow (5 points)
Heap concept in JVM
BibTex中参考文献种类
Blue Bridge Cup Quick sort (code completion)
Preliminary study on temporal database incluxdb 2.2
Amd RX 7000 Series graphics card product line exposure: two generations of core and process mix and match
Chrome is set to pure black
2022-021ARTS:下半年開始