当前位置:网站首页>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;
}
}
演示图片
边栏推荐
- 墨者学院-PHPMailer远程命令执行漏洞溯源
- Comparison between applet framework and platform compilation
- Routing decorator of tornado project
- ZABBIX monitoring system custom monitoring content
- 谷歌官方回应:我们没有放弃TensorFlow,未来与JAX并肩发展
- MYCAT middleware installation and use
- 节点基础~节点操作
- Two years ago, the United States was reluctant to sell chips, but now there are mountains of chips begging China for help
- zabbix监控系统部署
- ZABBIX monitoring system deployment
猜你喜欢
手写简易版flexible.js以及源码分析
深入浅出:了解时序数据库 InfluxDB
In the era of low code development, is it still needed?
墨者学院-Webmin未经身份验证的远程代码执行
How to send mail with Jianmu Ci
Introduction to sap commerce cloud B2B organization function
[Android reverse] function interception (use cache_flush system function to refresh CPU cache | refresh CPU cache disadvantages | recommended time for function interception)
ZABBIX monitoring system custom monitoring content
Take you to master the formatter of visual studio code
Zephyr Learning note 2, Scheduling
随机推荐
zabbix监控系统邮件报警配置
Leetcode (215) -- the kth largest element in the array
Activiti常見操作數據錶關系
Leetcode 23. 合并K个升序链表
Implementation of ZABBIX agent active mode
Oracle-存储过程与函数
2022-021ARTS:下半年开始
Introduction to neural network (Part 2)
zabbix监控系统部署
弈柯莱生物冲刺科创板:年营收3.3亿 弘晖基金与淡马锡是股东
Preliminary study on temporal database incluxdb 2.2
PCIE知识点-010:PCIE 热插拔资料从哪获取
L1-021 important words three times (5 points)
L1-028 judging prime number (10 points)
SQL foundation 9 [grouping data]
节点基础~节点操作
In the era of low code development, is it still needed?
ZABBIX monitoring system deployment
[FreeRTOS] FreeRTOS learning notes (7) - handwritten FreeRTOS two-way linked list / source code analysis
What are the work contents of operation and maintenance engineers? Can you list it in detail?