// 选择某一条具体的规则 private void OnRuleSelected(object select, int col) { AssetFormatRule rule = select as AssetFormatRule; if (rule == null) { return; } _shows.Clear(); _formatRule = rule; List <string> pathList = EPathHelper.GetAssetsPath(rule.FilterPath, true, "*.png"); int length = pathList.Count; for (int i = 0; i < length; i++) { if (!EPathHelper.IsTexture(pathList[i])) { continue; } var tmp = TextureFormatInfo.Create(pathList[i]); _shows.Add(tmp); } _texShowTablePanel.RefreshData(_shows); }
public static TextureFormatInfo GetInfo(string assetPath) { TextureFormatInfo tInfo; if (!_dictTexInfo.TryGetValue(assetPath, out tInfo)) { tInfo = new TextureFormatInfo(); _dictTexInfo.Add(assetPath, tInfo); } return(tInfo); }
// 选择某一条具体的信息 private void OnInfoSelected(object selected, int col) { TextureFormatInfo texInfo = selected as TextureFormatInfo; if (texInfo == null) { return; } UnityEngine.Object obj = AssetDatabase.LoadAssetAtPath(texInfo.Path, typeof(UnityEngine.Object)); EditorGUIUtility.PingObject(obj); Selection.activeObject = obj; }
public void OnSearchTextures(string searchPath) { _shows.Clear(); List <string> pathList = EPathHelper.GetAssetsPath(searchPath, true, "*.*"); int length = pathList.Count; for (int i = 0; i < length; i++) { if (!EPathHelper.IsTexture(pathList[i])) { continue; } var tmp = TextureFormatInfo.Create(pathList[i]); _shows.Add(tmp); } _texShowTablePanel.RefreshData(_shows); _formatRule = null; }
public void OnFormatBtn(EButton button) { if (_formatRule == null) { return; } int length = _shows.Count; for (int i = 0; i < length; i++) { TextureFormatInfo info = _shows[i] as TextureFormatInfo; Texture2D tex2D = AssetDatabase.LoadAssetAtPath <Texture2D>(info.Path); _formatRule.ApplySettings <Texture>(tex2D, info.Path); EditorUtility.DisplayProgressBar("格式化纹理", info.Path, (float)(i + 1) / length); } EditorUtility.ClearProgressBar(); OnRuleSelected(_formatRule, 0); }
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); }