Unity编辑器扩展 --- AssetPostprocessor资源导入自动设置

复制代码
unity导入资源的编辑器设置:

防止策划资源乱导入,资源导入需要的格式,统一资源管理

AssetPostprocessor资源导入管线

AssetPostprocessor用于在资源导入时自动做一些设置,比如当导入大量图片时,自动设置图片的类型,大小等。AssetPostprocessor作为资源导入的管理器,可以根据不同的资源类型,在导入前、导入后做一些处理。

示例:对图片纹理的设置需要放在OnPreprocessTexture方法中执行

cs 复制代码
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;

public class TexturePostProcessor : AssetPostprocessor
{
    void OnPreprocessTexture()
    {
        TextureImporter textureImporter = (TextureImporter)assetImporter;
        textureImporter.textureType = TextureImporterType.Default;
        textureImporter.mipmapEnabled = false;
        textureImporter.alphaIsTransparency = true;

        textureImporter.npotScale = TextureImporterNPOTScale.ToNearest;
        textureImporter.isReadable = false;
        textureImporter.wrapMode = TextureWrapMode.Clamp;

        int width = 0, height = 0;
        textureImporter.GetSourceTextureWidthAndHeight(out width, out height);
        Debug.LogErrorFormat("宽{0}, 高{1}", width, height);


        if (assetPath.Contains("Assets"))
        {
            Debug.LogError(assetPath);
        }
    }

}

一般常用的几个方法:

OnPreprocessTexture:在导入纹理贴图之前调用

OnPreprocessModel:在导入模型之前调用

OnPreprocessAudio:在导入音频之前调用

OnPostprocessTexture:在导入纹理贴图之后调用

OnPostprocessModel:在导入模型之后调用

OnPostprocessAudio:在导入音频之后调用

OnPostprocessAllAssets:所有资源的导入,删除,移动操作都会调用该方法

相关推荐
大神15731 小时前
重磅免费开放!基于B/S模式的Peach-Editor电子病历编辑器正式上线
javascript·编辑器·web
万岳科技系统开发9 小时前
外卖系统小程序开发趋势:即时零售与同城配送的融合升级
unity·游戏引擎·零售
Gene_202212 小时前
ubuntu22.04在vscode使用codex
ide·vscode·编辑器
十贺13 小时前
【Unity开发字典】分包、黏包基本概念和处理逻辑实现
unity·游戏引擎
lqqjuly15 小时前
vscode+remote-ssh+claude code+mimo-v2.5配置
ide·vscode·编辑器
2301_8059629317 小时前
Continue的安装与配置deepseek
linux·ai·编辑器
kebidaixu17 小时前
常用Vim指令
linux·编辑器·vim
淡海水17 小时前
01-认知篇-总览-HybridCLR是什么
unity·c#·aot·热更新·clr·hybrid
MrXun_19 小时前
vscode中同时连接多个远程并同时登录使用codex
ide·vscode·编辑器·codex
李白的天不白21 小时前
VSCODE 配置文件的方法
ide·vscode·编辑器