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

相关推荐
Monkey_Xuan2 小时前
C#中的引用传递和值传递
unity·c#
CreasyChan2 小时前
C# LINQ 深度解析:优缺点与性能陷阱
unity·c#·游戏开发
bulucc4 小时前
vim 快捷操作
linux·编辑器·vim
freshman1188 小时前
Unity动画控制
unity
超超~~10 小时前
Notepad(文本编辑器)v3.6.30绿色官方版
编辑器·notepad++
IMPYLH10 小时前
Lua 的 xpcall 函数
开发语言·笔记·后端·游戏引擎·lua
shhpeng10 小时前
Visual Studio Code 下 go 开发环境搭建
ide·vscode·编辑器
为什么要内卷,摆烂不香吗11 小时前
sed 流编辑器练习自用
linux·运维·编辑器
承接电子控制相关项目1 天前
安装VSCODE发现 右击选项中无VSCODE 打开选项,处理方法汇总
ide·vscode·编辑器
AI视觉网奇1 天前
虚幻引擎 metahuman
游戏引擎·虚幻