最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

unity實現(xiàn)簡單計算器

 更新時間:2021年08月08日 15:06:59   作者:BackyStone  
這篇文章主要為大家詳細(xì)介紹了unity實現(xiàn)簡單計算器,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了unity實現(xiàn)簡單計算器的具體代碼,供大家參考,具體內(nèi)容如下

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;//避免減為零后的第二次起不能為負(fù)
    private bool? isPlusOrDecrease, countType;//點擊加減符號,點擊等號
    public Button PointButton; 
    private int count;//限制最大輸入數(shù)
    private void Start()
    {
        spendPrice = new StringBuilder();
        totalPrice = 0;
        spendPrices = 0;
        rmbSymbol = "<size='50'>¥</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)//避免第一次點擊加號時沒反應(yīng)
                        {
                            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)//避免第一次點擊減號時沒反應(yīng)
                        {
                            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;
        }
    }
    //將科學(xué)計數(shù)法轉(zhuǎn)化為普通數(shù)字
    private Decimal ChangeDataToD(string strData)
    {
        Decimal dData = 0.0M;
        if (strData.Contains("E"))
        {
            dData = Decimal.Parse(strData, System.Globalization.NumberStyles.Float);
        }
        return dData;
    }
}

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

您可能感興趣的文章:

相關(guān)文章

  • C#制作二維柱狀圖方法

    C#制作二維柱狀圖方法

    在本文里小編為各位分享的是關(guān)于C#制作二維柱狀圖方法和步驟,需要的讀者們學(xué)習(xí)下。
    2018-12-12
  • C#上位機(jī)與三菱PLC通訊的實現(xiàn)步驟(圖文)

    C#上位機(jī)與三菱PLC通訊的實現(xiàn)步驟(圖文)

    這篇文章主要介紹了C#上位機(jī)與三菱PLC通訊的實現(xiàn)步驟(圖文),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2021-02-02
  • c# 通過代碼開啟或關(guān)閉防火墻

    c# 通過代碼開啟或關(guān)閉防火墻

    這篇文章主要介紹了c# 通過代碼開啟或關(guān)閉防火墻的示例,幫助大家更好的理解和使用c#,感興趣的朋友可以了解下
    2020-10-10
  • C#使用SQLite進(jìn)行大數(shù)據(jù)量高效處理的代碼示例

    C#使用SQLite進(jìn)行大數(shù)據(jù)量高效處理的代碼示例

    在軟件開發(fā)中,高效處理大數(shù)據(jù)量是一個常見且具有挑戰(zhàn)性的任務(wù),SQLite因其零配置、嵌入式、跨平臺的特性,成為許多開發(fā)者的首選數(shù)據(jù)庫,本文將深入探討如何使用SQLite優(yōu)化大數(shù)據(jù)量的存儲和檢索,,需要的朋友可以參考下
    2025-04-04
  • C#實現(xiàn)常見加密算法的示例代碼

    C#實現(xiàn)常見加密算法的示例代碼

    這篇文章主要為大家詳細(xì)介紹一下C#中一些常見加密算法(Base64編碼、凱撒密碼、Vigenere密碼、DES、AES)以及它們的實現(xiàn)代碼,感興趣的可以了解一下
    2022-07-07
  • C#使用異步流高效處理序列數(shù)據(jù)的方法詳解

    C#使用異步流高效處理序列數(shù)據(jù)的方法詳解

    C#中的異步流(Async Streams),異步流是C# 8.0引入的一個新特性,它允許你異步地處理序列數(shù)據(jù),非常適合處理大量數(shù)據(jù)或長時間運行的任務(wù),本文給大家介紹了C#使用異步流高效處理序列數(shù)據(jù)的方法步驟,需要的朋友可以參考下
    2024-11-11
  • 深入解析C#設(shè)計模式中對橋接模式的具體運用

    深入解析C#設(shè)計模式中對橋接模式的具體運用

    這篇文章主要介紹了C#設(shè)計模式中對橋接模式的具體運用,橋接模式所強(qiáng)調(diào)的解耦在代碼維護(hù)中非常有用,需要的朋友可以參考下
    2016-02-02
  • Unity中3DText顯示模糊不清的解決方案

    Unity中3DText顯示模糊不清的解決方案

    這篇文章主要介紹了Unity中3DText顯示模糊不清的解決方案,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2021-04-04
  • c#實現(xiàn)KTV點歌系統(tǒng)

    c#實現(xiàn)KTV點歌系統(tǒng)

    這篇文章主要用C#語言編寫的KTV點歌系統(tǒng),需要的朋友可以參考下
    2015-07-07
  • C# 獲取枚舉值的簡單實例

    C# 獲取枚舉值的簡單實例

    這篇文章介紹了C# 獲取枚舉值的簡單實例,有需要的朋友可以參考一下
    2013-09-09

最新評論

衡阳县| 潮州市| 合川市| 乐东| 磐安县| 万宁市| 贡觉县| 福泉市| 桐柏县| 龙井市| 巴东县| 鄂托克前旗| 长丰县| 苏尼特右旗| 都昌县| 高尔夫| 道孚县| 乌海市| 青川县| 涿鹿县| 巫溪县| 五峰| 靖安县| 仙居县| 盈江县| 大洼县| 措勤县| 慈溪市| 当雄县| 沽源县| 慈溪市| 兴义市| 铜山县| 留坝县| 河北省| 西乌珠穆沁旗| 天镇县| 佛山市| 什邡市| 阆中市| 黔江区|