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:所有资源的导入,删除,移动操作都会调用该方法

相关推荐
一颗橘子宣布成为星球5 小时前
Unity AI-使用Ollama本地大语言模型运行框架运行本地Deepseek等模型实现聊天对话(一)
人工智能·unity·语言模型·游戏引擎
Tandy12356_8 小时前
Godot开发2D冒险游戏——第三节:游戏地图绘制
游戏引擎·godot
一个程序员(●—●)9 小时前
漫反射实现+逐像素漫反射+逐像素漫反射实现
unity·着色器
Humbunklung11 小时前
Visual Studio Code 使用tab键往左和往右缩进内容
ide·vscode·编辑器
weixin_4239950012 小时前
unity 读取csv
unity·c#
李詹14 小时前
游戏哪些接口会暴露源IP?_深度解析服务器通信安全隐患
游戏·游戏引擎·cocos2d·3dcoat
pink大呲花14 小时前
设置右键打开VSCode
ide·vscode·编辑器
EQ-雪梨蛋花汤19 小时前
【Flutter】Flutter + Unity 插件结构与通信接口封装
flutter·unity·游戏引擎
折纸星空Unity课堂19 小时前
Unity之基于MVC的UI框架-含案例
ui·unity·mvc
暴走约伯19 小时前
【3DMax脚本MaxScript开发:创建高效模型虚拟体绑定和材质管理系统,从3DMax到Unreal和Unity引擎_系列第一篇】
3d·unity·材质·unreal·maxscript