using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Events; using UnityEngine.UI; public static class UIUtils { public static void BindBtn(Button pBtn, UnityAction pDel, AudioClipType pSound = AudioClipType.None) { pBtn.onClick.AddListener(pDel); pSound = AudioClipType.Click; pBtn.onClick.AddListener(() => { AudioManager.Instance.PlaySound(pSound); }); } public static void ShowTips(string pTips) { UIManager.Instance.OpenUI().ShowTips(pTips); } public static void ShowNoAdsTip() { ShowTips(LanguageConfig.Instance.GetText("NoAdsTip")); } public static void FlyCoin(Vector3 pPos, int pAdd) { PanelTopBar tTopUI = UIManager.Instance.GetUI(); if (tTopUI != null) { tTopUI.FlyCoin(pPos, pAdd); } } public static void DropCoin(int pDelta) { PanelTopBar tTopUI = UIManager.Instance.GetUI(); if (tTopUI != null) { tTopUI.PopCoin(-pDelta); } } public static void RefreshCoin() { PanelTopBar tTopUI = UIManager.Instance.GetUI(); if (tTopUI != null) { tTopUI.RefreshCoin(); } } const int BILLION = 1000000000; const int MILLION = 1000000; const int THOUSAND = 1000; public static string NumForShort(int pNum) { string tNumStr = pNum.ToString(); float tShortNum = 0; if (pNum >= BILLION) { tShortNum = pNum / (float)BILLION; tNumStr = (tShortNum - ((int)tShortNum)) >= 0.1f ? string.Format("{0:F1}B", tShortNum) : string.Format("{0}B", (int)tShortNum); } else if (pNum >= MILLION) { tShortNum = pNum / (float)MILLION; tNumStr = (tShortNum - ((int)tShortNum)) >= 0.1f ? string.Format("{0:F1}M", tShortNum) : string.Format("{0}M", (int)tShortNum); } else if (pNum >= THOUSAND * 10) { tShortNum = pNum / (float)THOUSAND; tNumStr = (tShortNum - ((int)tShortNum)) >= 0.1f ? string.Format("{0:F1}K", tShortNum) : string.Format("{0}K", (int)tShortNum); } return tNumStr; } }