Beispiel #1
0
    /// <summary>
    /// 根据build assetbundle后返回的AssetBundleManifest 生成一个本次AssetBundle的信息文件,包含所有的AssetBundle文件名与其hash值。
    /// </summary>
    /// <param name="mf">build assetbundle后返回的manifest对象</param>
    /// <param name="versionName">一般是平台名字,也可以加其他文件夹在</param>
    private static void GenABVersionInfo(AssetBundleManifest mf, string versionName)
    {
        var         abpi   = ABSH.GetABInfoXmlPath(versionName);
        XmlDocument xmlDoc = null;

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

        //创建个时间属性,可以更直观的对比不同版本的
        AllRoot.SetAttribute(AssetBundleSettingHelper.xmlAttribute_CreateTime, VersionInfo.GetVersionString());
        xmlDoc.AppendChild(AllRoot);

        //输出结果按名字排序,以后要对比两个文件也方面一些
        var abNames = mf.GetAllAssetBundles().OrderBy(n => n).Select(key => AssetBundleSettingHelper.PathToPlatformFormat(key).ToLower());
        List <KeyValuePair <long, XmlElement> > allE = new List <KeyValuePair <long, XmlElement> >();

        foreach (var abName in abNames)
        {
            //bundle大小也输出一下
            FileInfo fi = new FileInfo(AssetBundleSettingHelper.Combine(abpi.Dir_Relative, abName));
            {
                //把bundle大小也写到AB依赖中
                string name = abName.Substring(0, abName.IndexOf(ABSH.AssetBundelExtName));
                var    drac = ABDependenciesPositive.GetDRAC(name, true);
                if (drac != null)
                {
                    drac.FinalSize = fi.Length;
                }
            }
            var        hash = mf.GetAssetBundleHash(abName);
            XmlElement node = xmlDoc.CreateElement(AssetBundleSettingHelper.xmlNode_AB);
            node.SetAttribute(AssetBundleSettingHelper.xmlNode_Name, abName);
            node.SetAttribute(AssetBundleSettingHelper.xmlNode_Hash, hash.ToString());
            node.SetAttribute(AssetBundleSettingHelper.xmlNode_ABSize, fi.Length.ToString());
            if (fi.Length < 1024)
            {
                node.SetAttribute(AssetBundleSettingHelper.xmlNode_ABSizeXB, ((float)fi.Length).ToString() + " B");
            }
            else if (fi.Length >= 1024 && fi.Length < 1024 * 1024)
            {
                node.SetAttribute(AssetBundleSettingHelper.xmlNode_ABSizeXB, ((float)fi.Length / 1024).ToString("f3") + " KB");
            }
            else
            {
                node.SetAttribute(AssetBundleSettingHelper.xmlNode_ABSizeXB, ((float)fi.Length / (1024 * 1024)).ToString("f3") + " MB");
            }
            allE.Add(new KeyValuePair <long, XmlElement>(fi.Length, node));
        }
        foreach (var node in allE.OrderByDescending(k => k.Key).ThenBy(k => k.Value.GetAttribute(AssetBundleSettingHelper.xmlNode_Name)))
        {
            AllRoot.AppendChild(node.Value);
        }
        //同名文件直接覆盖
        xmlDoc.Save(abpi.FullName);

        xmlDoc = VersionInfo.OutputXmlDoc();
        abpi   = ABSH.GetABXmlPath(versionName, VersionXmlInfo.FileName);
        xmlDoc.Save(abpi.FullName);
    }
Beispiel #2
0
 /// <summary>
 /// 整个文件夹拷贝功能
 /// </summary>
 /// <param name="srcPath">源文件夹</param>
 /// <param name="tarPath">目标文件夹</param>
 private static void CopyFolder(string srcPath, string tarPath)
 {
     if (!Directory.Exists(srcPath))
     {
         return;
     }
     if (!Directory.Exists(tarPath))
     {
         Directory.CreateDirectory(tarPath);
     }
     CopyFile(srcPath, tarPath);
     string[] directionName = Directory.GetDirectories(srcPath);
     foreach (string dirPath in directionName)
     {
         string directionPathTemp = AssetBundleSettingHelper.Combine(tarPath, dirPath.Substring(srcPath.Length + 1));
         CopyFolder(dirPath, directionPathTemp);
     }
 }
Beispiel #3
0
 /// <summary>
 /// 文件夹下具体文件的拷贝,.meta .manifest和xml文件目前不拷贝
 /// </summary>
 /// <param name="srcPath">源文件夹</param>
 /// <param name="tarPath">目标文件夹</param>
 private static void CopyFile(string srcPath, string tarPath)
 {
     string[] filesList = Directory.GetFiles(srcPath);
     //.meta文件会自动生成,不需要拷贝
     //.manifest对于实际加载AB没有意义,不需要拷贝
     //.xml目前是用来记录AB信息的,不需要运行时加载,不需要拷贝
     foreach (string f in filesList.Where(f => !f.EndsWith(".meta") && !f.EndsWith(".manifest") && (!f.EndsWith(".xml") || f.EndsWith(VersionXmlInfo.FileName + AssetBundleSettingHelper.xmlExtName))))
     {
         string fTarPath = AssetBundleSettingHelper.Combine(tarPath, f.Substring(srcPath.Length + 1));
         if (File.Exists(fTarPath))
         {
             File.Copy(f, fTarPath, true);
         }
         else
         {
             File.Copy(f, fTarPath);
         }
     }
 }
Beispiel #4
0
 /// <summary>
 /// 整个文件夹拷贝功能
 /// </summary>
 /// <param name="srcPath">源文件夹</param>
 /// <param name="tarPath">目标文件夹</param>
 private static void CopyFolder(string srcPath, string tarPath)
 {
     if (!Directory.Exists(srcPath))
     {
         AssetBundleHelper.TestLog("!Directory.Exists(srcPath):" + srcPath);
         return;
     }
     if (!Directory.Exists(tarPath))
     {
         AssetBundleHelper.TestLog("Directory.CreateDirectory(tarPath)" + tarPath);
         Directory.CreateDirectory(tarPath);
     }
     string[] directionName = Directory.GetDirectories(srcPath);
     foreach (string dirPath in directionName)
     {
         string directionPathTemp = AssetBundleSettingHelper.Combine(tarPath, dirPath.Substring(srcPath.Length + 1));
         CopyFolder(dirPath, directionPathTemp);
     }
     //让最外层在最后拷贝
     CopyFile(srcPath, tarPath);
 }