当前位置:网站首页>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
边栏推荐
- Oracle stored procedures and functions
- 运动【跑步 01】一个程序员的半马挑战:跑前准备+跑中调整+跑后恢复(经验分享)
- Write a thread pool by hand, and take you to learn the implementation principle of ThreadPoolExecutor thread pool
- L1-022 odd even split (10 points)
- window上用.bat文件启动项目
- Zephyr learning notes 1, threads
- [Chongqing Guangdong education] National Open University spring 2019 770 real estate appraisal reference questions
- The frost peel off the purple dragon scale, and the xiariba people will talk about database SQL optimization and the principle of indexing (primary / secondary / clustered / non clustered)
- System architecture design of circle of friends
- NPM run build error
猜你喜欢
Text processing function sorting in mysql, quick search of collection
Practice (9-12 Lectures)
[gurobi] establishment of simple model
1、卡尔曼滤波-最佳的线性滤波器
博客停更声明
Zephyr learning notes 1, threads
zabbix監控系統自定義監控內容
MySQL中的文本處理函數整理,收藏速查
弈柯莱生物冲刺科创板:年营收3.3亿 弘晖基金与淡马锡是股东
Introduction to sap commerce cloud B2B organization function
随机推荐
1. Qt入门
[gurobi] establishment of simple model
Unity opens the explorer from the inspector interface, selects and records the file path
Unity-Text上标平方表示形式+text判断文本是否为空
MySQL中的文本處理函數整理,收藏速查
Improve the accuracy of 3D reconstruction of complex scenes | segmentation of UAV Remote Sensing Images Based on paddleseg
Basic DOS commands
In the era of low code development, is it still needed?
【Go基础】2 - Go基本语句
zabbix監控系統自定義監控內容
ZABBIX monitoring system deployment
Practice (9-12 Lectures)
Is l1-029 too fat (5 points)
论文学习——基于极值点特征的时间序列相似性查询方法
Easy to understand: understand the time series database incluxdb
Advanced MySQL: Basics (5-8 Lectures)
Oracle-存储过程与函数
Detailed introduction to the big changes of Xcode 14
Leetcode (215) -- the kth largest element in the array
How to reset IntelliSense in vs Code- How to reset intellisense in VS Code?