Beispiel #1
0
        public static void BuildAssetBundles(BuildTarget buildTarget, string inputProjectTag)
        {
            if (string.IsNullOrEmpty(inputProjectTag))
            {
                projectTag = "qframework";
            }
            else
            {
                projectTag = inputProjectTag;
            }

            SetProjectTag();

            // Choose the output path according to the build target.
            string outputPath = Path.Combine(QPlatform.ABundlesOutputForderName, QPlatform.GetPlatformName());

//			outputPath = outputPath + "/" + projectTag;

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

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

            List <string> finalzips  = PackZips(outputPath);
            List <string> finalFiles = PackPTFiles(outputPath);

            GenerateVersionConfig(outputPath, finalzips, finalFiles);

            if (Directory.Exists(QPath.StreamingAssetsABDir))
            {
                Directory.Delete(QPath.StreamingAssetsABDir, true);
            }
            Directory.CreateDirectory(QPath.StreamingAssetsABDir);
            FileUtil.ReplaceDirectory(QPlatform.ABundlesOutputForderName, Application.streamingAssetsPath + "/QAB");
            AssetDatabase.Refresh();

            string finalDir = Application.streamingAssetsPath + "/AssetBundles/" + QPlatform.GetPlatformName() + "/" + projectTag;

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

            Directory.CreateDirectory(finalDir);
            FileUtil.ReplaceDirectory(outputPath, finalDir);
            AssetDatabase.Refresh();
        }
Beispiel #2
0
 private void SetABPath(bool isAsync)
 {
     Debug.Log("***********hasResUpdated:" + hasResUpdated);
     if (hasResUpdated)
     {
         QABMgr.SetSourceABURL(Application.persistentDataPath + "/QAB/" + QPlatform.GetPlatformName() + "/");
     }
     else
     {
         if (!isAsync && Application.platform == RuntimePlatform.Android)
         {
             QABMgr.SetSourceABURL(Application.dataPath + "!assets" + "/QAB/" + QPlatform.GetPlatformName() + "/");
         }
         else
         {
             QABMgr.SetSourceABURL(Application.streamingAssetsPath + "/QAB/" + QPlatform.GetPlatformName() + "/");
         }
     }
 }
Beispiel #3
0
        public static void BuildAssetBundles(BuildTarget buildTarget)
        {
            string outputPath = Path.Combine(QPlatform.ABundlesOutputForderName, QPlatform.GetPlatformName());

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

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

            GenerateVersionConfig(outputPath);
            if (Directory.Exists(QPath.StreamingAssetsABDir))
            {
                Directory.Delete(QPath.StreamingAssetsABDir, true);
            }
            Directory.CreateDirectory(QPath.StreamingAssetsABDir);
            FileUtil.ReplaceDirectory(QPlatform.ABundlesOutputForderName, Application.streamingAssetsPath + "/QAB");
            AssetDatabase.Refresh();
        }
Beispiel #4
0
        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();
            }
        }
Beispiel #5
0
        private static void GenerateVersionConfig(string outputPath)
        {
            string              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();
            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);
                assetBundle.Unload(true);
            }
            ab.Unload(true);

            byte[] platformBytes = QEditorUtil.GetFileBytes(Path.Combine(outputPath, QPlatform.GetPlatformName()));

            string platformMD5  = QEditorUtil.MD5(platformBytes);
            string platformSize = QEditorUtil.Size(platformBytes);

            platformBytes = null;

            XmlElement platformItem = xmlDoc.CreateElement("item");

            platformItem.SetAttribute("name", QPlatform.GetPlatformName());
            platformItem.SetAttribute("abspath", QPlatform.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();
        }