示例#1
0
 //fileName = "Scene/1"
 public ResourceAsyncOperation loadLevel(string fileName, HandleFinishLoadLevel handle, string archiveName = "Level")
 {
     //使用assetbundle打包
     if (UsedAssetBundle)
     {
         //获取完整路径
         string completeName = ArchiveManager.Instance.getPath(archiveName, fileName);
         if (mLoadedResourceItem.ContainsKey(completeName))
         {
             DebugEx.LogError("why you load same level twice, maybe you have not unload last time!!!", ResourceCommon.DEBUGTYPENAME);
             return(null);
         }
         else
         {
             ResourceAsyncOperation operation = new ResourceAsyncOperation(ResourceRequestType.LOADLEVEL);
             mAllRequests.Enqueue(new ResourceRequest(completeName, ResourceType.LEVEL, handle, ResourceRequestType.LOADLEVEL, operation));
             return(operation);
         }
     }
     //不使用
     else
     {
         ResourceAsyncOperation operation = new ResourceAsyncOperation(ResourceRequestType.LOADLEVEL);
         mAllRequests.Enqueue(new ResourceRequest(fileName, ResourceType.LEVEL, handle, ResourceRequestType.LOADLEVEL, operation));
         return(operation);
     }
 }
示例#2
0
        private IEnumerator _loadLevel(string path, HandleFinishLoadLevel handle, ResourceType resourceType, ResourceAsyncOperation operation)
        {
            //使用assetbundle打包
            if (UsedAssetBundle)
            {
                //根据场景名称获取asset信息
                AssetInfo sceneAssetInfo = mAssetInfoManager.GetAssetInfo(path);
                //获取该包总大小
                operation.mAllDependencesAssetSize = mAssetInfoManager.GetAllAssetSize(sceneAssetInfo);

                //获取依赖的asset的索引
                foreach (int index in sceneAssetInfo.mDependencys)
                {
                    //根据索引获取依赖的Asset
                    AssetInfo depencyAsset     = mAssetInfoManager.GetAssetInfo(index);
                    string    depencyAssetName = depencyAsset.mName;

                    //加载场景依赖assetbundle
                    ResourceItem unit = _LoadImmediate(depencyAssetName, ResourceType.LEVEL);
                    operation.mLoadDependencesAssetSize += unit.AssetBundleSize;
                }

                //加载场景assetbundle
                int         scenAssetBundleSize = 0;
                byte[]      binary      = ResourceCommon.getAssetBundleFileBytes(path, ref scenAssetBundleSize);
                AssetBundle assetBundle = AssetBundle.LoadFromMemory(binary);
                if (!assetBundle)
                {
                    DebugEx.LogError("create scene assetbundle " + path + "in _LoadImmediate failed");
                }

                //添加场景大小
                operation.mLoadDependencesAssetSize += scenAssetBundleSize;

                AsyncOperation asyncOperation = SceneManager.LoadSceneAsync(ResourceCommon.getFileName(path, false));
                operation.asyncOperation = asyncOperation;
                yield return(asyncOperation);

                handleResponse();

                operation.asyncOperation = null;
                operation.mComplete      = true;
                operation.mResource      = null;

                if (null != handle)
                {
                    handle();
                }
            }
            //不使用
            else
            {
                ResourceItem level = new ResourceItem(null, 0, null, path, resourceType);

                //获取加载场景名称
                string         sceneName      = ResourceCommon.getFileName(path, true);
                AsyncOperation asyncOperation = SceneManager.LoadSceneAsync(sceneName);
                operation.asyncOperation = asyncOperation;
                yield return(asyncOperation);

                handleResponse();

                operation.asyncOperation = null;
                operation.mComplete      = true;

                if (null != handle)
                {
                    handle();
                }
            }
        }