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 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); }