public UniGameResourcesDownLoader AllocResourcesDownLoader_DontDestroyOnLoad() { UniGameResourcesDownLoader ret = AllocResourcesDownLoader(); UnityEngine.Object.DontDestroyOnLoad(ret.gameObject); return(ret); }
public IEnumerator LoadingGameSceneLevelAdditive(string packageName, string sceneName) { if (SceneLevelDownloader != null) { Debug.LogError("have other scene loader!"); yield break; } SceneLevelDownloader = AllocResourcesDownLoader_DontDestroyOnLoad(); yield return(StartCoroutine(SceneLevelDownloader.DownloadPackage(packageName))); Application.LoadLevelAdditive(sceneName); ReleaseResourcesDownLoader(SceneLevelDownloader); SceneLevelDownloader = null; }
public IEnumerator LoadingAssetObject(string packageName, string assetName, uint assetGuid, Type type, bool isInstantiate) { UniGameResourcesDownLoader loader = AllocResourcesDownLoader_DontDestroyOnLoad(); yield return(StartCoroutine(loader.DownloadPackage(packageName))); UniGameResourcesPackage package = UniGameResources.FindSystemResourcesPackageTable(packageName); if (package == null) { Debug.LogError(string.Format("not find package:{0}", packageName)); yield break; } UnityEngine.Object obj = null; package.LockPackage(); try { if (isInstantiate) { #if UNITY_4_3 || UNITY_4_6 obj = GameObject.Instantiate(package.currentAssetBundle.Load(assetName, type)); #else obj = GameObject.Instantiate(package.currentAssetBundle.LoadAsset(assetName, type)); #endif } else { #if UNITY_4_3 || UNITY_4_6 obj = package.currentAssetBundle.Load(assetName, type); #else obj = package.currentAssetBundle.LoadAsset(assetName, type); #endif } } catch (System.Exception ex) { Debug.LogError(ex.ToString()); } package.UnLockPackage(); loadingAssetTree.Add(assetGuid, obj); ReleaseResourcesDownLoader(loader); }
protected virtual IEnumerator BootingSystem() { //重新设置资源加载模式 UniGameResources.gameResourcesWorkMode = UniGameResources.GameResourcesWorkMode.Mode_Mobile; //语言支持模式 UniGameResources.gameResourcesWorkModeTwo = UniGameResources.GameResourcesWorkModeTwo.Mode_OutGameOptions; //更换成当前的资源加载支持对象 UniGameResources.uniGameResourcesSupport = new IUniGameResourcesSupport(); //启动协同程序装载包清单文件 UniGameResources.AllocResourcesDownLoadWorker(); yield return(StartCoroutine(UniGameResources.resourcesDownLoadWorker.LoadingGameAssetBundleInventoryPackageFile())); //显示启动页面 yield return(StartCoroutine(OpenGameBootFace())); //检测当前程序版本是否符合资源版本的要求 if (UniGameResources.produceInformation.SupportProgramVersion != UniGameResources.uniGameResourcesSupport.ProgramVersion) { bootingSystemStep = BootingSystemStep.Step_NeedInstallNewVersionProgram; yield break; } //装载要求强制装载的包,这些包不再卸载 List <string> packageList = new List <string>(8); Dictionary <uint, UniGameResourcesPackage> .Enumerator list = UniGameResources.systemResourcesPackageTable.GetEnumerator(); while (list.MoveNext()) { if (list.Current.Value.assetBundleExistType == UniGameResourcesPackage.AssetBundleExistType.ExistType_ConstraintInstall) { packageList.Add(list.Current.Value.packageName); } } list.Dispose(); if (packageList.Count != 0) { bootingSystemStep = BootingSystemStep.Step_ConstraintInstallPackage; constraintInstallDownloader = UniGameResources.resourcesDownLoadWorker.AllocResourcesDownLoader_DontDestroyOnLoad(); yield return(StartCoroutine(constraintInstallDownloader.DownloadPackageWithList(packageList))); } //进行强制下载的资源包 List <UniGameResourcesPackage> ConstraintDownloadPackageList = UniGameResources.ComparisonSystemResourcesPackageVersion(); if (ConstraintDownloadPackageList.Count != 0) { bootingSystemStep = BootingSystemStep.Step_ConstraintDownloadPackage; constraintDownloadDownloader = UniGameResources.resourcesDownLoadWorker.AllocResourcesDownLoader(); yield return(StartCoroutine(constraintDownloadDownloader.DownloadPackageWithList(ConstraintDownloadPackageList))); //下载完是需要卸载的 UniGameResources.resourcesDownLoadWorker.ReleaseResourcesDownLoader(constraintDownloadDownloader); constraintDownloadDownloader = null; } //保存一次当前资源包版本 UniGameResources.SaveSystemResourcesPackageVersion(); //全部处理完毕 bootingSystemStep = BootingSystemStep.Step_BootingOver; //示范代码下载并加载一个资源包内的场景 //yield return StartCoroutine(UniGameResources.resourcesDownLoadWorker.LoadingGameSceneLevelAdditiveAsync("scene_game", "game")); //资源加载工作全部完成,开始初始化程序 //这里GameRoot的初始化在GameRoot的静态构造函数里 //这里需要检测GameRoot是否加载完成了 GameRoot.GameRootInitializationSucceedEvent += OnGameRootInitializationSucceed; GameRoot.StartInitialization(); }
public void ReleaseResourcesDownLoader(UniGameResourcesDownLoader loader) { UnityEngine.Object.DestroyObject(loader.gameObject); }