当前位置:网站首页>Unity:文本输入框进行数值判定
Unity:文本输入框进行数值判定
2022-07-20 01:46:00 【小太阳每天都要很努力】
实现目标:对输入框中的数值进行判定
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Calculate : MonoBehaviour
{
public InputField zhiliangdenshu;//质量分数
public InputField dianya;//电压
public InputField liuliang;//流量
public InputField pentou_d;//喷头直径
public Text showText;
double dianyaValue;//电压值
double liuliangValue;//流量值
double pentou_dValue;//喷头直径
public void calculateValue()
{
if (IsSpace(zhiliangdenshu.text.ToString())||IsSpace(dianya.text.ToString())||IsSpace(liuliang.text.ToString()) ||IsSpace(liuliang.text.ToString()))//如果为空
{
showText.text="某项输入为空";
lineShow.SetActive(false);
}
else
{
dianyaValue = Convert.ToDouble(dianya.text.ToString());//string转为double
switch (zhiliangdenshu.text.ToString())//switch判断质量分数text字符串
{
case "4%":
if (( dianyaValue>15&&dianyaValue<19)&& (liuliangValue> 0.5f&&liuliangValue <2.0f) && (pentou_dValue> 0.5f&&pentou_dValue<1.0f))//判断数值区间
{
lineShow.transform.localScale = new Vector3(1.5f, 0.5f, 0.5f);
//图片大小形式设置
}
else
{
showText.text = "输入值不在测量范围内";
lineShow.SetActive(false);
}; break;
default:
showText.text = "质量分数输入有误";
lineShow.SetActive(false);
break;
}
}
}
//检测空格
private bool IsSpace(string textValue)
{
if (textValue.Trim().Length == 0)//去掉字符串头尾的空格
{
return true;
}
return false;
}
边栏推荐
- acwing 872. 最大公约数
- Detailed explanation of TestNG automated testing framework
- VMware 启动报错:Exception 0xc0000005和windwos11没有Hyper-V的解决方法
- 数据库系统原理与应用教程(027)—— MySQL 修改表中数据(三):改(update)
- Classes et objets (en haut)
- 数据库系统原理与应用教程(025)—— MySQL 修改表中数据(一):增(insert)
- 1002 A+B for Polynomials
- acwing 871. 约数之和
- 详解Redis的RDB和AOF
- Learn about spark project on nebulagraph
猜你喜欢
What are the three cache update strategies?
一文了解 NebulaGraph 上的 Spark 项目
软件测试如何快速入门
Applet: page scrolling to a certain position navigation bar fixed effect
Qt:Could not find qmake spec ‘default’. Error while parsing file xxx. pro. Giving up
【故事证明和概率公理】
程序环境和预处理详解
Encapsulation, inheritance, polymorphism
[probability and count]
acwing 872. 最大公约数
随机推荐
Introduction to audio and video -- Analysis of H.264 coding (macroblock + slice + frame)
vivo官网APP全机型UI适配方案
模糊照片秒变高清大图,飞桨PPDE带你复现图像恢复模型CMFNet
Difficulties and solutions of project management in complete electrical equipment manufacturing enterprises
The way to practice and play strange: the meaning of NPM global installation and local installation in nodejs, and the difference between global installation and local installation in NPM
一文了解 NebulaGraph 上的 Spark 项目
ORA-39194: Table mode jobs require the tables to be comma separated.
Translate official UE documents about uobject Foundation
xss漏洞的一些思考
redisconnectionfactory could not autowired
Blurred photos, second high-definition big picture, flying propeller ppde takes you to reproduce the image restoration model cmfnet
Xshell & putty color scheme
网络安全知识图谱关键技术
mim命令
acwing 871. 约数之和
一文搞懂MySQL架构设计,再也不用担心面试官问得太深
[model evaluation]
数据库系统原理与应用教程(027)—— MySQL 修改表中数据(三):改(update)
New features of globalization under the background of accelerated development of informatization
acwing 869. 试除法求约数