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

相关推荐
猫头虎6 小时前
GoLand 2025.3 最新变化:值得更新吗?
ide·windows·macos·pycharm·编辑器·intellij-idea·idea
☆七年6 小时前
Beyond Compare 过滤干扰项设置_android项目文件过滤设置
编辑器
技术小甜甜7 小时前
[Godot] 解决导出APK安装失败的常见问题:深入分析与调试方法
游戏引擎·godot·游戏开发
恶猫8 小时前
ImHex 十六进制编辑器 v1.38.0 多语便携版
编辑器·逆向·十六进制·模式匹配·imhex
啃火龙果的兔子8 小时前
Codeium如何在vscode中使用
ide·vscode·编辑器
恶猫10 小时前
UltraEdit中文高级版
编辑器·ultraedit
老朱佩琪!12 小时前
Unity桥接模式
unity·设计模式·c#·桥接模式
技术小甜甜12 小时前
[Godot][入门] 安装与版本选择:3.x 还是 4.x?(按项目类型一键决策)
游戏引擎·godot·游戏开发·2d
陈言必行12 小时前
Unity 之 物理引擎中三种刚体力施加方式详解
unity·游戏引擎
lovingsoft12 小时前
Vscode 与 jetbrains
ide·vscode·编辑器