示例#1
0
        public new bool Update()
        {
            if (m_Request != null)
            {
                CRequest.SetProgress(request, m_Request.progress);
                if (!allowSceneActivation && LoaderType.Typeof_ABScene.Equals(request.assetType) && m_Request.progress >= 0.9f)//加载场景的时候如果allowSceneActivation = false 只能通过progress判断完成
                {
                    return(false);
                }
                else
                {
                    return(!m_Request.isDone);
                }
            }

            string assetName       = request.assetName;
            string assetBundleName = request.assetBundleName;

            if (LoaderType.Typeof_ABScene.Equals(request.assetType)) //加载场景
            {
                var levelPaths = UnityEditor.AssetDatabase.GetAssetPathsFromAssetBundleAndAssetName(assetBundleName, assetName);

                if (levelPaths.Length == 0)
                {
                    CRequest.SetError(request, string.Format("There is no scene with name \"" + assetName + "\" in " + assetBundleName));
                    Debug.LogError(request.error);
                }
                else
                {
                    LoadSceneParameters loadSceneParameters = new LoadSceneParameters();
                    loadSceneParameters.loadSceneMode = loadSceneMode;
                    m_Request = UnityEditor.SceneManagement.EditorSceneManager.LoadSceneAsyncInPlayMode(levelPaths[0], loadSceneParameters);
                    m_Request.allowSceneActivation = allowSceneActivation;
                    CRequest.SetData(request, m_Request);
                    CRequest.SetProgress(request, m_Request.progress);
                    CacheManager.AddScene(request.assetName, request.assetBundleName);//缓存场景
                    if (!allowSceneActivation)
                    {
                        CacheManager.AddLoadingScene(request.assetName, m_Request);
                    }
                }
            }
            else //加载资源
            {
                StartSync();
                m_isDone = true;//标记完成
                return(false);
            }

            return(false);
        }
示例#2
0
        public bool Update()
        {
            if (m_Request != null)
            {
                CRequest.SetProgress(request, m_Request.progress);
                if (!allowSceneActivation && LoaderType.Typeof_ABScene.Equals(request.assetType) && m_Request.progress >= 0.9f)//加载场景的时候如果allowSceneActivation = false 只能通过progress判断完成
                {
                    return(false);
                }
                else
                {
                    return(!m_Request.isDone);
                }
            }

#if UNITY_EDITOR
            if (m_isDone)
            {
                return(false);          //only for editor 模拟模式使用
            }
#endif
            if (m_Bundle == null)
            {
                m_Bundle = CacheManager.TryGetCache(request.assetBundleName);
            }

            if (m_Bundle == null || !m_Bundle.isDone /* || !CacheManager.CheckDependenciesComplete(request.assetBundleName)*/)
            {
                return(true);     //wait bundle done
            }
            if (!m_Bundle.canUse) //ab失效
            {
                CRequest.SetError(request, string.Format("load asset({0}) from bundle({1}).canUse = false  error", request.assetName, request.assetBundleName));
                Debug.LogError(request.error);
                return(false);
            }
            else
            {
                string assetName = request.assetName;
                var    typ       = request.assetType;

                if (LoaderType.Typeof_ABScene.Equals(typ))
                {
                    m_Request = SceneManager.LoadSceneAsync(assetName, loadSceneMode);
                    m_Request.allowSceneActivation = allowSceneActivation;
                    CRequest.SetData(request, m_Request);                              //加载场景比较特殊 提前返回AsyncOperation对象方便操作
                    CacheManager.AddScene(request.assetName, request.assetBundleName); //缓存场景
                    if (!allowSceneActivation)
                    {
                        CacheManager.AddLoadingScene(request.assetName, m_Request);
                    }
                }
                else if (subAssets)
                {
                    m_Request = m_Bundle.assetBundle.LoadAssetWithSubAssetsAsync(assetName, typ);
                }
                else
                {
                    m_Request = m_Bundle.assetBundle.LoadAssetAsync(assetName, typ);
                }
                // #if HUGULA_LOADER_DEBUG
                //                 // HugulaDebug.FilterLogFormat (cRequest.key, " <color=#15A0A1> 1.2 Asset  Request(assetName={0}) is done={1} key={2},frame={3} </color>", cRequest.assetName, m_Request.isDone, cRequest.key, Time.frameCount);
                // #endif
                // GS_GameLog.LogFormat("LoadAssetAsync({0},{1}) m_Request.isDone={2}", assetName, typ, m_Request.isDone);
                CRequest.SetProgress(request, m_Request.progress);

                return(!m_Request.isDone);
            }
        }