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

相关推荐
nuoyigui988933 分钟前
vscode中常用插件介绍xiaojie
ide·vscode·编辑器
相信神话20211 小时前
3.5《酒魂》体验与失败设计
游戏引擎·godot·godot4
陳10302 小时前
Linux:工具Vscode的简单介绍
ide·vscode·编辑器
ChampaignWolf2 小时前
VSCode Copilot 也能支持其他OpenAI兼容接口啦,可以使用其他模型(DeepSeek、Kimi、Qwen)和第三方转发API
ide·vscode·编辑器
土豆.exe2 小时前
IfAI v0.5.0 深度技术解析:120,000 行 Rust 打造的 AI-Native 编辑器
rust·编辑器·ai-native
nebula-AI2 小时前
VSCode SFTP 同步流程指南
ide·vscode·云计算·编辑器·ssh
游乐码2 小时前
Unity基础(一)游戏中的数学Mathf函数
游戏·unity·游戏引擎
ChampaignWolf3 小时前
使用VS Code编辑器将Fiori应用程序部署到SAP本地系统
编辑器
蜡台3 小时前
IDEA 编辑器两个竖线显示位置
java·编辑器·intellij-idea
skywalk81633 小时前
如何编译并手动安装vscode插件
ide·vscode·编辑器