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

相关推荐
风酥糖1 小时前
Godot游戏练习01-第20节-增加亿点点细节
游戏·游戏引擎·godot
智算菩萨2 小时前
【OpenGL】6 真实感光照渲染实战:Phong模型、材质系统与PBR基础
开发语言·python·游戏引擎·游戏程序·pygame·材质·opengl
_长银3 小时前
Sublime Text保持只打开一个
编辑器·sublime text
心前阳光6 小时前
Unity之ScrollRect简易实现
unity·游戏引擎
WarrenMondeville8 小时前
9.Unity面向对象-对象池
unity
螺丝钉code8 小时前
迁移到 Openrouter 后 Claude Code Vscode 插件出现了一些奇怪的问题
ide·vscode·编辑器
KaGme13 小时前
生成3DGS场景在unity中的呈现
3d·unity·游戏引擎
zyh______1 天前
关于unity的序列化
unity·游戏引擎
weixin_409383121 天前
godot碰撞测试的学习
学习·游戏引擎·godot
电子云与长程纠缠1 天前
Godot学习06 - AnimationPlayer内置动画
学习·游戏引擎·godot