Example #1
0
        protected override IEnumerator OnLoadAsync()
        {
            ABRes abR = ResMgr.Instance.GetRes <ABRes>(mABs[0]);

            if (abR == null || abR.Assetbundle == null)
            {
                Debug.LogError(">>>[ResKit]: Failed to Load Scene, Can't Find AssetBundle: " + mABs[0].ABName);
                OnLoadFail();
                yield break;
            }

            if (!abR.Assetbundle.isStreamedSceneAssetBundle)
            {
                Debug.LogErrorFormat(">>>[ResKit]: Failed to Load Scene, Can't find scene {0} in assetbundle {1}", Name.AssetName, abR.Name);
                OnLoadFail();
                yield break;
            }

            mLoadRequest = SceneManager.LoadSceneAsync(Name.AssetName, LoadSceneMode.Additive);
            yield return(mLoadRequest);

            if (mLoadRequest.isDone)
            {
                OnLoadSuccess();
            }
            else
            {
                Debug.LogError(">>>[ResKit]: Failed to Async Load Scene: " + Name.AssetName);
                OnLoadFail();
            }

            mLoadRequest = null;
        }
Example #2
0
        protected override bool OnLoadSync()
        {
            //Can't use simulation load, because the scene has to be added to BuildSettings for loading it when Play.
            //But then the scene will be built into app package, which is not wanted.
            //The scene only needs to be built into assetbundle.

            ABRes abR = ResMgr.Instance.GetRes <ABRes>(mABs[0]);

            if (abR == null || abR.Assetbundle == null)
            {
                Debug.LogError(">>>[ResKit]: Failed to Load Scene, Can't Find AssetBundle: " + mABs[0].ABName);
                OnLoadFail();
                return(false);
            }
            if (!abR.Assetbundle.isStreamedSceneAssetBundle)
            {
                Debug.LogErrorFormat(">>>[ResKit]: Failed to Load Scene, Can't find scene {0} in assetbundle {1}", Name.AssetName, abR.Name);
                OnLoadFail();
                return(false);
            }

            SceneManager.LoadScene(Name.AssetName, LoadSceneMode.Additive);
            OnLoadSuccess();
            return(true);
        }
Example #3
0
        protected override IEnumerator OnLoadAsync()
        {
            if (RefCount <= 0)
            {
                OnLoadFail();
                yield break;
            }

            if (ResMgr.SimulationMode)
            {
                SimulateLoad();
            }
            if (mAsset == null)
            {
                ABRes abR = ResMgr.Instance.GetRes <ABRes>(mABs[0]);
                if (abR == null || abR.Assetbundle == null)
                {
                    Debug.LogError(">>>[ResKit]: Failed to Load Asset, Can't Find AssetBundle: " + mABs[0].ABName);
                    OnLoadFail();
                    yield break;
                }

                //确保加载过程中依赖资源不被释放:目前只有AssetRes需要处理该情况
                HoldDependency();

                mLoadRequest = abR.Assetbundle.LoadAssetAsync(Name.AssetNameWithExtension);
                yield return(mLoadRequest);

                UnHoldDependency();

                if (mLoadRequest.isDone)
                {
                    mAsset = ((AssetBundleRequest)mLoadRequest).asset;
                }
                mLoadRequest = null;
            }

            if (mAsset == null)
            {
                Debug.LogError(">>>[ResKit]: Failed to Async Load Asset: " + Name.AssetNameWithExtension);
                OnLoadFail();
                yield break;
            }

            OnLoadSuccess();
        }
Example #4
0
        protected override bool OnLoadSync()
        {
            if (ResMgr.SimulationMode)
            {
                SimulateLoad();
            }

            if (mAsset == null)
            {
                ABRes abR = ResMgr.Instance.GetRes <ABRes>(mABs[0]);
                if (abR == null || abR.Assetbundle == null)
                {
                    if (abR != null && abR.State == eResState.Loading)
                    {
                        Debug.LogErrorFormat(">>>[ResKit]: Failed to Load Asset. AssetBundle {0} is async loading, please call SyncLoad after.", mABs[0].ABName);
                    }
                    else
                    {
                        Debug.LogError(">>>[ResKit]: Failed to Load Asset, Can't Find AssetBundle: " + mABs[0].ABName);
                    }

                    OnLoadFail();
                    return(false);
                }
                mAsset = abR.Assetbundle.LoadAsset(Name.AssetNameWithExtension);
            }

            if (mAsset == null)
            {
                Debug.LogError(">>>[ResKit]: Failed to Load Asset, Can't Find Asset: " + Name.AssetNameWithExtension);
                OnLoadFail();
                return(false);
            }

            OnLoadSuccess();
            return(true);
        }