public IEnumerator DownloadPackageWithList(List <string> list) { if (needDownloadPackageList.Count != 0 || overDownloadPackageList.Count != 0) { Debug.LogError("Is Have Loader Package!"); yield break; } if (list.Count == 0) { Debug.LogError("Download What?!"); yield break; } List <UniGameResourcesPackage> packageList = new List <UniGameResourcesPackage>(8); for (int i = 0; i < list.Count; i++) { UniGameResourcesPackage package = UniGameResources.FindSystemResourcesPackageTable(list[i]); if (package == null) { Debug.LogError(string.Format("not find package:{0}", list[i])); yield break; } packageList.Add(package); } yield return(StartCoroutine(DownloadPackageWithList(packageList))); }
private XmlDocument LoadResource_PublicXmlDocument(ref GameResourcesNode data, Encoding code) { if (UniGameResources.gameResourcesWorkMode == GameResourcesWorkMode.Mode_AloneSecurity) { try { #if _Develop XmlDocument doc = new XmlDocument(); doc.Load(UniGameResources.ConnectPath(UniGameResources.DataPath, data.packageName, "/", data.path)); return(doc); #else return(xmlPublicReaderSecurity.LoadXml(UniGameResources.ConnectPath(UniGameResources.DataPath, data.packageName, "/", data.path))); #endif//_Develop } catch (System.Exception ex) { Debug.LogError(ex.ToString()); return(null); } } else if (UniGameResources.gameResourcesWorkMode == GameResourcesWorkMode.Mode_Mobile) { UniGameResourcesPackage package = (UniGameResourcesPackage)data.package; package.LockPackage(); #if UNITY_4_3 || UNITY_4_6 TextAsset textAsset = package.currentAssetBundle.Load(data.path, typeof(TextAsset)) as TextAsset; #else TextAsset textAsset = package.currentAssetBundle.LoadAsset(data.path, typeof(TextAsset)) as TextAsset; #endif XmlDocument doc = null; try { byte[] xmldata = textAsset.bytes; xmldata = Convert.FromBase64String(Encoding.ASCII.GetString(xmldata)); //解密数据 #if _SupportDeviceVerify xmldata = xmlFileEncipher.FileDecrypt(xmldata, true); #else xmldata = xmlFileEncipher.FileDecrypt(xmldata); #endif //_SupportDeviceVerify //MemoryStream s = new MemoryStream(xmldata); doc = new XmlDocument(); doc.LoadXml(code.GetString(xmldata)); //s.Close(); } catch (System.Exception ex) { Debug.LogError(ex.ToString()); doc = null; } UniGameResources.ReleaseOneAssets(textAsset); package.UnLockPackage(); return(doc); } return(null); }
//给定一个xml文件用于建立资源包表 public static void BuildSystemResourcesPackageTable(XmlDocument doc) { XmlNode root = doc.SelectSingleNode("GameResourcesPackageList"); XmlNodeList nodelist = root.SelectNodes("Package"); for (int i = 0; i < nodelist.Count; i++) { UniGameResourcesPackage package = new UniGameResourcesPackage(nodelist[i]); systemResourcesPackageTable.Add(package.packageId, package); } produceInformation.Initialization(root.SelectSingleNode("ProduceInformation")); }
public void InitializationName(string luaScriptName, uint storeMethodMask, OnStoreMethod storeMethod) { try { if (UniGameResources.currentUniGameResources == null) { throw new Exception("UniGameResources.currentUniGameResources == null!"); } FTLibrary.Resources.GameResourcesNode data = new FTLibrary.Resources.GameResourcesNode(); if (!UniGameResources.currentUniGameResources.FindResources(UniGameResourcesDefine.ResourcesTypeIndex_LuaScript, luaScriptName, ref data)) { throw new Exception(string.Format("cant find lua script!name={0}", luaScriptName)); } if (UniGameResources.gameResourcesWorkMode == UniGameResources.GameResourcesWorkMode.Mode_AloneSecurity) { try { InitializationFile(data.path, storeMethodMask, storeMethod); } catch (System.Exception ex) { Debug.LogError(ex.ToString()); } } else if (UniGameResources.gameResourcesWorkMode == UniGameResources.GameResourcesWorkMode.Mode_Mobile) { UniGameResourcesPackage package = (UniGameResourcesPackage)data.package; package.LockPackage(); try { InitializationFile(data.path, storeMethodMask, storeMethod); } catch (System.Exception ex) { Debug.LogError(ex.ToString()); } package.UnLockPackage(); } } catch (System.Exception ex) { Debug.LogError(ex.ToString()); } }
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); }
private byte[] LoadResource_ByteFile(ref GameResourcesNode data) { if (UniGameResources.gameResourcesWorkMode == GameResourcesWorkMode.Mode_AloneSecurity) { try { string path = UniGameResources.ConnectPath(UniGameResources.DataPath, data.packageName, "/", data.path); FileStream file = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, 4096); byte[] buffer = new byte[file.Length]; file.Read(buffer, 0, buffer.Length); file.Close(); return(buffer); } catch (System.Exception ex) { Debug.LogError(ex.ToString()); return(null); } } else if (UniGameResources.gameResourcesWorkMode == GameResourcesWorkMode.Mode_Mobile) { UniGameResourcesPackage package = (UniGameResourcesPackage)data.package; package.LockPackage(); #if UNITY_4_3 || UNITY_4_6 TextAsset textAsset = package.currentAssetBundle.Load(data.path, typeof(TextAsset)) as TextAsset; #else TextAsset textAsset = package.currentAssetBundle.LoadAsset(data.path, typeof(TextAsset)) as TextAsset; #endif byte[] buffer = textAsset.bytes; buffer = Convert.FromBase64String(Encoding.ASCII.GetString(buffer)); //解密数据 #if _SupportDeviceVerify buffer = xmlFileEncipher.FileDecrypt(buffer, true); #else buffer = xmlFileEncipher.FileDecrypt(buffer); #endif //_SupportDeviceVerify UniGameResources.ReleaseOneAssets(textAsset); package.UnLockPackage(); return(buffer); } return(null); }
private UnityEngine.Object PrivateLoadResource(ref GameResourcesNode data, Type type, bool isInstantiate) { //如果是系统资源包就换个函数加载 if (data.packageId == UniGameResourcesDefine.DefineSystemAssetBundleId) { return(PrivateLoadResource_Resource(ref data, type, isInstantiate)); } else if (UniGameResources.gameResourcesWorkMode == GameResourcesWorkMode.Mode_AloneSecurity) { try { if (isInstantiate) { #if UNITY_4_3 || UNITY_4_6 return(GameObject.Instantiate(Resources.LoadAssetAtPath(UniGameResources.ConnectPath(UniGameResources.DataPath, data.packageName, "/", data.path), type))); #else return(GameObject.Instantiate(Resources.Load(UniGameResources.ConnectPath(UniGameResources.DataPath, data.packageName, "/", data.path), type))); #endif } else { #if UNITY_4_3 || UNITY_4_6 return(Resources.LoadAssetAtPath(UniGameResources.ConnectPath(UniGameResources.DataPath, data.packageName, "/", data.path), type)); #else return(Resources.Load(UniGameResources.ConnectPath(UniGameResources.DataPath, data.packageName, "/", data.path), type)); #endif } } catch (System.Exception ex) { Debug.LogError(ex.ToString()); return(null); } } else if (UniGameResources.gameResourcesWorkMode == GameResourcesWorkMode.Mode_Mobile) { UnityEngine.Object ret = null; UniGameResourcesPackage package = (UniGameResourcesPackage)data.package; package.LockPackage(); try { if (isInstantiate) { #if UNITY_4_3 || UNITY_4_6 ret = GameObject.Instantiate(package.currentAssetBundle.Load(data.path, type)); #else ret = GameObject.Instantiate(package.currentAssetBundle.LoadAsset(data.path, type)); #endif } else { #if UNITY_4_3 || UNITY_4_6 ret = package.currentAssetBundle.Load(data.path, type); #else ret = package.currentAssetBundle.LoadAsset(data.path, type); #endif } } catch (System.Exception ex) { Debug.LogError(ex.ToString()); } package.UnLockPackage(); return(ret); } return(null); }
//是否支持及时下载模式 public void Initialization() { //移动资源包模式需要加载文件解密器 //移动模式必须提供资源包列表 if (UniGameResources.gameResourcesWorkMode == GameResourcesWorkMode.Mode_Mobile) { xmlFileEncipher = UniGameResources.AllocXmlFileEncipher(); luaScriptFileEncipher = UniGameResources.AllocLuaScriptFileEncipher(); } else if (UniGameResources.gameResourcesWorkMode == GameResourcesWorkMode.Mode_AloneSecurity) { xmlReaderSecurity = new FTLibrary.XML.XmlReaderSecurity(); xmlReaderSecurity.Initialization(UniGameResources.ConnectPath(UniGameResources.DataPath, UniGameResourcesDefine.DefineAssetBundleName_Config, "\\")); xmlPublicReaderSecurity = new FTLibrary.XML.XmlPublicReaderSecurity(); luaScriptReaderSecurity = new FTLibrary.XML.LuaScriptReaderSecurity(); luaScriptReaderSecurity.Initialization(UniGameResources.ConnectPath(UniGameResources.DataPath, UniGameResourcesDefine.DefineAssetBundleName_LuaScript, "\\")); //需要载入包清单来构建包表 //这里虚构一份资源进行加载 GameResourcesNode data = new GameResourcesNode(); data.packageName = UniGameResourcesDefine.DefineAssetBundleName_Config; data.path = UniGameResourcesDefine.GameAssetBundleInventoryXmlFilePath; //载入系统包清单 UniGameResources.BuildSystemResourcesPackageTable(LoadResource_XmlDocument(ref data, Encoding.Default)); } //定于到资源对象的表内以方便所有资源进行索引 Dictionary <uint, UniGameResourcesPackage> .Enumerator list = UniGameResources.systemResourcesPackageTable.GetEnumerator(); while (list.MoveNext()) { resourcesPackageTable.Add(list.Current.Value.packageId, list.Current.Value); } list.Dispose(); //开始重建资源表 //注册所有资源类型 RegisterResourcesType(UniGameResourcesDefine.ResourcesTypeName_XmlFile, UniGameResourcesDefine.ResourcesTypeIndex_XmlFile); RegisterResourcesType(UniGameResourcesDefine.ResourcesTypeName_ResourceFile, UniGameResourcesDefine.ResourcesTypeIndex_ResourceFile); RegisterResourcesType(UniGameResourcesDefine.ResourcesTypeName_LanguageResourceFile, UniGameResourcesDefine.ResourcesTypeIndex_LanguageResourceFile); RegisterResourcesType(UniGameResourcesDefine.ResourcesTypeName_LuaScript, UniGameResourcesDefine.ResourcesTypeIndex_LuaScript); RegisterResourcesType(UniGameResourcesDefine.ResourcesTypeName_String, UniGameResourcesDefine.ResourcesTypeIndex_String); RegisterResourcesType(UniGameResourcesDefine.ResourcesTypeName_Prefabs, UniGameResourcesDefine.ResourcesTypeIndex_Prefabs); RegisterResourcesType(UniGameResourcesDefine.ResourcesTypeName_PublicXmlFile, UniGameResourcesDefine.ResourcesTypeIndex_PublicXmlFile); RegisterResourcesType(UniGameResourcesDefine.ResourcesTypeName_Texture, UniGameResourcesDefine.ResourcesTypeIndex_Texture); RegisterResourcesType(UniGameResourcesDefine.ResourcesTypeName_AudioClip, UniGameResourcesDefine.ResourcesTypeIndex_AudioClip); RegisterResourcesType(UniGameResourcesDefine.ResourcesTypeName_TimerDefine, UniGameResourcesDefine.ResourcesTypeIndex_TimerDefine); RegisterResourcesType(UniGameResourcesDefine.ResourcesTypeName_Material, UniGameResourcesDefine.ResourcesTypeIndex_Material); RegisterResourcesType(UniGameResourcesDefine.ResourcesTypeName_PathDefine, UniGameResourcesDefine.ResourcesTypeIndex_PathDefine); RegisterResourcesType(UniGameResourcesDefine.ResourcesTypeName_CarList, UniGameResourcesDefine.ResourcesTypeIndex_CarList); //一些索引资源需要手动注册以方便读取 uint configPackageId = 0; if (UniGameResources.gameResourcesWorkMode == GameResourcesWorkMode.Mode_Mobile) { GameResourcesPackage configPackage = LockPackage(UniGameResourcesDefine.DefineAssetBundleName_Config); configPackageId = configPackage.packageId; luaScriptPackage = LockPackage(UniGameResourcesDefine.DefineAssetBundleName_LuaScript) as UniGameResourcesPackage; LockPackage(UniGameResourcesDefine.DefineAssetBundleName_PublicConfig); //这里锁定就不释放了,永远驻留内存 } //注册LUA脚本读取器为从资源中加载脚本 uniResourcesLuaScriptLoader = new UniResourcesLuaScriptLoader(); //植入主清单文件 AddResourcesToTable(UniGameResourcesDefine.ResourcesTypeIndex_XmlFile, UniGameResourcesDefine.DefineResourcesName_MainResourcesFile, configPackageId, UniGameResourcesDefine.DefineAssetBundleName_Config, UniGameResourcesDefine.DefineResourcesPath_MainResourcesFile, -1); //加载这个主清单文件 XmlDocument mainXmlDoc = LoadResource_XmlFile(UniGameResourcesDefine.DefineResourcesName_MainResourcesFile); if (mainXmlDoc == null) { throw new Exception("load main xml Inventory file err!"); } //加载这个资源清单 BuildResourcesTable(mainXmlDoc); //加载其他资源清单 Dictionary <uint, GameResourcesNode> .Enumerator resourceFileList = GetResourceEnumerator(UniGameResourcesDefine.ResourcesTypeIndex_ResourceFile); while (resourceFileList.MoveNext()) { XmlDocument doc = LoadResource_ResourceXmlFile(resourceFileList.Current.Value.name); if (doc == null) { throw new Exception("load xml Inventory file err!"); } //加载这份清单 BuildResourcesTable(doc); } resourceFileList.Dispose(); //资源清单已经加载完成了 //加载语言定义 LoadLanguageDefine(); //外部定义模式不在这里加载语言定义 if (UniGameResources.gameResourcesWorkModeTwo != GameResourcesWorkModeTwo.Mode_OutGameOptions) { //加载资源模块使用的LUA脚本 uniLuaResourcesScript = new UniLuaResourcesScript(); //选择当前使用的语言 SelectCurrentLanguage(); //加载语言资源清单 LoadLanguageResourcesInventory(); } //加载当前版本信息 produceVersion.Initialization(LoadResource_PublicXmlFile(UniGameResourcesDefine.ProduceVersionFileName)); //加载资源卸载器 UniGameResources.AllocUnloadUnusedAssetsGameObject(); //加载资源下载器 UniGameResources.AllocResourcesDownLoadWorker(); }
public IEnumerator DownloadPackageWithList(List <UniGameResourcesPackage> packageList) { if (needDownloadPackageList.Count != 0 || overDownloadPackageList.Count != 0) { Debug.LogError("Is Have Loader Package!"); yield break; } for (int i = 0; i < packageList.Count; i++) { UniGameResourcesPackage package = packageList[i]; package.LockPackage(); needDownloadPackageList.Add(package); } //开始下载过程 do { UniGameResourcesPackage package = needDownloadPackageList[0]; //检测是否已经存在资源对象了 //存在就不要下载了 if (package.currentAssetBundle == null) { if (package.assetBundleType == UniGameResourcesPackage.AssetBundleType.Type_Local) { if (UniGameResources.ForceUpdateAllGameAssetBundle) { downloadNowWWW = WWW.LoadFromCacheOrDownload(UniGameResources.ConnectPath(UniGameResources.StreamingAssetsPath, package.packagePath), UniGameResources.version_GameAssetBundleInventoryPackageFile); } else { downloadNowWWW = WWW.LoadFromCacheOrDownload(UniGameResources.ConnectPath(UniGameResources.StreamingAssetsPath, package.packagePath), package.assetBundleVersion); } } else if (package.assetBundleType == UniGameResourcesPackage.AssetBundleType.Type_Net) { if (UniGameResources.ForceUpdateAllGameAssetBundle) { downloadNowWWW = WWW.LoadFromCacheOrDownload(UniGameResources.ConnectPath(UniGameResources.downloadUrlPath, package.packagePath), UniGameResources.version_GameAssetBundleInventoryPackageFile); } else { downloadNowWWW = WWW.LoadFromCacheOrDownload(UniGameResources.ConnectPath(UniGameResources.downloadUrlPath, package.packagePath), package.assetBundleVersion); } } else { Debug.LogError("assetBundleType Err!"); yield break; } //等待完成 yield return(downloadNowWWW); if (downloadNowWWW.error != null) { Debug.LogError(string.Format("download package err:{0}", downloadNowWWW.error)); downloadNowWWW.Dispose(); downloadNowWWW = null; yield break; } else if (!downloadNowWWW.isDone) { Debug.LogError("download package can not download over!"); downloadNowWWW.Dispose(); downloadNowWWW = null; yield break; } package.currentAssetBundle = downloadNowWWW.assetBundle; downloadNowWWW.Dispose(); downloadNowWWW = null; } overDownloadPackageList.Add(package); needDownloadPackageList.RemoveAt(0); } while (needDownloadPackageList.Count != 0); }