public void SetAssetBundleName() { // 脑子不好,直接粗糙算法,直接按照顺序加下去 //int length = _assets_map.Count; float leftSize = EAssetBundleConst.ASSETBUILD_MAX_SIZE; string directory = EPathHelper.AbsoluteToRelativePathRemoveAssets(_directory); int nameIndex = 1; foreach (var info in _assetsMap) { string assetPath = info.Key; float fileSize = EMemorySizeHelper.CalculateTextureSizeBytes(assetPath); if (fileSize >= EAssetBundleConst.ASSETBUILD_MAX_SIZE) { SetAbName(info.Key, directory, nameIndex); nameIndex++; } else { if (leftSize >= fileSize) { SetAbName(assetPath, directory, nameIndex); leftSize = leftSize - fileSize; } else { nameIndex++; leftSize = EAssetBundleConst.ASSETBUILD_MAX_SIZE - fileSize; SetAbName(assetPath, directory, nameIndex); } } } }
public static List <KeyValuePair <string, System.Object> > AnalyzeAnimationClip(Object obj, SerializedObject serialized_object) { AnimationClip clip = obj as AnimationClip; float size = EMemorySizeHelper.GetBlobSize(clip); var propertys = new List <KeyValuePair <string, object> > { new KeyValuePair <string, object>("内存占用", size), }; return(propertys); }
public void SetInfo(List <string> content) { AnimationName = content[0]; MemSize = int.Parse((content[1])); MemSizeT = EMemorySizeHelper.GetKb(MemSize); BeRefCount = content.Count - 2; BeRefs.Clear(); for (int i = 2; i < content.Count; i++) { BeRefs.Add(content[i]); } }
public void AddTexList(Object[] objs) { foreach (Object t in objs) { if (t is Texture2D) { TexCount++; float mem = EMemorySizeHelper.GetRuntimeMemorySize(t) / 2f; TexMemSize += mem; tex_mem_map.Add(t.name, mem); } } }
public static TextureFormatInfo Create(string assetPath) { TextureFormatInfo info = GetInfo(assetPath); TextureImporter importer = AssetImporter.GetAtPath(assetPath) as TextureImporter; Debug.Assert(!(importer == null), "错误的地址:" + assetPath); if (importer == null) { return(null); } // 1.初始化纹理格式化信息 info.Path = importer.assetPath; info.ImportType = importer.textureType; info.ImportShape = importer.textureShape; info.ReadWriteEnable = importer.isReadable; info.MipmapEnable = importer.mipmapEnabled; info.IsSpriteTag = !string.IsNullOrEmpty(importer.spritePackingTag); info.AndroidFormat = GetPlatformTextureSettings(importer, AssetFormatConst.PLATFORM_ANDROID); info.IosFormat = GetPlatformTextureSettings(importer, AssetFormatConst.PLATFORM_IOS); // 计算纹理的大小内存占用 Texture texture = AssetDatabase.LoadAssetAtPath <Texture>(assetPath); info.Width = texture.width; info.Height = texture.height; info.AndroidSize = EMemorySizeHelper.CalculateTextureSizeBytes(texture, info.AndroidFormat); info.IosSize = EMemorySizeHelper.CalculateTextureSizeBytes(texture, info.IosFormat); info.MemSize = (int)(Mathf.Max(info.AndroidSize, info.IosSize)); info.FileSize = EPathHelper.GetFileSize(assetPath); if (Selection.activeObject != texture) { Resources.UnloadAsset(texture); } if (++LoadCount % 256 == 0) { Resources.UnloadUnusedAssets(); } return(info); }
// 分析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); }