Esempio n. 1
0
        public static void AppendType(StringBuilder sb, EAssetBundleFileInfo abFileInfo, E_AssetType assetType, bool isEdundance, string des)
        {
            List <EAssetFileInfo> assetFiles = new List <EAssetFileInfo>();

            abFileInfo.FindAssetFiles(assetFiles, assetType);
            if (assetFiles.Count == 0)
            {
                return;
            }

            float allSize = 0;
            int   length  = assetFiles.Count;

            for (int i = 0; i < length; i++)
            {
                bool result = assetFiles[i]._includedBundles.Count > 1;
                if (result == isEdundance)
                {
                    allSize += assetFiles[i].GetMemorySize();
                }
            }

            sb.Append(",," + des + "(" + allSize + ")");
            for (int i = 0; i < length; i++)
            {
                bool result = assetFiles[i]._includedBundles.Count > 1;
                if (result == isEdundance)
                {
                    string tmpSize = (assetFiles[i].GetMemorySize()).ToString("f2");
                    sb.Append("," + assetFiles[i]._assetName + "(" + tmpSize + "Kb)");
                }
            }
            sb.AppendLine();
        }
Esempio n. 2
0
        public static void CreateReport(string directory_path)
        {
            List <EAssetFileInfo> asset_files = new List <EAssetFileInfo>(AssetBundleAnalyzeManager.FindAssetFiles().Values);

            asset_files.Sort(SortAsset);

            StringBuilder sb = new StringBuilder();

            sb.AppendLine(string.Format("{0},{1},{5},{2},{3},{4}", asset_name, asset_size, asset_type, be_ref_count, ab_list, in_built));

            int length = asset_files.Count;

            for (int i = 0; i < length; i++)
            {
                EAssetFileInfo info = asset_files[i];
                sb.Append(info._assetName + "," + info.GetMemorySize() + "," + info._inBuilt + "," + info._assetType + "," + info._includedBundles.Count);
                int ref_count = info._includedBundles.Count;
                for (int j = 0; j < ref_count; j++)
                {
                    EAssetBundleFileInfo assetbundle_file = info._includedBundles[j];
                    sb.Append("," + assetbundle_file.AbName);
                }

                sb.AppendLine();
            }

            FileHelper.WriteTxtByFile(directory_path + "/" + ASSET_REPORT_NAME, sb.ToString());
        }
Esempio n. 3
0
 public static int SortAsset(EAssetBundleFileInfo a, EAssetBundleFileInfo b)
 {
     if (a == null || b == null)
     {
         return(0);
     }
     return(String.Compare(a.AbName, b.AbName, StringComparison.Ordinal));
 }
Esempio n. 4
0
 public static void AppendLineRedundance(StringBuilder sb, EAssetBundleFileInfo abFileInfo)
 {
     sb.AppendLine(" , " + _redundance + "[" + abFileInfo.FindRedundance() + "]");
     AppendType(sb, abFileInfo, E_AssetType.TEXTURE, true, _texture);
     AppendType(sb, abFileInfo, E_AssetType.MESH, true, MESH);
     AppendType(sb, abFileInfo, E_AssetType.MATERIAL, true, MATERIAL);
     AppendType(sb, abFileInfo, E_AssetType.SPRITE, true, SPRITE);
     AppendType(sb, abFileInfo, E_AssetType.SHADER, true, SHADER);
     AppendType(sb, abFileInfo, E_AssetType.ANIMATION_CLIP, true, ANIMATION_CLIP);
     AppendType(sb, abFileInfo, E_AssetType.AUDIO_CLIP, true, AUDIO_CLIP);
 }
Esempio n. 5
0
 public static void AppendLine(StringBuilder sb, EAssetBundleFileInfo abFileInfo)
 {
     sb.AppendLine(" , OK");
     AppendType0(sb, abFileInfo, E_AssetType.TEXTURE, false, _texture);
     AppendType0(sb, abFileInfo, E_AssetType.MESH, false, MESH);
     AppendType0(sb, abFileInfo, E_AssetType.MATERIAL, false, MATERIAL);
     AppendType0(sb, abFileInfo, E_AssetType.SPRITE, false, SPRITE);
     AppendType0(sb, abFileInfo, E_AssetType.SHADER, false, SHADER);
     AppendType0(sb, abFileInfo, E_AssetType.ANIMATION_CLIP, false, ANIMATION_CLIP);
     AppendType0(sb, abFileInfo, E_AssetType.AUDIO_CLIP, false, AUDIO_CLIP);
 }
Esempio n. 6
0
        public bool AddParent(EAssetBundleFileInfo info)
        {
            int length = _includedBundles.Count;

            for (int i = 0; i < length; i++)
            {
                if (info.AbName == _includedBundles[i].AbName)
                {
                    return(false);
                }
            }
            _includedBundles.Add(info);
            return(true);
        }
Esempio n. 7
0
        /// <summary>
        /// 分析AssetBundle中有多少Asset资源
        /// </summary>
        private static void AnalyzeAssetbundleFile(EAssetBundleFileInfo assetbundleFileInfo)
        {
            AssetBundle ab = AssetBundle.LoadFromFile(assetbundleFileInfo.FilePath);

            if (assetbundleFileInfo.FilePath.Contains("ship/ship_100"))
            {
                Debug.Log("1");
            }
            string resualName = string.Empty;

            try
            {
                if (ab == null)
                {
                    Debug.LogErrorFormat("[{0}]加载失败:", assetbundleFileInfo.FilePath);
                    return;
                }
                Object[] objs           = ab.LoadAllAssets <Object>();
                Object[] collectDepends = EditorUtility.CollectDependencies(objs);
                int      length         = collectDepends.Length;
                for (int i = 0; i < length; i++)
                {
                    if (!collectDepends[i])
                    {
                        continue;
                    }
                    resualName = collectDepends[i].name;
                    AnalyzeAssetObject(collectDepends[i], assetbundleFileInfo);
                }
            }
            catch (Exception e)
            {
                Debug.LogError("[" + assetbundleFileInfo.AbName + "]_[" + resualName + "]_" + e.Message);
            }
            finally
            {
                if (ab != null)
                {
                    ab.Unload(true);
                }
            }
        }
Esempio n. 8
0
        public static void CreateReport(string directoryPath)
        {
            List <EAssetBundleFileInfo> assetbundleFiles = AssetBundleAnalyzeManager.FindAssetBundleFiles();

            assetbundleFiles.Sort(SortAsset);


            StringBuilder sb = new StringBuilder();

            sb.AppendLine(string.Format("{0},{1},{2},{12}," +
                                        "{3},{4},{5}," +
                                        "{6},{7},{8}," +
                                        "{9},{10},{11}",
                                        ASSETBUNDLE_NAME, AB_MEMORY_SIZE, CAL_MEMORY_SIZE,
                                        AB_DEP, BE_REF, MESH,
                                        MATERIAL, TEXTURE, SHADER,
                                        SPRITE, ANIMATION_CLIP, AUDIO_CLIP, REPEAT_MEMORY_SIZE));

            int length = assetbundleFiles.Count;

            for (int i = 0; i < length; i++)
            {
                EAssetBundleFileInfo info = assetbundleFiles[i];

                int tRepeatMemSize = (int)info.GetRepeatMemSize();
                int tAbSize        = (int)info.FileAbMemorySize;
                int tAbMemSize     = (int)(info.GetMemorySize());
                sb.AppendLine(string.Format("{0},{1},{2},{12}," +
                                            "{3},{4},{5}," +
                                            "{6},{7},{8}," +
                                            "{9},{10},{11}",
                                            info.AbName, tAbSize, tAbMemSize,
                                            info._allDepends.Count, info.FindRedundance(), info.GetAssetCount(E_AssetType.MESH),
                                            info.GetAssetCount(E_AssetType.MATERIAL), info.GetAssetCount(E_AssetType.TEXTURE), info.GetAssetCount(E_AssetType.SHADER),
                                            info.GetAssetCount(E_AssetType.SPRITE), info.GetAssetCount(E_AssetType.ANIMATION_CLIP), info.GetAssetCount(E_AssetType.AUDIO_CLIP), tRepeatMemSize));
            }

            FileHelper.WriteTxtByFile(directoryPath + "/" + ASSETBUNDLE_REPORT_NAME, sb.ToString());
        }
Esempio n. 9
0
        public static void AppendType0(StringBuilder sb, EAssetBundleFileInfo abFileInfo, E_AssetType assetType, bool isEdundance, string des)
        {
            List <EAssetFileInfo> assetFiles = new List <EAssetFileInfo>();

            abFileInfo.FindAssetFiles(assetFiles, assetType);
            if (assetFiles.Count == 0)
            {
                return;
            }

            sb.Append(",," + des);
            int length = assetFiles.Count;

            for (int i = 0; i < length; i++)
            {
                bool result = assetFiles[i]._includedBundles.Count > 1;
                if (result == isEdundance)
                {
                    sb.Append("," + assetFiles[i]._assetName);
                }
            }
            sb.AppendLine();
        }
Esempio n. 10
0
        // 是否加入引用
        public static E_AssetType CheckObject(Object ob, EAssetBundleFileInfo assetbundleFileInfo, ref bool inBuilt)
        {
            inBuilt = false;
            if (ob == null)
            {
                return(E_AssetType.NONE);
            }
            Type objectType = ob.GetType();

            // 1.剔除掉部分 比如Transform 脚本.cs等
            if (!_analyzeMap.ContainsKey(objectType))
            {
                if (ob as Component)
                {
                    return(E_AssetType.NONE);
                }
                if (ob as ScriptableObject)
                {
                    return(E_AssetType.NONE);
                }
                if (ob as MonoScript)
                {
                    return(E_AssetType.NONE);
                }
                if (ob as GameObject)
                {
                    return(E_AssetType.NONE);
                }
                if (ob as Avatar)
                {
                    return(E_AssetType.NONE);
                }
                Debug.LogError("CheckObject:" + ob.name + "_" + objectType);
                return(E_AssetType.NONE);
            }

            // 内建资源
            string assetPath = AssetDatabase.GetAssetPath(ob);

            if (string.IsNullOrEmpty(assetPath))
            {
                return(_analyzeMap[objectType]);
            }

            inBuilt = true;
            //assetbundle_file_info.in_built = true;
            if (ob as Mesh) // 先排除掉网格的内建资源
            {
                return(E_AssetType.NONE);
            }
            else
            {
                //Debug.LogError("使用了内建的资源" + asset_path + "_____" + object_type + "______" + assetbundle_file_info.ab_name);
            }
            if (objectType == typeof(AnimatorOverrideController))
            {
                Debug.Log("1");
            }
            if (objectType == typeof(AnimationClip))
            {
                Debug.Log("2");
            }
            if (objectType == typeof(Animation))
            {
                Debug.Log("3");
            }
            return(_analyzeMap[objectType]);
        }
Esempio n. 11
0
        /// <summary>
        /// 收集bundle资源
        /// </summary>
        private static void AnalyzeCollectBundles()
        {
            _assetBundleFileInfos.Clear();
            _assetFileInfos.Clear();

            /* string manifestPath = EAssetBundleConst.ManifestPath;
             * AssetBundle manifestAb = AssetBundle.LoadFromFile(manifestPath);
             *
             * Debug.AssertFormat(manifestAb != null, "manifest_ab 加载失败,路径地址:[{0}]", manifestPath);
             * if (manifestAb == null) return;
             *
             * AssetBundleManifest assetBundleManifest = manifestAb.LoadAsset<AssetBundleManifest>("assetbundlemanifest");
             * string[] bundles = assetBundleManifest.GetAllAssetBundles();*/

            List <string>   temp  = new List <string>();
            List <FileInfo> files = FileHelper.GetAllFiles(Application.streamingAssetsPath + "/BundleResources");

            for (int i = 0; i < files.Count; i++)
            {
                FileInfo fileInfo = files[i];
                if (fileInfo.Extension == ".meta")
                {
                    continue;
                }
                if (fileInfo.Extension == ".manifest")
                {
                    continue;
                }
                string t = fileInfo.FullName;
                t = t.Replace("F:\\RPG\\Assets\\StreamingAssets\\BundleResources", "");
                t = t.Replace("\\", "/");
                temp.Add(t);
            }
            string[] bundles = temp.ToArray();
            for (int i = 0; i < bundles.Length; i++)
            {
                EAssetBundleFileInfo info = new EAssetBundleFileInfo(bundles[i]);
                _assetBundleFileInfos.Add(info);
            }

            /*            int length = bundles.Length;
             *          for (int i = 0; i < length; i++)
             *          {
             *              EAssetBundleFileInfo info = new EAssetBundleFileInfo(bundles[i]);
             *              if (bundles[i].Contains("11002"))
             *              {
             *                  uint crc;
             *                  Hash128 hash1;
             *                  Hash128 hash=assetBundleManifest.GetAssetBundleHash(bundles[i]);
             *
             *                  BuildPipeline.GetCRCForAssetBundle(bundles[i], out crc);
             *                  BuildPipeline.GetHashForAssetBundle(bundles[i], out hash1);
             *                  UnityEngine.Debug.Log(hash);
             *                  UnityEngine.Debug.Log(hash1);
             *                  UnityEngine.Debug.Log(crc);
             *                  UnityEngine.Debug.Log("=======================================================");
             *              }
             *
             *              info._allDepends.AddRange(assetBundleManifest.GetAllDependencies(info.AbName));
             *              _assetBundleFileInfos.Add(info);
             *          }
             *          manifestAb.Unload(true);*/
        }
Esempio n. 12
0
        // 分析Asset Object信息
        private static void AnalyzeAssetObject(Object assetObject, EAssetBundleFileInfo assetbundleFileInfo)
        {
            bool inBuilt = false;
            // 1.检测类型需要符合要求
            E_AssetType assetType = AssetBundleAnallyzeObject.CheckObject(assetObject, assetbundleFileInfo, ref inBuilt);

            long size = EMemorySizeHelper.GetRuntimeMemorySize(assetObject);

            if (assetType == E_AssetType.NONE)
            {
                return;
            }

            if (_inspectorMode == null)
            {
                _inspectorMode = typeof(SerializedObject).GetProperty("inspectorMode", BindingFlags.NonPublic | BindingFlags.Instance);
            }

            // 得到guid
            SerializedObject serializedObject = new SerializedObject(assetObject);

            if (_inspectorMode != null)
            {
                _inspectorMode.SetValue(serializedObject, InspectorMode.Debug, null);
            }
            SerializedProperty pathIdProp = serializedObject.FindProperty(EAssetBundleConst.LOCAL_ID_DENTFIER_IN_FILE);

            if (pathIdProp == null)
            {
                Debug.LogError("得到Id失败:" + assetbundleFileInfo.AbName + "_" + assetObject);
                return;
            }
            long guid = pathIdProp.longValue;

            List <KeyValuePair <string, System.Object> > propertys = new List <KeyValuePair <string, object> >();

            if (AssetBundleAnallyzeObject._funMap.ContainsKey(assetType))
            {
                propertys.AddRange(AssetBundleAnallyzeObject._funMap[assetType].Invoke(assetObject, serializedObject));
            }

            if (assetbundleFileInfo.IsAssetContain(guid))
            {
                Debug.LogAssertionFormat("[{0}]已经存在了[{1}]资源", assetbundleFileInfo.AbName, assetObject.name);
                serializedObject.Dispose();
                return;
            }
            if (assetType == E_AssetType.TEXTURE)
            {
                size = (long)propertys[5].Value;
            }
            EAssetFileInfo assetFileInfo = FindAssetFile(guid, size, assetType);

            assetFileInfo._memorysize = size;
            assetFileInfo.InitAsset   = true;
            assetFileInfo._assetName  = assetObject.name;
            assetFileInfo._assetType  = assetType;
            assetFileInfo._inBuilt    = inBuilt;
            assetFileInfo._propertys  = propertys;


            if (assetObject.name.Contains("11001_N") && assetType == E_AssetType.TEXTURE)
            {
                string path = AssetDatabase.GetAssetPath(assetObject);
                Debug.Log("guid:" + guid + "_" + assetbundleFileInfo.AbName + "_" + EMemorySizeHelper.GetRuntimeMemorySize(assetObject) + "_" + size + "_" + path);
            }

            // AssetBundle包含了Asset资源
            assetbundleFileInfo.AddDepAssetFile(assetFileInfo);
            // Asset被指定的AssetBundle引用
            assetFileInfo.AddParent(assetbundleFileInfo);
            serializedObject.Dispose();

            AssetRepeatReport.AddAssetFile(assetFileInfo);
        }