Unity 文档 https://docs.unity.cn/cn/current/ScriptReference/AssetPostprocessor.html Editor 文件夹下
using System.IO;
using UnityEditor;
using UnityEngine;
public class AssetPostprocessorTools : AssetPostprocessor
{
private void OnPreprocessAudio()
{
AudioImporter _importer = (AudioImporter)assetImporter;
_importer.preloadAudioData = true;
}
private void OnPreprocessAnimation()
{
ModelImporter _importer = (ModelImporter)assetImporter;
}
private void OnPreprocessModel()
{
ModelImporter _importer = (ModelImporter)assetImporter;
}
private void OnPostprocessAudio(AudioClip clip)
{
Debug.Log("导入音频:" + clip.name);
AudioImporter _importer = (AudioImporter)assetImporter;
}
private void OnPostprocessModel(GameObject g)
{
Debug.Log("导入模型:" + g.name);
}
private void OnPostprocessSprites(Texture2D texture, Sprite[] sprites)
{
Debug.Log("导入纹理:" + texture.name);
}
private static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
{
foreach (string str in importedAssets)
{
Debug.Log("导入资源: " + str);
if (str.EndsWith(".atlas"))
{
Debug.LogError("啊啊啊啊啊啊啊啊啊啊啊啊");
if (File.Exists(str))
{
File.Move(str, str + ".txt");
Debug.LogError("修改成功");
}
}
}
foreach (string str in deletedAssets)
{
Debug.Log("删除资源: " + str);
}
for (int i = 0; i < movedAssets.Length; i++)
{
Debug.Log("从:" + movedFromAssetPaths[i] + ",移动资源到:" + movedAssets[i]);
}
}
private void OnPostprocessTexture(Texture2D texture)
{
Debug.Log("导入贴图:" + texture.name);
Debug.Log("assetPath :" + assetPath);
TextureImporter textureImporter = AssetImporter.GetAtPath(assetPath) as TextureImporter;
if (textureImporter != null)
{
string AtlasName = new System.IO.DirectoryInfo(System.IO.Path.GetDirectoryName(assetPath)).Name;
textureImporter.textureType = TextureImporterType.Sprite;
textureImporter.spriteImportMode = SpriteImportMode.Single;
textureImporter.spritePackingTag = AtlasName;
textureImporter.mipmapEnabled = false;
}
}
private void OnPreprocessTexture()
{
Debug.Log("导入贴图:" + assetPath);
TextureImporter _importer = (TextureImporter)assetImporter;
_importer.textureType = TextureImporterType.Default;
_importer.mipmapEnabled = false;
_importer.isReadable = false;
var setting = _importer.GetPlatformTextureSettings("Android");
if (setting.format == TextureImporterFormat.ARGB32 || setting.format == TextureImporterFormat.RGB24)
{
Debug.Log("Android平台贴图没压缩:" + _importer.assetPath);
}
setting = _importer.GetPlatformTextureSettings("iPhone");
if (setting.format == TextureImporterFormat.ARGB32 || setting.format == TextureImporterFormat.RGB24)
{
Debug.Log("iOS平台贴图没压缩:" + _importer.assetPath);
}
}
}
|