当前位置:网站首页>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;
}
}
演示图片
边栏推荐
- Improve the accuracy of 3D reconstruction of complex scenes | segmentation of UAV Remote Sensing Images Based on paddleseg
- Leetcode 23. 合并K个升序链表
- This monitoring system can monitor the turnover intention and fishing all, and the product page has 404 after the dispute appears
- window上用.bat文件启动项目
- Text processing function sorting in mysql, quick search of collection
- Advanced MySQL: Basics (5-8 Lectures)
- [freertos] freertos Learning notes (7) - written freertos bidirectionnel Link LIST / source analysis
- [FreeRTOS] FreeRTOS learning notes (7) - handwritten FreeRTOS two-way linked list / source code analysis
- 2022 - 021arts: début du deuxième semestre
- Write a thread pool by hand, and take you to learn the implementation principle of ThreadPoolExecutor thread pool
猜你喜欢
ZABBIX 5.0 monitoring client
Sqli labs download, installation and reset of SQL injection test tool one of the solutions to the database error (# 0{main}throw in d:\software\phpstudy_pro\www\sqli labs-...)
节点基础~节点操作
Go learning notes - constants
How to improve your system architecture?
Heap concept in JVM
博客停更声明
University stage summary
What are the work contents of operation and maintenance engineers? Can you list it in detail?
Improve the accuracy of 3D reconstruction of complex scenes | segmentation of UAV Remote Sensing Images Based on paddleseg
随机推荐
zabbix監控系統自定義監控內容
Rhcsa the next day
Easy to understand: understand the time series database incluxdb
[real case] how to deal with the failure of message consumption?
谷歌官方回应:我们没有放弃TensorFlow,未来与JAX并肩发展
zabbix监控系统邮件报警配置
Leetcode (215) -- the kth largest element in the array
Used on windows Bat file startup project
Zephyr 学习笔记2,Scheduling
SQL foundation 9 [grouping data]
Rapidjson reading and writing JSON files
Ecole bio rushes to the scientific innovation board: the annual revenue is 330million. Honghui fund and Temasek are shareholders
The IP bound to the socket is inaddr_ The meaning of any htonl (inaddr_any) (0.0.0.0 all addresses, uncertain addresses, arbitrary addresses)
ZABBIX monitoring system deployment
MySQL中的文本处理函数整理,收藏速查
大学阶段总结
How to improve your system architecture?
L1-024 the day after tomorrow (5 points)
促进OKR落地的工作总结该如何写?
Relations courantes de la fiche de données d'exploitation pour les activités