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

相关推荐
AIKZX12 小时前
西门子博途 TIA Portal v18 中文版图文安装教程(超级详细)附下载链接
开发语言·c#·编辑器·idea
Hy行者勇哥15 小时前
国内外与vscode类似的软件有哪些?国内那些软件可以平替?
ide·vscode·编辑器
XiaoZhangGOGOGO15 小时前
《剑来2》动画第二季点映百度网盘提取码_百度网盘提取码资源
unity
惊鸿醉16 小时前
基于Kinect SDK的Unity艺术交互展项——完整技术方案
unity
坚持就完事了17 小时前
再谈编辑器Vim
linux·编辑器·vim
MFXWW218 小时前
从 Python 到 3D 开发:Ursina 引擎零基础入门学习路径与核心开发思路
python·游戏引擎·游戏程序·ursina
mxwin1 天前
Unity URP 半透明阴影的局限性
unity·游戏引擎
空中海1 天前
第四篇:Unity高级阶段(架构级开发能力)
unity·架构·游戏引擎
小贺儿开发1 天前
【MediaPipe】Unity3D 虚拟面具互动演示
unity·人机交互·shader·摄像头·面具·互动·脸部捕捉
DaLiangChen1 天前
Unity URP 绘制参考网格 Shader 教程(抗锯齿 + 渐变淡出)
unity·游戏引擎