Example #1
0
        /// <summary>
        /// 加载场景
        /// </summary>
        /// <param name="sceneId">场景编号</param>
        /// <param name="showLoadingForm">是否显示Loading</param>
        /// <param name="onComplete">加载完毕</param>
        public void LoadScene(int sceneId, bool showLoadingForm = false, BaseAction onComplete = null)
        {
            if (m_CurrSceneIsLoading)
            {
                GameEntry.LogError("场景{0}正在加载中", m_CurrLoadSceneId);
                return;
            }

            if (m_CurrLoadSceneId == sceneId)
            {
                GameEntry.LogError("正在重复加载场景{0}", sceneId);
                return;
            }

            m_CurrLoadingParam = GameEntry.Pool.DequeueClassObject <BaseParams>();
            m_OnComplete       = onComplete;

            if (showLoadingForm)
            {
                //加载Loading
                GameEntry.UI.OpenUIForm(UIFormId.Loading, onOpen: (UIFormBase form) =>
                {
                    DoLoadScene(sceneId);
                });
            }
            else
            {
                DoLoadScene(sceneId);
            }
        }
Example #2
0
        /// <summary>
        /// 根据资源分类和资源路径获取资源信息
        /// </summary>
        /// <param name="assetCategory">资源分类</param>
        /// <param name="assetFullName">资源路径</param>
        /// <returns>资源信息</returns>
        public AssetEntity GetAssetEntity(AssetCategory assetCategory, string assetFullName)
        {
            Dictionary <string, AssetEntity> dicCategory = null;

            if (m_AssetInfoDic.TryGetValue(assetCategory, out dicCategory))
            {
                AssetEntity entity = null;
                if (dicCategory.TryGetValue(assetFullName, out entity))
                {
                    return(entity);
                }
            }
            GameEntry.LogError("assetFullName=>{0}不存在", assetFullName);
            return(null);
        }
Example #3
0
        /// <summary>
        /// 下载多个文件
        /// </summary>
        /// <param name="lstUrl"></param>
        /// <param name="onDownloadMulitUpdate"></param>
        /// <param name="onDownloadMulitComplete"></param>
        public void BeginDownloadMulit(LinkedList <string> lstUrl, BaseAction <int, int, ulong, ulong> onDownloadMulitUpdate = null, BaseAction onDownloadMulitComplete = null)
        {
            m_OnDownloadMulitUpdate   = onDownloadMulitUpdate;
            m_OnDownloadMulitComplete = onDownloadMulitComplete;

            m_NeedDownloadList.Clear();
            m_DownloadMulitCurrSizeDic.Clear();

            m_DownloadMulitNeedCount = 0;
            m_DownloadMulitCurrCount = 0;

            m_DownloadMulitTotalSize = 0;
            m_DownloadMulitCurrSize  = 0;

            //1.把需要下载的加入下载队列
            for (LinkedListNode <string> item = lstUrl.First; item != null; item = item.Next)
            {
                string url = item.Value;
                AssetBundleInfoEntity entity = GameEntry.Resource.ResourceManager.GetAssetBundleInfo(url);
                if (entity != null)
                {
                    m_DownloadMulitTotalSize += entity.Size;
                    m_DownloadMulitNeedCount++;
                    m_NeedDownloadList.AddLast(url);
                    m_DownloadMulitCurrSizeDic[url] = 0;
                }
                else
                {
                    GameEntry.LogError("无效资源包=>" + url);
                }
            }

            //下载器数量 最多5个
            int routineCount = Mathf.Min(GameEntry.Download.DownloadRoutineCount, m_NeedDownloadList.Count);

            for (int i = 0; i < routineCount; i++)
            {
                DownloadRoutine routine = GameEntry.Pool.DequeueClassObject <DownloadRoutine>();

                string url = m_NeedDownloadList.First.Value;
                m_NeedDownloadList.RemoveFirst();

                AssetBundleInfoEntity entity = GameEntry.Resource.ResourceManager.GetAssetBundleInfo(url);
                routine.BeginDownload(url, entity, OnDownloadMulitUpdate, OnDownloadMulitComplete);
                m_DownloadRoutineList.AddLast(routine);
            }
        }
Example #4
0
        /// <summary>
        /// 每帧执行
        /// </summary>
        public void OnUpdate()
        {
            if (m_IsPause)
            {
                return;
            }

            if (Time.time > m_CurrRunTime + m_PauseTime + m_DelayTime)
            {
                GameEntry.LogError("当程序执行到这里的时候,表明已经第一次过了延迟时间");
                IsRuning      = true;
                m_CurrRunTime = Time.time;
                m_PauseTime   = 0;
                if (m_OnStar != null)
                {
                    m_OnStar();
                }
            }

            if (!IsRuning)
            {
                return;
            }

            if (Time.time > m_CurrRunTime + m_PauseTime)
            {
                m_CurrRunTime = Time.time + m_Interval;
                m_PauseTime   = 0;
                //以下代码 间隔m_Interval 时间 执行一次
                if (m_OnUpdate != null)
                {
                    m_OnUpdate(m_Loop - m_CurrLoop);
                }

                if (m_Loop > -1)
                {
                    m_CurrLoop++;
                    if (m_CurrLoop >= m_Loop)
                    {
                        Stop();
                    }
                }
            }
        }
Example #5
0
        /// <summary>
        /// 更新资源包请求
        /// </summary>
        private void UpdateAssetBundleCreateRequest()
        {
            if (m_CurrAssetBundleCreateRequest != null)
            {
                if (m_CurrAssetBundleCreateRequest.isDone)
                {
                    AssetBundle assetBundle = m_CurrAssetBundleCreateRequest.assetBundle;
                    if (assetBundle != null)
                    {
                        GameEntry.Log(LogCategory.Resource, "资源包=>{0} 加载完毕", m_CurrAssetBundleInfo.AssetBundleName);
                        Reset(); //一定要早点Reset

                        if (OnLoadAssetBundleComplete != null)
                        {
                            OnLoadAssetBundleComplete(assetBundle);
                        }
                    }
                    else
                    {
                        GameEntry.LogError("资源包=>{0} 加载失败", m_CurrAssetBundleInfo.AssetBundleName);
                        Reset();

                        if (OnLoadAssetBundleComplete != null)
                        {
                            OnLoadAssetBundleComplete(null);
                        }
                    }
                }
                else
                {
                    // 加载进度
                    if (OnAssetBundleCreateUpdate != null)
                    {
                        OnAssetBundleCreateUpdate(m_CurrAssetBundleCreateRequest.progress);
                    }
                }
            }
        }
Example #6
0
        /// <summary>
        /// 更新加载资源请求
        /// </summary>
        private void UpdateAssetBundleRequest()
        {
            if (m_CurrAssetBundleRequest != null)
            {
                if (m_CurrAssetBundleRequest.isDone)
                {
                    UnityEngine.Object obj = m_CurrAssetBundleRequest.asset;
                    if (obj != null)
                    {
                        GameEntry.Log(LogCategory.Resource, "资源=>{0} 加载完毕", obj.name);
                        Reset(); //一定要早点Reset

                        if (OnLoadAssetComplete != null)
                        {
                            OnLoadAssetComplete(obj);
                        }
                    }
                    else
                    {
                        GameEntry.LogError("资源=>{0} 加载失败", m_CurrAssetName);
                        Reset(); //一定要早点Reset

                        if (OnLoadAssetComplete != null)
                        {
                            OnLoadAssetComplete(obj);
                        }
                    }
                }
                else
                {
                    // 加载进度
                    if (OnAssetUpdate != null)
                    {
                        OnAssetUpdate(m_CurrAssetBundleRequest.progress);
                    }
                }
            }
        }
Example #7
0
        /// <summary>
        /// 下载单一文件
        /// </summary>
        /// <param name="url"></param>
        /// <param name="onUpdate"></param>
        /// <param name="onComplete"></param>
        public void BeginDownloadSingle(string url, BaseAction <string, ulong, float> onUpdate = null, BaseAction <string> onComplete = null)
        {
            AssetBundleInfoEntity entity = GameEntry.Resource.ResourceManager.GetAssetBundleInfo(url);

            if (entity == null)
            {
                GameEntry.LogError("无效资源包=>" + url);
                return;
            }

            DownloadRoutine routine = GameEntry.Pool.DequeueClassObject <DownloadRoutine>();

            routine.BeginDownload(url, entity, onUpdate, onComplete: (string fileUrl, DownloadRoutine r) =>
            {
                m_DownloadRoutineList.Remove(r);
                GameEntry.Pool.EnqueueClassObject(routine);
                if (onComplete != null)
                {
                    onComplete(fileUrl);
                }
            });
            m_DownloadRoutineList.AddLast(routine);
        }
Example #8
0
 public void Resume()
 {
     m_IsPause   = false;
     m_PauseTime = Time.time - m_LasetPauseTime;
     GameEntry.LogError("恢复运行 暂停了m_PauseTime" + m_PauseTime);
 }
Example #9
0
 public void Pause()
 {
     m_LasetPauseTime = Time.time;
     m_IsPause        = true;
     GameEntry.LogError("暂停运行");
 }
Example #10
0
        /// <summary>
        /// 更新
        /// </summary>
        public void OnUpdate()
        {
            if (m_UnityWebRequest == null)
            {
                return;
            }

            if (m_TotalSize == 0)
            {
                m_TotalSize = 0;
                ulong.TryParse(m_UnityWebRequest.GetResponseHeader("Content-Length"), out m_TotalSize);
            }

            if (!m_UnityWebRequest.isDone)
            {
                if (m_CurrDownloadedSize < m_UnityWebRequest.downloadedBytes)
                {
                    m_CurrDownloadedSize = m_UnityWebRequest.downloadedBytes;

                    this.Sava(m_UnityWebRequest.downloadHandler.data);

                    if (m_OnUpdate != null)
                    {
                        m_OnUpdate(m_CurrFileUrl, m_CurrDownloadedSize, m_CurrDownloadedSize / (float)m_TotalSize);
                    }
                }
                return;
            }

            if (m_UnityWebRequest.isNetworkError)
            {
                GameEntry.LogError("下载失败url=>{0} error=>{1}", m_UnityWebRequest.url, m_UnityWebRequest.error);
                Reset();
            }
            else
            {
                m_CurrDownloadedSize = m_UnityWebRequest.downloadedBytes;
                this.Sava(m_UnityWebRequest.downloadHandler.data, true);

                if (m_OnUpdate != null)
                {
                    m_OnUpdate(m_CurrFileUrl, m_CurrDownloadedSize, m_CurrDownloadedSize / (float)m_TotalSize);
                }

                Reset();

                File.Move(m_DownloadLocalFilePath, m_DownloadLocalFilePath.Replace(".temp", ""));
                m_DownloadLocalFilePath = null;

                if (PlayerPrefs.HasKey(m_CurrFileUrl))
                {
                    PlayerPrefs.DeleteKey(m_CurrFileUrl);
                }

                //写入本地版本文件
                GameEntry.Resource.ResourceManager.SaveVersion(m_CurrAssetBundleInfo);

                if (m_OnComplete != null)
                {
                    m_OnComplete(m_CurrFileUrl, this);
                }
            }
        }
Example #11
0
        /// <summary>
        /// 打开UI窗体
        /// </summary>
        /// <param name="uiFormId">formId</param>
        /// <param name="userData"></param>
        internal void OpenUIForm(int uiFormId, object userData = null, BaseAction <UIFormBase> onOpen = null)
        {
            if (IsExists(uiFormId))
            {
                return;
            }

            //1.读表
            Sys_UIFormEntity entity = GameEntry.DataTable.DataTableManager.Sys_UIFormDBModel.Get(uiFormId);

            if (entity == null)
            {
                GameEntry.LogError(uiFormId + "对应的UI窗体不存在");
                return;
            }

            UIFormBase formBase = GameEntry.UI.Dequeue(uiFormId);

            if (formBase == null)
            {
                //TODO:异步加载UI需要时间 此处需要处理过滤加载中的UI

                string assetPath = string.Empty;
                switch (GameEntry.Localization.CurrLanguage)
                {
                case YouYouLanguage.Chinese:
                    assetPath = entity.AssetPath_Chinese;
                    break;

                case YouYouLanguage.English:
                    assetPath = entity.AssetPath_English;
                    break;
                }

                LoadUIAsset(assetPath, (ResourceEntity resourceEntity) =>
                {
                    GameObject uiObj = Object.Instantiate((Object)resourceEntity.Target) as GameObject;

                    //把克隆出来的资源 加入实例资源池
                    GameEntry.Pool.RegisterInstanceResource(uiObj.GetInstanceID(), resourceEntity);

                    uiObj.transform.SetParent(GameEntry.UI.GetUIGroup(entity.UIGroupId).Group);
                    uiObj.transform.localPosition = Vector3.zero;
                    uiObj.transform.localScale    = Vector3.one;

                    formBase = uiObj.GetComponent <UIFormBase>();
                    formBase.Init(uiFormId, entity.UIGroupId, entity.DisableUILayer == 1, entity.IsLock == 1, userData);
                    m_OpenUIFormList.AddLast(formBase);

                    if (onOpen != null)
                    {
                        onOpen(formBase);
                    }
                });
            }
            else
            {
                formBase.gameObject.SetActive(true);
                formBase.Open(userData);
                m_OpenUIFormList.AddLast(formBase);

                if (onOpen != null)
                {
                    onOpen(formBase);
                }
            }
        }