示例#1
0
        static void CopyAssetBundlesTo(string outputPath)
        {
            // Clear streaming assets folder.
            FileUtil.DeleteFileOrDirectory(Application.streamingAssetsPath);
            Directory.CreateDirectory(outputPath);

            string outputFolder = QABUtil.GetPlatformName();

            // Setup the source folder for assetbundles.
            var source = Path.Combine(Path.Combine(System.Environment.CurrentDirectory, QABUtil.ABundlesOutputPath), outputFolder);

            if (!System.IO.Directory.Exists(source))
            {
                Debug.Log("No assetBundle output folder, try to build the assetBundles first.");
            }

            // Setup the destination folder for assetbundles.
            var destination = System.IO.Path.Combine(outputPath, outputFolder);

            if (System.IO.Directory.Exists(destination))
            {
                FileUtil.DeleteFileOrDirectory(destination);
            }

            FileUtil.CopyFileOrDirectory(source, destination);
        }
示例#2
0
        public static void BuildAssetBundles(BuildTarget buildTarget)
        {
            string outputPath = Path.Combine(QABUtil.ABundlesOutputPath, QABUtil.GetPlatformName());

            if (Directory.Exists(outputPath))
            {
                Directory.Delete(outputPath, true);
            }
            Directory.CreateDirectory(outputPath);

            BuildPipeline.BuildAssetBundles(outputPath, BuildAssetBundleOptions.None, buildTarget);

            GenerateVersionConfig(outputPath);
            if (Directory.Exists(Application.streamingAssetsPath + "/QAB"))
            {
                Directory.Delete(Application.streamingAssetsPath + "/QAB", true);
            }
            Directory.CreateDirectory(Application.streamingAssetsPath + "/QAB");
            FileUtil.ReplaceDirectory(QABUtil.ABundlesOutputPath, Application.streamingAssetsPath + "/QAB");
            AssetDatabase.Refresh();
        }
示例#3
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();
        }