Exemple #1
0
        public GoldManager(int initialValue, float goldPerSecond)
        {
            Gold = initialValue;
            this.goldPerSecond = goldPerSecond;
            waitForUpdate      = new WaitForUpdate();

            AutoGenerate();
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="TimerCountdown"/> class.
        /// </summary>
        /// <param name="countdowned">The countdowned object.</param>
        /// <param name="description">The description.</param>
        /// <param name="countdownInitial">The initial value in seconds.</param>
        /// <exception cref="ArgumentNullException">countdowned</exception>
        public TimerCountdown(object countdowned, string description = "", float countdownInitial = 0)
        {
            Countdowned       = countdowned ?? throw new ArgumentNullException(nameof(countdowned));
            Description       = description;
            countdown         = countdownInitial;
            unityUpdateWaiter = new WaitForUpdate();
            timer             = new Timer(CountdownTick);

            if (countdownInitial > 0)
            {
                StartCountdown(countdownInitial);
            }
        }
 public static SimpleCoroutineAwaiter GetAwaiter(this WaitForUpdate instruction)
 {
     return(GetAwaiterReturnVoid(instruction));
 }
Exemple #4
0
    /// <summary>
    /// 开始更新资源
    /// </summary>
    private async void UpdateABFile()
    {
        float value = (downSizeVer) / (float)totalSizeVer;
        //每下载downloadNum个数的文件更新一次Ui
        int downloadNum = Math.Min(5, needUpdateList.Count);
        //需要下载的文件list
        List <ABDownLoad> downList = new List <ABDownLoad>();
        ABDownLoad        downLoad;
        ABResFile         file;
        //已完成的下载
        ulong loadCompleteSize = 0;
        //正在进行的下载
        ulong loadingSize = 0;
        //已经下载的总大小
        ulong         totalLoadSize     = 0;
        WaitForUpdate waitUpdate        = new WaitForUpdate();
        bool          isAllLoadComplate = false;
        //计算已下载的文件数
        int newDownloadSuccFile = 0;

        for (int i = 0; i < downloadNum; i++)
        {
            downLoad = new ABDownLoad(remoteVersion.ResURL);
            downList.Add(downLoad);
        }
        //Stopwatch(https://blog.csdn.net/qq_33574890/article/details/83344307)
        while (!isAllLoadComplate)
        {
            loadingSize = 0;
            for (int i = downList.Count; --i >= 0;)
            {
                downLoad = downList[i];
                //如果可以下载
                if (downLoad.IsCanDownload)
                {
                    //加到下载完成列表
                    if (downLoad.IsDownload)
                    {
                        newDownloadSuccFile++;
                    }
                    loadCompleteSize += downLoad.ByteDownloaded;
                    //还有资源没下载完成
                    if (needUpdateList.Count > 0)
                    {
                        file = needUpdateList.Dequeue();
                        downLoad.DownloadAsync(file);
                        await waitUpdate;
                    }
                    else
                    {
                        downList.RemoveAt(i);
                        break;
                    }
                }
                else
                {
                    loadingSize += downLoad.ByteDownloaded;
                }
            }
            //当前下载的总大小
            totalLoadSize = loadCompleteSize + loadingSize + downSizeVer;
            string str = string.Format("{0}/{1}", getSizeString(totalLoadSize), getSizeString(totalSizeVer));
            PanelMgr.Instance.GetPanel <VersionCheckPl>(PanelName.VersionCheckPl).VersionInfo.text = "正在下载中...";
            PanelMgr.Instance.GetPanel <VersionCheckPl>(PanelName.VersionCheckPl).SpeedText.text   = str;
            SetValue((totalLoadSize) / (float)totalSizeVer);
            await waitUpdate;
            if (downList.Count == 0)
            {
                saveABFileInfo(true);
                isAllLoadComplate = true;
                await new WaitForSeconds(0.5f);
                SetComplate(remoteABRes);
            }
        }
    }
Exemple #5
0
 public static YieldAwaiter <CustomYieldInstruction> GetAwaiter(this WaitForUpdate instruction)
 {
     return(new YieldAwaiter <CustomYieldInstruction>(instruction));
 }