iis服务器助手广告广告
返回顶部
首页 > 资讯 > 精选 >unity怎么实现简单计算器
  • 334
分享到

unity怎么实现简单计算器

2023-06-20 20:06:38 334人浏览 独家记忆
摘要

本篇内容介绍了“Unity怎么实现简单计算器”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!本文实例为大家分享了unity实现简单计算器的具体

本篇内容介绍了“Unity怎么实现简单计算器”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!

本文实例为大家分享了unity实现简单计算器的具体代码,供大家参考,具体内容如下

using System.Text;using UnityEngine;using UnityEngine.UI;using DG.Tweening;using System;public class Calculator : MonoBehaviour{    public Text SpendText;    private StringBuilder spendPrice;//初始金额    private string rmbSymbol;    private float totalPrice, spendPrices;//总和,初始金额    private bool isFirstDecrease;//避免减为零后的第二次起不能为负    private bool? isPlusOrDecrease, countType;//点击加减符号,点击等号    public Button PointButton;     private int count;//限制最大输入数    private void Start()    {        spendPrice = new StringBuilder();        totalPrice = 0;        spendPrices = 0;        rmbSymbol = "<size='50'>&yen;</size> ";        isPlusOrDecrease = null;//true为加,false为减        countType = null;//true为加,false为减        isFirstDecrease = true;        count = 0;    }    public void PointButtonController(bool type)    {        PointButton.interactable = type;    }    public void InputNumber(int num)    {        //按钮        switch (num)        {            case 0:                if (count < 11)                {                    count++;                    spendPrice.Append("0");                    SpendText.DOText(rmbSymbol + spendPrice.ToString(), 0.1f);                }                break;            case 1:                if (count < 11)                {                    count++;                    spendPrice.Append("1");                    SpendText.DOText(rmbSymbol + spendPrice.ToString(), 0.1f);                }                break;            case 2:                if (count < 11)                {                    count++;                    spendPrice.Append("2");                    SpendText.DOText(rmbSymbol + spendPrice.ToString(), 0.1f);                }                break;            case 3:                if (count < 11)                {                    count++;                    spendPrice.Append("3");                    SpendText.DOText(rmbSymbol + spendPrice.ToString(), 0.1f);                }                break;            case 4:                if (count < 11)                {                    count++;                    spendPrice.Append("4");                    SpendText.DOText(rmbSymbol + spendPrice.ToString(), 0.1f);                }                break;            case 5:                if (count < 11)                {                    count++;                    spendPrice.Append("5");                    SpendText.DOText(rmbSymbol + spendPrice.ToString(), 0.1f);                }                break;            case 6:                if (count < 11)                {                    count++;                    spendPrice.Append("6");                    SpendText.DOText(rmbSymbol + spendPrice.ToString(), 0.1f);                }                break;            case 7:                if (count < 11)                {                    count++;                    spendPrice.Append("7");                    SpendText.DOText(rmbSymbol + spendPrice.ToString(), 0.1f);                }                break;            case 8:                if (count < 11)                {                    count++;                    spendPrice.Append("8");                    SpendText.DOText(rmbSymbol + spendPrice.ToString(), 0.1f);                }                break;            case 9:                if (count < 11)                {                    count++;                    spendPrice.Append("9");                    SpendText.DOText(rmbSymbol + spendPrice.ToString(), 0.1f);                }                break;            case 10:                if (count < 11)                {                    count += 2;                    spendPrice.Append("00");                    SpendText.DOText(rmbSymbol + spendPrice.ToString(), 0.1f);                }                break;            case 11://加                isPlusOrDecrease = true;                countType = true;                count = 0;                if (!spendPrice.ToString().Equals(""))                {                    if ((totalPrice + float.Parse(spendPrice.ToString()) < 99999999999) && !totalPrice.ToString().Contains("E"))                    {                                                PointButtonController(true);                        if (totalPrice != 0)//避免第一次点击加号时没反应                        {                            TotalCount();                        }                        CountNum();                    }                    else                    {                        count = 0;                        PointButtonController(true);                        totalPrice = 0;                        spendPrice.Clear();                        SpendText.DOText(rmbSymbol, 0);                        isFirstDecrease = true;                    }                }                break;            case 12://减                isPlusOrDecrease = false;                countType = false;                count = 0;                if (!spendPrice.ToString().Equals(""))                {                    if ((totalPrice + float.Parse(spendPrice.ToString()) < 99999999999) && !totalPrice.ToString().Contains("E"))                    {                        PointButtonController(true);                        if (totalPrice != 0)//避免第一次点击减号时没反应                        {                            TotalCount();                        }                        CountNum();                    }                    else                    {                        count = 0;                        PointButtonController(true);                        totalPrice = 0;                        spendPrice.Clear();                        SpendText.DOText(rmbSymbol, 0);                        isFirstDecrease = true;                    }                }                break;            case 13://点                PointButtonController(false);                spendPrice.Append(".");                SpendText.DOText(rmbSymbol + spendPrice.ToString(), 0.1f);                break;            case 14://等号                count = 0;                if (!spendPrice.ToString().Equals(""))                {                    if ((totalPrice + float.Parse(spendPrice.ToString()) < 9999999999) && !totalPrice.ToString().Contains("E"))                    {                        PointButtonController(true);                        TotalCount();                    }                    else                    {                        count = 0;                        PointButtonController(true);                        totalPrice = 0;                        spendPrice.Clear();                        SpendText.DOText(rmbSymbol, 0);                        isFirstDecrease = true;                    }                }                break;            case 15://清零                count = 0;                PointButtonController(true);                totalPrice = 0;                spendPrice.Clear();                SpendText.DOText(rmbSymbol, 0);                isFirstDecrease = true;                break;            default:                break;        }    }    public void CountNum()    {        if (spendPrice.ToString().StartsWith("0") || spendPrice.ToString().Equals(""))//去除开始的无效零        {            if (spendPrice.ToString().TrimStart('0') == "" || spendPrice.ToString().TrimStart('0').TrimEnd('0') == ".")//0000,00.00,0.,.0            {                spendPrices = 0;            }            else            {                spendPrices = float.Parse((float.Parse(spendPrice.ToString().TrimStart('0'))).ToString("f2"));            }        }        else        {            spendPrices = float.Parse((float.Parse(spendPrice.ToString())).ToString("f2"));        }        if (isPlusOrDecrease == true && totalPrice != 0 && spendPrices != 0)        {            totalPrice += spendPrices;            spendPrice.Clear();            SpendText.DOText(rmbSymbol + totalPrice.ToString(), 0.1f);            isPlusOrDecrease = null;        }        else if (isPlusOrDecrease == true && totalPrice == 0 && spendPrices != 0 && spendPrices != 0)        {            totalPrice = spendPrices;            spendPrice.Clear();        }                if (isPlusOrDecrease == false && totalPrice == 0 && spendPrices != 0 && isFirstDecrease)        {            totalPrice = spendPrices;            spendPrice.Clear();            isFirstDecrease = false;        }        else if (isPlusOrDecrease == false && spendPrices != 0)        {            totalPrice -= spendPrices;            spendPrice.Clear();            SpendText.DOText(rmbSymbol + totalPrice.ToString(), 0.1f);            isPlusOrDecrease = null;        }    }    public void TotalCount()    {        if (spendPrice.ToString().StartsWith("0") || spendPrice.ToString().Equals(""))        {            if (spendPrice.ToString().TrimStart('0') == "" || spendPrice.ToString().TrimStart('0').TrimEnd('0') == ".")            {                spendPrices = 0;            }            else            {                spendPrices = float.Parse((float.Parse(spendPrice.ToString().TrimStart('0'))).ToString("f2"));            }        }        else        {            spendPrices = float.Parse((float.Parse(spendPrice.ToString())).ToString("f2"));        }        if (spendPrices != 0)        {            if (countType == true)            {                totalPrice += spendPrices;            }            else if (countType == false)            {                totalPrice -= spendPrices;            }            spendPrice.Clear();            SpendText.DOText(rmbSymbol + totalPrice.ToString(), 0.1f);            countType = null;        }    }    //将科学计数法转化为普通数字    private Decimal ChangeDataToD(string strData)    {        Decimal dData = 0.0M;        if (strData.Contains("E"))        {            dData = Decimal.Parse(strData, System.Globalization.NumberStyles.Float);        }        return dData;    }}

unity怎么实现简单计算器

“unity怎么实现简单计算器”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注编程网网站,小编将为大家输出更多高质量的实用文章!

--结束END--

本文标题: unity怎么实现简单计算器

本文链接: https://www.lsjlt.com/news/299954.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • unity怎么实现简单计算器
    本篇内容介绍了“unity怎么实现简单计算器”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!本文实例为大家分享了unity实现简单计算器的具体...
    99+
    2023-06-20
  • unity实现简单计算器
    本文实例为大家分享了unity实现简单计算器的具体代码,供大家参考,具体内容如下 using System.Text; using UnityEngine; using Unit...
    99+
    2024-04-02
  • jQuery实现简单计算器
    本文实例为大家分享了jQuery实现简单计算器的具体代码,供大家参考,具体内容如下 基本功能: 1、计算器换肤,目前有白色(默认色)、绿色、蓝色、灰色、橙色几种颜色可供选择。 2、简...
    99+
    2024-04-02
  • PHP实现简单计算器
    目录 一、题目:  二、基本界面设计代码:  三、分析: 四、实现编程三个步骤 五、完整实现代码 一、题目:     题目描述:下列列表框中有+、-、*、/四种运算符,选择不同的运算符进行,单击计算按钮进行不同的计算。   二、基本界...
    99+
    2023-10-01
    php
  • Android实现简单计算器
    本文实例为大家分享了Android实现简单计算器的具体代码,供大家参考,具体内容如下 功能 1、加减乘除四则运算 2、归0 3、回退 4、即时运算 配置 在build.gradle...
    99+
    2024-04-02
  • Swift实现简单计算器
    本文实例为大家分享了Swift实现简单计算器的具体代码,供大家参考,具体内容如下 使用Storyboard 快速而又方便的进行控件的布局,功能操作简单的进行一些运算; 代码实现 //...
    99+
    2024-04-02
  • Vue怎么实现简单网页计算器
    这篇文章主要介绍“Vue怎么实现简单网页计算器”,在日常操作中,相信很多人在Vue怎么实现简单网页计算器问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”Vue怎么实现简单网页计算器”的疑惑有所帮助!接下来,请跟...
    99+
    2023-06-30
  • iOS怎么实现简单计算器功能
    本篇文章给大家分享的是有关iOS怎么实现简单计算器功能,小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着小编一起来看看吧。//  ZYAppDelegate.m// &...
    99+
    2023-06-29
  • 用javascript实现简单计算器
    本文实例为大家分享了javascript实现简单计算器的具体代码,供大家参考,具体内容如下 设计一个简单的计算器 代码 <body> <a>第一个...
    99+
    2024-04-02
  • swift实现简单的计算器
    本文实例为大家分享了swift实现简单计算器的具体代码,供大家参考,具体内容如下 代码 // //  ViewController.swift //  Calculator // ...
    99+
    2024-04-02
  • C#怎么实现简单的计算器功能
    这篇“C#怎么实现简单的计算器功能”文章的知识点大部分人都不太理解,所以小编给大家总结了以下内容,内容详细,步骤清晰,具有一定的借鉴价值,希望大家阅读完这篇文章能有所收获,下面我们一起来看看这篇“C#怎么实现简单的计算器功能”文章吧。1.界...
    99+
    2023-06-29
  • 怎么用Java实现简单计算器功能
    这篇文章主要讲解了“怎么用Java实现简单计算器功能”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“怎么用Java实现简单计算器功能”吧!一 项目说明实训目的:掌握 Java GUI 开发中的...
    99+
    2023-06-20
  • java swing怎么实现简单计算器界面
    这篇文章主要介绍“java swing怎么实现简单计算器界面”,在日常操作中,相信很多人在java swing怎么实现简单计算器界面问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”java&...
    99+
    2023-06-30
  • Vue实现简单网页计算器
    本文实例为大家分享了Vue实现简单网页计算器的具体代码,供大家参考,具体内容如下 案例描述 1、 考核知识点 2、 创建vue实例和对v-model内置指令的使用 3、 练习目标 创...
    99+
    2024-04-02
  • iOS实现简单计算器功能
    本文实例为大家分享了iOS实现简单计算器功能的具体代码,供大家参考,具体内容如下 //  ZYAppDelegate.m //  Calculator // //  Created ...
    99+
    2024-04-02
  • jQuery实现简单计算器功能
    本文实例为大家分享了jQuery实现简单计算器的具体代码,供大家参考,具体内容如下 要求: 代码: <html> <head>     <meta c...
    99+
    2024-04-02
  • HTML如何实现简单计算器
    本篇内容介绍了“HTML如何实现简单计算器”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!代码如下:   ...
    99+
    2024-04-02
  • Java实现一个简单计算器
    先来看看界面效果: 源码如下: package test1;   import java.awt.Frame; import java.awt.TextField; import ...
    99+
    2024-04-02
  • JSP实现简单网页计算器
    本文实例为大家分享了JSP实现简单网页计算器的具体代码,供大家参考,具体内容如下 一、构造一个简单的计算器,能够进行“+、—、*、/”运算 (1)...
    99+
    2024-04-02
  • Swift实现简单计算器项目
    本文实例为大家分享了Swift实现简单计算器项目的具体代码,供大家参考,具体内容如下 // //  ViewController.swift //  计算器 // //  Creat...
    99+
    2024-04-02
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作