//when_show_unit传入的是大于多少开始显示单位 public static string GetString(long num, int?maxDecimalsCount, long?whenShowUnit, List <NumberUnitInfo> numberUnitList = null) { if (whenShowUnit.HasValue && num >= whenShowUnit) { long whenShowUnitValue = whenShowUnit.Value; int maxDecimalsCountValue = maxDecimalsCount.GetValueOrDefault(NumberUnitUtil.Max_Decimals_Count); var isFuShu = num < 0; // 是否是负数 num = Math.Abs(num); var zhiShu = 0; // 指数 num = (long)Mathf.Floor(num); var getNum = num; while (true) { if (getNum < 10) { break; } getNum = (long)Mathf.Floor(getNum / 10f); zhiShu = zhiShu + 1; } float showNum; string showUnit; if ((zhiShu + 1) <= NumberUnitUtil.Init_Max_Integer_Count) { showNum = num; showUnit = StringConst.String_Empty; } else { var outZhiShu = zhiShu - NumberUnitUtil.Init_Max_Integer_Count; var showWeiShu = outZhiShu % NumberUnitUtil.Max_Integer_Count; showNum = Mathf.Floor(num / (Mathf.Pow(10, (zhiShu - showWeiShu - maxDecimalsCountValue - 1)))); showNum = Mathf.Floor((showNum + 5) / 10); showNum = showNum / (Mathf.Pow(10, maxDecimalsCountValue)); showUnit = NumberUnitUtil.GetNumberUnitInfoByZhiShu((int)(Mathf.Floor(zhiShu / 3f) * 3), numberUnitList); } var result = string.Format("{0}{1}", showNum, showUnit); if (isFuShu) // 如果是负数 { result = string.Format("-{0}", result); } return(result); } return(((long)Mathf.Floor(num)).ToString()); }
public override void Update(float deltaTime = 0, float unscaledDeltaTime = 0) { base.Update(deltaTime, unscaledDeltaTime); //LogCat.LogWarning(isUpdatingRes); if (!isUpdatingRes) { return; } while (downloadingRequestList.Count < Max_DownLoad_Num && needDownloadList.Count > 0) { var filePath = needDownloadList[needDownloadList.Count - 1]; needDownloadList.RemoveAt(needDownloadList.Count - 1); var resourceWebRequester = Client.instance.assetBundleManager.DownloadFileAsyncNoCache(URLSetting.Server_Resource_URL, filePath); resourceWebRequester.cache["file_path"] = filePath; downloadingRequestList.Add(resourceWebRequester); } for (var i = 0; i < downloadingRequestList.Count; i++) { var downloadingRequest = downloadingRequestList[i]; needDownloadDict[downloadingRequest.cache.Get <string>("file_path")]["downloded_bytes"] = downloadingRequest.GetDownloadedBytes(); } long currentDownloadedBytes = 0; foreach (var keyValue in needDownloadDict) { var download = keyValue.Value; currentDownloadedBytes += download.GetOrGetDefault2 <long>("downloded_bytes", () => (long)0); } Client.instance.uiManager.uiLoadingPanel.SetDesc(string.Format("{0}/{1}", NumberUnitUtil.GetString(currentDownloadedBytes, 2, 1000), NumberUnitUtil.GetString(totalNeedDownloadBytes, 1, 1000))); }