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

相关推荐
远离UE43 小时前
UE5 如何在延时渲染在材质编辑器提前使用到多灯光的数据
ue5·编辑器·材质
bestlanzi5 小时前
vscode 常用的配置内容
ide·vscode·编辑器
晨陌y7 小时前
打工人被WPS卡顿和隐私问题折磨?document本地文档编辑器能不能作为替代方案
编辑器·wps
程序员JerrySUN11 小时前
Jetson边缘嵌入式实战课程第五讲:Jetson Secure Boot - 安全启动
android·linux·服务器·人工智能·安全·unity·游戏引擎
Zik----12 小时前
Unity 虚拟美术馆漫游系统
unity·vr·虚拟现实
十贺14 小时前
【Unity开发字典】序列化基类
unity·c#·tcp
不断学习加努力14 小时前
ubuntu22.04的vscode上部署claude的教程
ide·vscode·编辑器
Phodal14 小时前
从复杂编辑器到 Agent 工作台:Office 的 Cursor 时刻
编辑器
相醉为友15 小时前
001 VSCode图形化提交也弹出GPG密码框
ide·vscode·编辑器
莫逸雪1 天前
Nodemo使用学习
学习·编辑器·vim