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

相关推荐
Codiggerworld15 小时前
Vim配置从0到1:打造专属编辑器
编辑器·vim·excel
lqj_本人17 小时前
鸿蒙electron跨端框架PC青简笔记实战:从笔记列表、编辑器到桌面导出,一次做完整
笔记·编辑器
相信神话202120 小时前
第四章:创建《酒魂》项目与场景结构
游戏·游戏引擎·godot·2d游戏开发
mxwin20 小时前
Unity Shader URP 使用模板测试 · 深度测试实现秘境空间效果
unity·游戏引擎·shader
图像僧21 小时前
没有sudo权限也能安装和使用 VSCode
ide·vscode·编辑器
咬人喵喵1 天前
E2编辑器里的零高容器是什么?怎么用?
低代码·微信·编辑器·交互·svg
真鬼1232 天前
【Unity 6】Unity6快捷下载,快速下载
unity·游戏引擎
小e说说2 天前
主流活动策划工具特点比较
编辑器
winlife_2 天前
把 Godot 编辑器接入 AI:Funplay MCP for Godot 介绍
人工智能·编辑器·godot·ai编程·游戏开发·mcp
会潜水的小火龙2 天前
unity打包apk报错Failure to initialize问题解决方法
unity·游戏引擎