コード例 #1
0
ファイル: BuildScript.cs プロジェクト: rongjianxie/QFramework
        private static void GenerateVersionConfig(string outputPath)
        {
            var abManifestFile = Path.Combine(outputPath, GetPlatformName());
            var ab             = AssetBundle.LoadFromFile(abManifestFile);

            var abMainfest = (AssetBundleManifest)ab.LoadAsset("AssetBundleManifest");
            var allABNames = abMainfest.GetAllAssetBundles();

            AssetBundleInfos.Clear();

            foreach (var abName in allABNames)
            {
                var assetBundle = AssetBundle.LoadFromFile(Path.Combine(outputPath, abName));
                var abInfo      = new AssetBundleInfo(abName)
                {
                    assets = assetBundle.GetAllAssetNames()
                };
                AssetBundleInfos.Add(abInfo);
                assetBundle.Unload(true);
            }

            ab.Unload(true);

            AssetDatabase.Refresh();

            if (ResKitEditorWindow.isEnableGenerateClass)
            {
                "Assets/QFrameworkData".CreateDirIfNotExists();

                var path   = Path.GetFullPath(Application.dataPath + Path.DirectorySeparatorChar + "QFrameworkData/QAssets.cs");
                var writer = new StreamWriter(File.Open(path, FileMode.Create));
                QBundleInfoGenerator.WriteClass(writer, "QAssetBundle", AssetBundleInfos);
                writer.Close();
                AssetDatabase.Refresh();
            }
        }
コード例 #2
0
        private static void GenerateVersionConfig(string outputPath, List <string> finalZips, List <string> finalFiles)
        {
            string abManifestFile;

            if (projectTag != "")
            {
                abManifestFile = Path.Combine(outputPath, projectTag);
            }
            else
            {
                abManifestFile = Path.Combine(outputPath, GetPlatformName());
            }

            AssetBundle ab = AssetBundle.LoadFromFile(abManifestFile);

            AssetBundleManifest abMainfest = (AssetBundleManifest)ab.LoadAsset("AssetBundleManifest");

            string[]    allABNames = abMainfest.GetAllAssetBundles();
            XmlDocument xmlDoc     = new XmlDocument();
            XmlElement  xmlRoot    = xmlDoc.CreateElement("config");

            xmlRoot.SetAttribute("res_version", QResSystemBuilder.resVersion);
            xmlDoc.AppendChild(xmlRoot);
            assetBundleInfos.Clear();
            for (int i = 0; i < allABNames.Length; 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]));
                AssetBundleInfo abInfo      = new AssetBundleInfo(allABNames[i]);
                abInfo.assets = assetBundle.GetAllAssetNames();
                assetBundleInfos.Add(abInfo);
                assetBundle.Unload(true);
            }
            // 这里要加上平台相关的xml
            string     platformBundleName = 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);
            }

            XmlElement filTiem = CreateConfigItem(xmlDoc,
                                                  Application.streamingAssetsPath + QFrameworkConfigData.RELATIVE_AB_ROOT_FOLDER +
                                                  QFrameworkConfigData.EXPORT_ASSETBUNDLE_CONFIG_FILENAME,
                                                  QFrameworkConfigData.EXPORT_ASSETBUNDLE_CONFIG_FILENAME,
                                                  QFrameworkConfigData.EXPORT_ASSETBUNDLE_CONFIG_FILENAME);

            xmlRoot.AppendChild(filTiem);

            ab.Unload(true);

            xmlDoc.Save(outputPath + "/resconfig.xml");
            AssetDatabase.Refresh();

            if (QResSystemBuilder.isEnableGenerateClass)
            {
                if (!Directory.Exists("QFrameworkData"))
                {
                    Directory.CreateDirectory("QFrameworkData");
                }

                var          path   = Path.GetFullPath(Application.dataPath + Path.DirectorySeparatorChar + "QFrameworkData/QAssets.cs");
                StreamWriter writer = new StreamWriter(File.Open(path, FileMode.Create));
                QBundleInfoGenerator.WriteClass(writer, "QAssetBundle", assetBundleInfos, projectTag);
                writer.Close();
                AssetDatabase.Refresh();
            }
        }