当前位置:网站首页>Unity text superscript square representation +text judge whether the text is empty
Unity text superscript square representation +text judge whether the text is empty
2022-07-04 07:48:00 【Little sun works hard every day】
Code
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()
{
// Determines if the input value is null
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 Edit is empty ");
}
else if (!valueOfAText.Equals(""))
{
Debug.Log("A Edit is not empty ");
}
if (IsSpace(valueOfBText))
{
Debug.Log("B Edit is empty ");
}
else if (!valueOfBText.Equals(""))
{
Debug.Log("B Edit is not empty ");
}
if (IsSpace(valueOfCText))
{
Debug.Log("C Edit is empty ");
}
else if (!valueOfCText.Equals(""))
{
Debug.Log("C Edit is not empty ");
}
if (IsSpace(valueOfDText))
{
Debug.Log("D Edit is empty ");
}
else if (!valueOfDText.Equals(""))
{
Debug.Log("D Edit is not empty ");
}
if(!IsSpace(valueOfAText)&& !IsSpace(valueOfBText) && !IsSpace(valueOfCText) && !IsSpace(valueOfDText))
{
return true;
}else
{
return false;
}
}
public void clickComputeBtn()
{
// Judge whether the value is empty
if(JudgeValue())
{ // Calculation
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);
}
// Detect spaces
private bool IsSpace(string textValue)
{
if (textValue.Trim().Length == 0)// Remove the spaces at the beginning and end of the string
{
return true;
}
return false;
}
}
Demo picture



边栏推荐
- MySQL 数据库 - 函数 约束 多表查询 事务
- 人生规划(Flag)
- Routing decorator of tornado project
- 大学阶段总结
- Project 1 household accounting software (goal + demand description + code explanation + basic fund and revenue and expenditure details record + realization of keyboard access)
- Take you to master the formatter of visual studio code
- 21个战略性目标实例,推动你的公司快速发展
- R language ggplot2 visualization: ggplot2 visualization grouping box diagram, place the legend and title of the visualization image on the top left of the image and align them to the left, in which th
- Unity-Text上标平方表示形式+text判断文本是否为空
- L1-024 the day after tomorrow (5 points)
猜你喜欢
![[performance test] read JMeter](/img/c9/25a0df681c7ecb4a0a737259c882b3.png)
[performance test] read JMeter

Routing decorator of tornado project

Zabbix agent主动模式的实现

【Go基础】1 - Go Go Go
![[real case] how to deal with the failure of message consumption?](/img/ec/2bb2f0ff53c586bf45f364210658d7.jpg)
[real case] how to deal with the failure of message consumption?

MySQL中的文本處理函數整理,收藏速查

Zephyr study notes 2, scheduling

Comparison between applet framework and platform compilation

1. Qt入门

弈柯莱生物冲刺科创板:年营收3.3亿 弘晖基金与淡马锡是股东
随机推荐
R language ggplot2 visualization: ggplot2 visualization grouping box diagram, place the legend and title of the visualization image on the top left of the image and align them to the left, in which th
[Gurobi] 简单模型的建立
Scanf read in data type symbol table
【性能测试】一文读懂Jmeter
SQL注入测试工具之Sqli-labs下载安装重置数据库报错解决办法之一(#0{main}thrown in D:\Software\phpstudy_pro\WWW\sqli-labs-……)
21个战略性目标实例,推动你的公司快速发展
1. Qt入门
Unity-写入Word
21 examples of strategic goals to promote the rapid development of your company
How to improve your system architecture?
猜数字游戏
Leetcode 23. Merge K ascending linked lists
在所有SwiftUI版本(1.0-4.0)中原生实现Charts图表视图之思路
The cloud native programming challenge ended, and Alibaba cloud launched the first white paper on application liveliness technology in the field of cloud native
Zabbix agent主动模式的实现
Relations courantes de la fiche de données d'exploitation pour les activités
How to write a summary of the work to promote the implementation of OKR?
Ecole bio rushes to the scientific innovation board: the annual revenue is 330million. Honghui fund and Temasek are shareholders
What determines vacuum permittivity and vacuum permeability? Why do these two physical quantities exist?
弈柯莱生物冲刺科创板:年营收3.3亿 弘晖基金与淡马锡是股东