public static WriteClass ( |
||
writer | ||
ns | string | |
assetBundleInfos | List |
|
리턴 | void |
private static void GenerateVersionConfig(string outputPath, List <string> finalZips, List <string> finalFiles) { // string abManifestFile; string abManifestFile = Path.Combine(outputPath, QPlatform.GetPlatformName()); if (projectTag != "") { abManifestFile = Path.Combine(outputPath, projectTag); } else { abManifestFile = Path.Combine(outputPath, QPlatform.GetPlatformName()); } AssetBundle ab = AssetBundle.LoadFromFile(abManifestFile); AssetBundleManifest abMainfest = (AssetBundleManifest)ab.LoadAllAssets() [0]; string[] allABNames = abMainfest.GetAllAssetBundles(); XmlDocument xmlDoc = new XmlDocument(); XmlElement xmlRoot = xmlDoc.CreateElement("config"); xmlRoot.SetAttribute("res_version", PTAssetBundleBuilder.resVersion); xmlDoc.AppendChild(xmlRoot); mABInfos.Clear(); for (int i = 0; i < allABNames.Length; i++) { Hash128 hash = abMainfest.GetAssetBundleHash(allABNames [i]); XmlElement xmlItem = CreateConfigItem(xmlDoc, Path.Combine(outputPath, allABNames [i]), allABNames [i], allABNames [i]); xmlRoot.AppendChild(xmlItem); AssetBundle assetBundle = AssetBundle.LoadFromFile(Path.Combine(outputPath, allABNames [i])); QABItemInfo abInfo = new QABItemInfo(allABNames [i], Path.Combine(outputPath, allABNames [i])); abInfo.assets = assetBundle.GetAllAssetNames(); mABInfos.Add(abInfo); assetBundle.Unload(true); } // 这里要加上平台相关的xml string platformBundleName = QPlatform.GetPlatformName(); XmlElement platformItem; if (projectTag == "") { platformItem = CreateConfigItem(xmlDoc, abManifestFile, platformBundleName, platformBundleName); } else { platformItem = CreateConfigItem(xmlDoc, abManifestFile, projectTag, projectTag); } xmlRoot.AppendChild(platformItem); foreach (var zipPath in finalZips) { XmlElement zipItem = CreateConfigItem(xmlDoc, zipPath, Path.GetFileName(zipPath), Path.GetFileName(zipPath)); xmlRoot.AppendChild(zipItem); } foreach (var filePath in finalFiles) { XmlElement fileItem = CreateConfigItem(xmlDoc, filePath, Path.GetFileName(filePath), Path.GetFileName(filePath)); xmlRoot.AppendChild(fileItem); } ab.Unload(true); platformItem = CreateConfigItem(xmlDoc, Path.Combine(outputPath, QPlatform.GetPlatformName()), QPlatform.GetPlatformName(), QPlatform.GetPlatformName()); xmlRoot.AppendChild(platformItem); xmlDoc.Save(outputPath + "/resitems.xml"); AssetDatabase.Refresh(); if (PTAssetBundleBuilder.isEnableGenerateClass) { if (!Directory.Exists(Application.dataPath + Path.DirectorySeparatorChar + "QData")) { Directory.CreateDirectory(Application.dataPath + Path.DirectorySeparatorChar + "QData"); } var path = Path.GetFullPath(Application.dataPath + Path.DirectorySeparatorChar + "QData/QAB/QAssets.cs"); StreamWriter writer = new StreamWriter(File.Open(path, FileMode.Create)); QABCodeGenerator.WriteClass(writer, "QAB", mABInfos); writer.Close(); AssetDatabase.Refresh(); } }
private static void GenerateVersionConfig(string outputPath) { string abManifestFile = Path.Combine(outputPath, QABUtil.GetPlatformName()); AssetBundle ab = AssetBundle.LoadFromFile(abManifestFile); AssetBundleManifest abMainfest = (AssetBundleManifest)ab.LoadAllAssets() [0]; string[] allABNames = abMainfest.GetAllAssetBundles(); XmlDocument xmlDoc = new XmlDocument(); XmlNode xmlRoot = xmlDoc.CreateElement("config"); xmlDoc.AppendChild(xmlRoot); mABInfos.Clear(); for (int i = 0; i < allABNames.Length; i++) { Hash128 hash = abMainfest.GetAssetBundleHash(allABNames [i]); byte[] fileBytes = QEditorUtil.GetFileBytes(Path.Combine(outputPath, allABNames [i])); string md5 = QEditorUtil.MD5(fileBytes); string size = QEditorUtil.Size(fileBytes); fileBytes = null; XmlElement xmlItem = xmlDoc.CreateElement("item"); string abName = QABConfigMgr.Instance.markItems4AbsPath [allABNames [i]].name; string absPath = allABNames [i]; xmlItem.SetAttribute("name", abName); xmlItem.SetAttribute("abspath", absPath); xmlItem.SetAttribute("md5", md5); xmlItem.SetAttribute("size", size); xmlRoot.AppendChild(xmlItem); AssetBundle assetBundle = AssetBundle.LoadFromFile(Path.Combine(outputPath, allABNames [i])); QABItemInfo abInfo = new QABItemInfo(abName, absPath); abInfo.assets = assetBundle.GetAllAssetNames(); mABInfos.Add(abInfo); } ab.Unload(true); byte[] platformBytes = QEditorUtil.GetFileBytes(Path.Combine(outputPath, QABUtil.GetPlatformName())); string platformMD5 = QEditorUtil.MD5(platformBytes); string platformSize = QEditorUtil.Size(platformBytes); platformBytes = null; XmlElement platformItem = xmlDoc.CreateElement("item"); platformItem.SetAttribute("name", QABUtil.GetPlatformName()); platformItem.SetAttribute("abspath", QABUtil.GetPlatformName()); platformItem.SetAttribute("md5", platformMD5); platformItem.SetAttribute("size", platformSize); xmlRoot.AppendChild(platformItem); xmlDoc.Save(outputPath + "/resitems.xml"); AssetDatabase.Refresh(); if (!Directory.Exists(Application.dataPath + Path.DirectorySeparatorChar + "QData")) { Directory.CreateDirectory(Application.dataPath + Path.DirectorySeparatorChar + "QData"); } var path = Path.GetFullPath(Application.dataPath + Path.DirectorySeparatorChar + "QData/QAB/QAssets.cs"); StreamWriter writer = new StreamWriter(File.Open(path, FileMode.Create)); QABCodeGenerator.WriteClass(writer, "QAB", mABInfos); writer.Close(); AssetDatabase.Refresh(); }