Exemple #1
0
        private void OnGUI()
        {
            compressionType = (BuildAssetBundleOptions)EditorGUILayout.EnumPopup("Asset bundle compression:", compressionType);

            if (GUILayout.Button("Save"))
            {
                EditorPrefs.SetString("COMPRESSION_TYPE", compressionType.ToString());
            }
            else if (GUILayout.Button("Save and build"))
            {
                EditorPrefs.SetString("COMPRESSION_TYPE", compressionType.ToString());

                AssetBundleBuilder.BuildAssetBundles();
            }
        }
Exemple #2
0
        private void DrawBuildOptions()
        {
            EditorGUILayout.LabelField("Build Options:");
            EditorGUILayout.BeginVertical("box");
            {
                foreach (var rawValue in System.Enum.GetValues(typeof(BuildAssetBundleOptions)))
                {
                    BuildAssetBundleOptions value = (BuildAssetBundleOptions)rawValue;
                    if (!AssetBundleBuilder.ValidBuildOptions.Contains(value))
                    {
                        continue;
                    }

                    var displayName = ObjectNames.NicifyVariableName(value.ToString());
                    var oldToggle   = (Config.BuildAssetBundleOptions & value) != 0;
                    var toggle      = EditorGUILayout.ToggleLeft(displayName, oldToggle);
                    if (toggle != oldToggle)
                    {
                        Config.BuildAssetBundleOptions ^= value;
                    }
                }
            }
            EditorGUILayout.EndVertical();
        }
Exemple #3
0
            public void SaveReport()
            {
                XmlElement   xmlElement   = null;
                XmlAttribute xmlAttribute = null;

                XmlDocument xmlDocument = new XmlDocument();

                xmlDocument.AppendChild(xmlDocument.CreateXmlDeclaration("1.0", "UTF-8", null));

                XmlElement xmlRoot = xmlDocument.CreateElement("UnityGameFramework");

                xmlDocument.AppendChild(xmlRoot);

                XmlElement xmlBuildReport = xmlDocument.CreateElement("BuildReport");

                xmlRoot.AppendChild(xmlBuildReport);

                XmlElement xmlSummary = xmlDocument.CreateElement("Summary");

                xmlBuildReport.AppendChild(xmlSummary);

                xmlElement           = xmlDocument.CreateElement("ProductName");
                xmlElement.InnerText = m_ProductName;
                xmlSummary.AppendChild(xmlElement);
                xmlElement           = xmlDocument.CreateElement("CompanyName");
                xmlElement.InnerText = m_CompanyName;
                xmlSummary.AppendChild(xmlElement);
                xmlElement           = xmlDocument.CreateElement("GameIdentifier");
                xmlElement.InnerText = m_GameIdentifier;
                xmlSummary.AppendChild(xmlElement);
                xmlElement           = xmlDocument.CreateElement("GameFrameworkVersion");
                xmlElement.InnerText = m_GameFrameworkVersion;
                xmlSummary.AppendChild(xmlElement);
                xmlElement           = xmlDocument.CreateElement("UnityVersion");
                xmlElement.InnerText = m_UnityVersion;
                xmlSummary.AppendChild(xmlElement);
                xmlElement           = xmlDocument.CreateElement("ApplicableGameVersion");
                xmlElement.InnerText = m_ApplicableGameVersion;
                xmlSummary.AppendChild(xmlElement);
                xmlElement           = xmlDocument.CreateElement("InternalResourceVersion");
                xmlElement.InnerText = m_InternalResourceVersion.ToString();
                xmlSummary.AppendChild(xmlElement);
                xmlElement           = xmlDocument.CreateElement("Platforms");
                xmlElement.InnerText = m_Platforms.ToString();
                xmlSummary.AppendChild(xmlElement);
                xmlElement           = xmlDocument.CreateElement("AssetBundleCompression");
                xmlElement.InnerText = m_AssetBundleCompression.ToString();
                xmlSummary.AppendChild(xmlElement);
                xmlElement           = xmlDocument.CreateElement("CompressionHelperTypeName");
                xmlElement.InnerText = m_CompressionHelperTypeName;
                xmlSummary.AppendChild(xmlElement);
                xmlElement           = xmlDocument.CreateElement("AdditionalCompressionSelected");
                xmlElement.InnerText = m_AdditionalCompressionSelected.ToString();
                xmlSummary.AppendChild(xmlElement);
                xmlElement           = xmlDocument.CreateElement("ForceRebuildAssetBundleSelected");
                xmlElement.InnerText = m_ForceRebuildAssetBundleSelected.ToString();
                xmlSummary.AppendChild(xmlElement);
                xmlElement           = xmlDocument.CreateElement("BuildEventHandlerTypeName");
                xmlElement.InnerText = m_BuildEventHandlerTypeName;
                xmlSummary.AppendChild(xmlElement);
                xmlElement           = xmlDocument.CreateElement("OutputDirectory");
                xmlElement.InnerText = m_OutputDirectory;
                xmlSummary.AppendChild(xmlElement);
                xmlElement           = xmlDocument.CreateElement("BuildAssetBundleOptions");
                xmlElement.InnerText = m_BuildAssetBundleOptions.ToString();
                xmlSummary.AppendChild(xmlElement);

                XmlElement xmlResources = xmlDocument.CreateElement("Resources");

                xmlAttribute       = xmlDocument.CreateAttribute("Count");
                xmlAttribute.Value = m_ResourceDatas.Count.ToString();
                xmlResources.Attributes.SetNamedItem(xmlAttribute);
                xmlBuildReport.AppendChild(xmlResources);
                foreach (ResourceData resourceData in m_ResourceDatas.Values)
                {
                    XmlElement xmlResource = xmlDocument.CreateElement("Resource");
                    xmlAttribute       = xmlDocument.CreateAttribute("Name");
                    xmlAttribute.Value = resourceData.Name;
                    xmlResource.Attributes.SetNamedItem(xmlAttribute);
                    if (resourceData.Variant != null)
                    {
                        xmlAttribute       = xmlDocument.CreateAttribute("Variant");
                        xmlAttribute.Value = resourceData.Variant;
                        xmlResource.Attributes.SetNamedItem(xmlAttribute);
                    }

                    xmlAttribute       = xmlDocument.CreateAttribute("Extension");
                    xmlAttribute.Value = GetExtension(resourceData);
                    xmlResource.Attributes.SetNamedItem(xmlAttribute);

                    if (resourceData.FileSystem != null)
                    {
                        xmlAttribute       = xmlDocument.CreateAttribute("FileSystem");
                        xmlAttribute.Value = resourceData.FileSystem;
                        xmlResource.Attributes.SetNamedItem(xmlAttribute);
                    }

                    xmlAttribute       = xmlDocument.CreateAttribute("LoadType");
                    xmlAttribute.Value = ((byte)resourceData.LoadType).ToString();
                    xmlResource.Attributes.SetNamedItem(xmlAttribute);
                    xmlAttribute       = xmlDocument.CreateAttribute("Packed");
                    xmlAttribute.Value = resourceData.Packed.ToString();
                    xmlResource.Attributes.SetNamedItem(xmlAttribute);
                    string[] resourceGroups = resourceData.GetResourceGroups();
                    if (resourceGroups.Length > 0)
                    {
                        xmlAttribute       = xmlDocument.CreateAttribute("ResourceGroups");
                        xmlAttribute.Value = string.Join(",", resourceGroups);
                        xmlResource.Attributes.SetNamedItem(xmlAttribute);
                    }

                    xmlResources.AppendChild(xmlResource);

                    AssetData[] assetDatas = resourceData.GetAssetDatas();
                    XmlElement  xmlAssets  = xmlDocument.CreateElement("Assets");
                    xmlAttribute       = xmlDocument.CreateAttribute("Count");
                    xmlAttribute.Value = assetDatas.Length.ToString();
                    xmlAssets.Attributes.SetNamedItem(xmlAttribute);
                    xmlResource.AppendChild(xmlAssets);
                    foreach (AssetData assetData in assetDatas)
                    {
                        XmlElement xmlAsset = xmlDocument.CreateElement("Asset");
                        xmlAttribute       = xmlDocument.CreateAttribute("Guid");
                        xmlAttribute.Value = assetData.Guid;
                        xmlAsset.Attributes.SetNamedItem(xmlAttribute);
                        xmlAttribute       = xmlDocument.CreateAttribute("Name");
                        xmlAttribute.Value = assetData.Name;
                        xmlAsset.Attributes.SetNamedItem(xmlAttribute);
                        xmlAttribute       = xmlDocument.CreateAttribute("Length");
                        xmlAttribute.Value = assetData.Length.ToString();
                        xmlAsset.Attributes.SetNamedItem(xmlAttribute);
                        xmlAttribute       = xmlDocument.CreateAttribute("HashCode");
                        xmlAttribute.Value = assetData.HashCode.ToString();
                        xmlAsset.Attributes.SetNamedItem(xmlAttribute);
                        xmlAssets.AppendChild(xmlAsset);
                        string[] dependencyAssetNames = assetData.GetDependencyAssetNames();
                        if (dependencyAssetNames.Length > 0)
                        {
                            XmlElement xmlDependencyAssets = xmlDocument.CreateElement("DependencyAssets");
                            xmlAttribute       = xmlDocument.CreateAttribute("Count");
                            xmlAttribute.Value = dependencyAssetNames.Length.ToString();
                            xmlDependencyAssets.Attributes.SetNamedItem(xmlAttribute);
                            xmlAsset.AppendChild(xmlDependencyAssets);
                            foreach (string dependencyAssetName in dependencyAssetNames)
                            {
                                XmlElement xmlDependencyAsset = xmlDocument.CreateElement("DependencyAsset");
                                xmlAttribute       = xmlDocument.CreateAttribute("Name");
                                xmlAttribute.Value = dependencyAssetName;
                                xmlDependencyAsset.Attributes.SetNamedItem(xmlAttribute);
                                xmlDependencyAssets.AppendChild(xmlDependencyAsset);
                            }
                        }
                    }

                    XmlElement xmlCodes = xmlDocument.CreateElement("Codes");
                    xmlResource.AppendChild(xmlCodes);
                    foreach (ResourceCode resourceCode in resourceData.GetCodes())
                    {
                        XmlElement xmlCode = xmlDocument.CreateElement(resourceCode.Platform.ToString());
                        xmlAttribute       = xmlDocument.CreateAttribute("Length");
                        xmlAttribute.Value = resourceCode.Length.ToString();
                        xmlCode.Attributes.SetNamedItem(xmlAttribute);
                        xmlAttribute       = xmlDocument.CreateAttribute("HashCode");
                        xmlAttribute.Value = resourceCode.HashCode.ToString();
                        xmlCode.Attributes.SetNamedItem(xmlAttribute);
                        xmlAttribute       = xmlDocument.CreateAttribute("CompressedLength");
                        xmlAttribute.Value = resourceCode.CompressedLength.ToString();
                        xmlCode.Attributes.SetNamedItem(xmlAttribute);
                        xmlAttribute       = xmlDocument.CreateAttribute("CompressedHashCode");
                        xmlAttribute.Value = resourceCode.CompressedHashCode.ToString();
                        xmlCode.Attributes.SetNamedItem(xmlAttribute);
                        xmlCodes.AppendChild(xmlCode);
                    }
                }

                xmlDocument.Save(m_BuildReportName);
                File.WriteAllText(m_BuildLogName, m_LogBuilder.ToString());
            }
    public void SaveToFile()
    {
        XmlDocument    xmldoc      = new XmlDocument();
        XmlDeclaration declaration = xmldoc.CreateXmlDeclaration("1.0", "utf-8", string.Empty);

        xmldoc.AppendChild(declaration);

        XmlElement root = xmldoc.CreateElement("SettingInfo");

        xmldoc.AppendChild(root);

        XmlElement version = xmldoc.CreateElement("Version");

        version.InnerText = Version;
        root.AppendChild(version);

        XmlElement outPath = xmldoc.CreateElement("OutPath");

        outPath.InnerText = OutPath;
        root.AppendChild(outPath);

        XmlElement options = xmldoc.CreateElement("Options");

        options.InnerText = Options.ToString();
        root.AppendChild(options);

        XmlElement resetAbName = xmldoc.CreateElement("ResetAssetBundleName");

        resetAbName.InnerText = (ResetAssetBundleName == true ? 1 : 0).ToString();
        root.AppendChild(resetAbName);

        StringBuilder UnpackPathsb   = GetStringBuilder(UnpackPath);
        StringBuilder IgnoreSuffixsb = GetStringBuilder(IgnoreSuffix);
        StringBuilder AssetsMapsb    = GetAssetsMap(AssetsMap);

        XmlElement unpackPath = xmldoc.CreateElement("UnpackPath");

        unpackPath.InnerText = UnpackPathsb.ToString();
        root.AppendChild(unpackPath);

        XmlElement ignoreSuffix = xmldoc.CreateElement("IgnoreSuffix");

        ignoreSuffix.InnerText = IgnoreSuffixsb.ToString();
        root.AppendChild(ignoreSuffix);

        XmlElement assetsMap = xmldoc.CreateElement("AssetsMap");

        assetsMap.InnerText = AssetsMapsb.ToString();
        root.AppendChild(assetsMap);

        // 将AssetsMap写入到 L_Resources 目录下的文件中,
        // 在加载ab时有用到
        StringBuilder @string = new StringBuilder();
        var           itr     = AssetsMap.Keys.GetEnumerator();

        while (itr.MoveNext())
        {
            @string.Append(itr.Current + "|" + AssetsMap[itr.Current] + "\n");
        }
        itr.Dispose();

        string filePath = Application.dataPath + "/L_Resources/";

        if (!Directory.Exists(filePath))
        {
            Directory.CreateDirectory(filePath);
        }

        string fileName = filePath + PathConstant.FileName.ASSETS_MAP_NAME;

        if (File.Exists(fileName))
        {
            File.Delete(fileName);
        }

        using (FileStream fs = File.Create(fileName))
        {
            byte[] bytes = System.Text.Encoding.Default.GetBytes(@string.ToString());
            fs.Write(bytes, 0, bytes.Length);
            fs.Close();
        }

        string xmlName = GetXmlName();

        if (!System.IO.File.Exists(xmlName))
        {
            using (FileStream fs = System.IO.File.Create(xmlName))
                fs.Close();
        }

        xmldoc.Save(GetXmlName());

        AssetDatabase.Refresh();
    }