コード例 #1
0
        private static XmlElement CreateConfigItem(XmlDocument xmlDoc, string filePath, string fileName, string finalPath)
        {
            XmlElement platformItem = xmlDoc.CreateElement("item");

            platformItem.SetAttribute("name", fileName);
            platformItem.SetAttribute("path", finalPath);
            byte[] platformFileBytes = QEditorUtil.GetFileBytes(filePath);
            platformItem.SetAttribute("hash", QEditorUtil.MD5(platformFileBytes));
            platformItem.SetAttribute("size", QEditorUtil.Size(platformFileBytes));
            return(platformItem);
        }
コード例 #2
0
        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();
        }