Beispiel #1
0
    /// <summary>
    /// 生成资源依赖信息
    /// </summary>
    /// <param name="versionName">一般是平台名字,也可以加其他文件夹在</param>
    private static void GenABDependenciesInfo(string versionName)
    {
        var         abpi   = ABSH.GetABDependenciesXmlPath(versionName);
        XmlDocument xmlDoc = null;

        //创建XML文档实例
        xmlDoc = new XmlDocument();
        XmlElement AllRoot = xmlDoc.CreateElement(AssetBundleSettingHelper.xmlNode_ABDependencies);

        //创建个时间属性,可以更直观的对比不同版本的
        AllRoot.SetAttribute(AssetBundleSettingHelper.xmlAttribute_CreateTime, VersionInfo.GetVersionString());
        xmlDoc.AppendChild(AllRoot);
        //正向依赖
        XmlElement ABDs_P = xmlDoc.CreateElement(AssetBundleSettingHelper.xmlNode_ABDependencies_P);

        foreach (var abd in ABDependenciesPositive.GetDic())
        {
            XmlElement ABD_P = xmlDoc.CreateElement(AssetBundleSettingHelper.xmlNode_ABDependency_P);
            ABD_P.SetAttribute(AssetBundleSettingHelper.xmlNode_AB, abd.Key);
            ABD_P.SetAttribute(AssetBundleSettingHelper.xmlNode_ABDependency_Count, abd.Value.Count.ToString());
            if (abd.Value.FinalSize > 0 && abd.Value.FinalSize < 1024)
            {
                ABD_P.SetAttribute(AssetBundleSettingHelper.xmlNode_ABSizeXB, ((float)abd.Value.FinalSize).ToString() + " B");
            }
            else if (abd.Value.FinalSize >= 1024 && abd.Value.FinalSize < 1024 * 1024)
            {
                ABD_P.SetAttribute(AssetBundleSettingHelper.xmlNode_ABSizeXB, ((float)abd.Value.FinalSize / 1024).ToString("f3") + " KB");
            }
            else if (abd.Value.FinalSize >= 1024 * 1024)
            {
                ABD_P.SetAttribute(AssetBundleSettingHelper.xmlNode_ABSizeXB, ((float)abd.Value.FinalSize / (1024 * 1024)).ToString("f3") + " MB");
            }
            foreach (var d in abd.Value.Refs)
            {
                XmlElement d_P = xmlDoc.CreateElement(AssetBundleSettingHelper.xmlNode_ABDependency);
                d_P.SetAttribute(AssetBundleSettingHelper.xmlNode_Name, d);
                var size = ABDependenciesPositive.GetDRAC(d, true).FinalSize;
                if (size > 0 && size < 1024)
                {
                    d_P.SetAttribute(AssetBundleSettingHelper.xmlNode_ABSizeXB, ((float)size).ToString() + " B");
                }
                else if (size >= 1024 && size < 1024 * 1024)
                {
                    d_P.SetAttribute(AssetBundleSettingHelper.xmlNode_ABSizeXB, ((float)size / 1024).ToString("f3") + " KB");
                }
                else if (size >= 1024 * 1024)
                {
                    d_P.SetAttribute(AssetBundleSettingHelper.xmlNode_ABSizeXB, ((float)size / (1024 * 1024)).ToString("f3") + " MB");
                }
                ABD_P.AppendChild(d_P);
            }
            ABDs_P.AppendChild(ABD_P);
        }
        AllRoot.AppendChild(ABDs_P);
        //反向依赖
        XmlElement ABDs_R = xmlDoc.CreateElement(AssetBundleSettingHelper.xmlNode_ABDependencies_R);

        foreach (var abd in ABDependenciesReverse.GetDic())
        {
            XmlElement ABD_R = xmlDoc.CreateElement(AssetBundleSettingHelper.xmlNode_ABDependency_R);
            ABD_R.SetAttribute(AssetBundleSettingHelper.xmlNode_AB, abd.Key);
            ABD_R.SetAttribute(AssetBundleSettingHelper.xmlNode_ABDependency_Count, abd.Value.Count.ToString());
            if (abd.Value.FinalSize > 0 && abd.Value.FinalSize < 1024)
            {
                ABD_R.SetAttribute(AssetBundleSettingHelper.xmlNode_ABSizeXB, ((float)abd.Value.FinalSize).ToString() + " B");
            }
            else if (abd.Value.FinalSize >= 1024 && abd.Value.FinalSize < 1024 * 1024)
            {
                ABD_R.SetAttribute(AssetBundleSettingHelper.xmlNode_ABSizeXB, ((float)abd.Value.FinalSize / 1024).ToString("f3") + " KB");
            }
            else if (abd.Value.FinalSize >= 1024 * 1024)
            {
                ABD_R.SetAttribute(AssetBundleSettingHelper.xmlNode_ABSizeXB, ((float)abd.Value.FinalSize / (1024 * 1024)).ToString("f3") + " MB");
            }
            foreach (var d in abd.Value.Refs)
            {
                XmlElement d_R = xmlDoc.CreateElement(AssetBundleSettingHelper.xmlNode_ABDependency);
                d_R.SetAttribute(AssetBundleSettingHelper.xmlNode_Name, d);
                var size = ABDependenciesPositive.GetDRAC(d, true).FinalSize;
                if (size > 0 && size < 1024)
                {
                    d_R.SetAttribute(AssetBundleSettingHelper.xmlNode_ABSizeXB, ((float)size).ToString() + " B");
                }
                else if (size >= 1024 && size < 1024 * 1024)
                {
                    d_R.SetAttribute(AssetBundleSettingHelper.xmlNode_ABSizeXB, ((float)size / 1024).ToString("f3") + " KB");
                }
                else if (size >= 1024 * 1024)
                {
                    d_R.SetAttribute(AssetBundleSettingHelper.xmlNode_ABSizeXB, ((float)size / (1024 * 1024)).ToString("f3") + " MB");
                }
                ABD_R.AppendChild(d_R);
            }
            ABDs_R.AppendChild(ABD_R);
        }
        AllRoot.AppendChild(ABDs_R);

        //同名文件直接覆盖
        xmlDoc.Save(abpi.FullName);
    }