public static TextureInfo CreateTextureInfo(string assetPath) { if (!EditorPath.IsTexture(assetPath)) { return(null); } TextureInfo textureInfo = null; if (!_dictTexInfo.TryGetValue(assetPath, out textureInfo)) { textureInfo = new TextureInfo(); _dictTexInfo.Add(assetPath, textureInfo); } TextureImporter textureImport = AssetImporter.GetAtPath(assetPath) as TextureImporter; Texture texture = AssetDatabase.LoadAssetAtPath <Texture>(assetPath); if (textureImport == null || texture == null) { return(null); } textureInfo.Path = textureImport.assetPath; textureInfo.ImportType = textureImport.textureType; textureInfo.ImportShape = textureImport.textureShape; textureInfo.ReadWriteEnable = textureImport.isReadable; textureInfo.MipmapEnable = textureImport.mipmapEnabled; textureInfo.WrapMode = textureImport.wrapMode; textureInfo.FilterMode = textureImport.filterMode; textureInfo.StandaloneFormat = EditorTool.GetPlatformTextureSettings(textureImport, EditorConst.PlatformStandalone); textureInfo.AndroidFormat = EditorTool.GetPlatformTextureSettings(textureImport, EditorConst.PlatformAndroid); textureInfo.IosFormat = EditorTool.GetPlatformTextureSettings(textureImport, EditorConst.PlatformIos); textureInfo.StandaloneOverriden = EditorTool.IsTextureOverriden(textureImport, EditorConst.PlatformStandalone); textureInfo.AndroidOverriden = EditorTool.IsTextureOverriden(textureImport, EditorConst.PlatformAndroid); textureInfo.IosOverriden = EditorTool.IsTextureOverriden(textureImport, EditorConst.PlatformIos); textureInfo.StandaloneSize = EditorTool.CalculateTextureSizeBytes(texture, textureInfo.StandaloneFormat); textureInfo.AndroidSize = EditorTool.CalculateTextureSizeBytes(texture, textureInfo.AndroidFormat); textureInfo.IosSize = EditorTool.CalculateTextureSizeBytes(texture, textureInfo.IosFormat); textureInfo.MemSize = Mathf.Max(textureInfo.StandaloneSize, textureInfo.AndroidSize, textureInfo.IosSize); textureInfo.Width = texture.width; textureInfo.Height = texture.height; if (Selection.activeObject != texture) { Resources.UnloadAsset(texture); } if (++_loadCount % 256 == 0) { Resources.UnloadUnusedAssets(); } return(textureInfo); }
protected override void _RefreshList(List <string> list) { m_texInfoList = new List <TextureInfo>(); for (int i = 0; i < list.Count; ++i) { string path = EditorPath.FormatAssetPath(list[i]); string name = System.IO.Path.GetFileName(path); EditorUtility.DisplayProgressBar("获取贴图数据", name, (i * 1.0f) / list.Count); if (!EditorPath.IsTexture(path)) { continue; } TextureInfo texInfo = TextureInfo.CreateTextureInfo(path); if (texInfo != null) { m_texInfoList.Add(texInfo); } } EditorUtility.ClearProgressBar(); RefreshDataWithSelect(); }
public override bool IsMatch(string path) { if (AlwaysMatch) { return(true); } bool pathMatch = EditorPath.IsTexture(path) && base.IsMatch(path); if (!pathMatch || ForceSet) { return(pathMatch); } TextureImporter texureImporter = AssetImporter.GetAtPath(path) as TextureImporter; #pragma warning disable 0618 if (TexType == TextureImporterType.Cubemap) { #pragma warning restore 0618 if (texureImporter.textureShape != TextureImporterShape.TextureCube) { return(false); } else { return(true); } } else { if (texureImporter.textureShape == TextureImporterShape.TextureCube) { return(false); } } return(texureImporter.textureType == TexType); }
public static long CalcAssetSize(string assetPath, BundleType type) { assetPath = EditorPath.FormatAssetPath(assetPath); assetPath = EditorPath.NormalizePathSplash(assetPath); long ret = 0; if (m_pathFileSize.TryGetValue(assetPath, out ret)) { return(ret); } BundleImportData assetImportData = BundleDataControl.Instance.GetPathImportData(assetPath); UnityEngine.Object[] assets = null; switch (type) { case BundleType.Texture: assets = AssetDatabase.LoadAllAssetsAtPath(assetPath); for (int i = 0; i < assets.Length; ++i) { if (assets[i] is Texture) { ret += EditorTool.GetRuntimeMemorySize(assets[i]); } } break; case BundleType.Material: string[] deps = AssetDepot.GetDependenciesCache(assetPath); for (int i = 0; i < deps.Length; ++i) { if (EditorPath.IsTexture(deps[i])) { BundleImportData data = BundleDataControl.Instance.GetPathImportData(deps[i]); if (assetImportData == null || data == null || assetImportData.Index < data.Index || data.SkipData) { ret += EditorTool.CalculateTextureSizeBytes(deps[i]); } } } ret += 512; break; case BundleType.FBX: case BundleType.Controller: case BundleType.Animation: assets = AssetDatabase.LoadAllAssetsAtPath(assetPath); List <UnityEngine.Object> list = AssetFilter.FilterObjectByType(assets, type, assetPath); for (int i = 0; i < list.Count; ++i) { ret += EditorTool.GetRuntimeMemorySize(list[i]); } break; default: FileInfo fileInfo = new FileInfo(assetPath); ret = fileInfo.Length; break; } for (int i = 0; assets != null && i < assets.Length; ++i) { if ((!(assets[i] is GameObject)) && (!(assets[i] is Component))) { Resources.UnloadAsset(assets[i]); } } m_pathFileSize.Add(assetPath, ret); return(ret); }