当前位置:   article > 正文

AssetBundleManifest文件的内容转txt文件输出_androidmanifest转txt

androidmanifest转txt

打完补丁包后,补丁包中会有一个Android.ab或者iphone.ab文件,里面记录了所有ab资源的依赖关系,但是这种格式的文件直接打开是看不了的,无论怎么转码都看不了,所以就写了一个编辑器工具用来查看里面的资源依赖关系。(其实打完包后,会附带输出一个manifest文件的,也记录有ab的依赖关系,但是我就是无聊想读Android.ab中的内容,所以简单写了下代码,大佬勿喷)

在这里插入图片描述

代码如下:

/********************************************************************
    DateTime:   2021-03-23 23:44:17
    Author:     xiaolin
    Description:加载Android.ab文件,读取为txt文件
*********************************************************************/
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
using UnityEditor;

public class ReadAndroidABFile : EditorWindow
{
    [MenuItem("开发工具/ShowAndroidABName")]
    private static void OpenShowManifestWindow()
    {
        GetWindow<ReadAndroidABFile>("导出ab文件为txt");
    }
    private string inputPath = null;
    private string outputPath = null;
    private void OnGUI()
    {
        inputPath = EditorGUILayout.TextField("请输入文件路径:", inputPath);
        outputPath = EditorGUILayout.TextField("导出txt文件的路径:", outputPath);

        if (GUILayout.Button("确定", GUILayout.Width(150)))
        {
            if (inputPath == string.Empty)
                Debug.LogError("输入的文件路径不能为空!!!");
            if (!File.Exists(inputPath))
                Debug.LogError("输入的文件路径不存在!!!");
            if (outputPath == string.Empty)
                Debug.LogError("输出的文件路径不能为空!!!");
            ReadABFile();
            Debug.Log("导出完成 !");
        }
    }


    public void ReadABFile()
    {
        AssetBundleManifest manifest = new AssetBundleManifest();
        //string manifestFileUrl = @"C:\Users\Administrator\Desktop\ver_1.0.1.167_android_644428_20210323222358/Android.ab";
        Stream stream = File.Open(inputPath, FileMode.Open, FileAccess.Read, FileShare.Read);
        if (stream == null)
        {
            Debug.LogError("文件不存在:" + inputPath);
            return;
        }
        else
        {
            byte[] bytes = new byte[stream.Length];
            stream.Read(bytes, 0, bytes.Length);
            stream.Seek(0, SeekOrigin.Begin);

            try
            {
                AssetBundle assetBundle = AssetBundle.LoadFromMemory(bytes);

                manifest = assetBundle.LoadAsset("AssetBundleManifest") as AssetBundleManifest;

                assetBundle.Unload(false);
            }
            catch (System.Exception e)
            {
                Debug.LogError("加载文件AssetBundleManifest文件异常,路径:" + inputPath + "           异常信息:" + e.ToString());
                return;
            }
        }
        stream.Close();
        string[] allAssetBundles = manifest.GetAllAssetBundles();
        using (StreamWriter sw = new StreamWriter(outputPath))//(@"C:\Users\Administrator\Desktop\Android.txt"))
        {
            for (int i = 0; i < allAssetBundles.Length; i++)
            {
                sw.WriteLine(allAssetBundles[i]);
                string[] abDependencies = manifest.GetDirectDependencies(allAssetBundles[i]);//获取 AssetBundle 直接依赖
                for (int j = 0; j < abDependencies.Length; j++)
                {
                    sw.WriteLine(abDependencies[j]);
                }
                sw.WriteLine("---------------------------------------------------------");
                //Debug.Log(allAssetBundles[i]);
            }
        }
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小小林熬夜学编程/article/detail/82236
推荐阅读
相关标签
  

闽ICP备14008679号