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



边栏推荐
- [FreeRTOS] FreeRTOS learning notes (7) - handwritten FreeRTOS two-way linked list / source code analysis
- [Android reverse] function interception (use cache_flush system function to refresh CPU cache | refresh CPU cache disadvantages | recommended time for function interception)
- 21 examples of strategic goals to promote the rapid development of your company
- How to improve your system architecture?
- [Gurobi] 简单模型的建立
- Zephyr 学习笔记2,Scheduling
- L1-030 one gang one (15 points)
- ZABBIX monitoring system custom monitoring content
- 【Go基础】1 - Go Go Go
- zabbix監控系統自定義監控內容
猜你喜欢

With excellent strength, wangchain technology, together with IBM and Huawei, has entered the annual contribution list of "super ledger"!

In the era of low code development, is it still needed?

NPM run build error

University stage summary

Advanced MySQL: Basics (5-8 Lectures)

What are the work contents of operation and maintenance engineers? Can you list it in detail?

window上用.bat文件启动项目

BUUCTF(3)

This monitoring system can monitor the turnover intention and fishing all, and the product page has 404 after the dispute appears

Zephyr Learning note 2, Scheduling
随机推荐
Oceanbase is the leader in the magic quadrant of China's database in 2021
21个战略性目标实例,推动你的公司快速发展
2022-021ARTS:下半年开始
Handwritten easy version flexible JS and source code analysis
L1-021 important words three times (5 points)
Technical experts from large factories: common thinking models in architecture design
User login function: simple but difficult
Devops Practice Guide - reading notes (long text alarm)
神经网络入门(下)
Practice (9-12 Lectures)
Chrome is set to pure black
[Flink] temporal semantics and watermark
How to improve your system architecture?
rapidjson读写json文件
论文学习——基于极值点特征的时间序列相似性查询方法
The idea of implementing charts chart view in all swiftui versions (1.0-4.0) was born
Tri des fonctions de traitement de texte dans MySQL, recherche rapide préférée
Types of references in BibTex
Blue Bridge Cup Quick sort (code completion)
Write a thread pool by hand, and take you to learn the implementation principle of ThreadPoolExecutor thread pool