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

相关推荐
咬人喵喵20 分钟前
植树节主题核心 SVG 交互玩法 + 品牌 / 账号案例 + 组件 / 教程
前端·css·编辑器·svg·e2编辑器
鹿野素材屋1 小时前
Unity动画幅度太大怎么办
unity·游戏引擎
阴暗扭曲实习生1 小时前
基于135编辑器的SaaS/PaaS服务集成实践
java·编辑器·paas
垂葛酒肝汤2 小时前
Unity Sprite Rect 越界问题笔记
笔记·unity·游戏引擎
平行云2 小时前
数字孪生信创云渲染系列(一):混合信创与全国产化架构
unity·ue5·3dsmax·webgl·gpu算力·实时云渲染·像素流送
夏至xz3 小时前
类似 typora 的新一代 Markdown 编辑器
编辑器·typora·markdown·milkup·milkdown
White-Legend3 小时前
我用GTP5.4写了一个飞书编辑器
人工智能·gpt·编辑器·飞书·ai编程
废嘉在线抓狂.3 小时前
Unity拓展关于阵列物品生成以及物品替换
unity·游戏引擎
Ama_tor4 小时前
Visual Studio Code (VS Code) |下载与前端开发环境配置(带图详细)
ide·vscode·编辑器
阴暗扭曲实习生4 小时前
135编辑器API接口设计与开发指南
windows·编辑器