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

相关推荐
两水先木示41 分钟前
【Unity】探索小地图迷雾散开Shader效果(基础版)
unity·游戏引擎
WarrenMondeville8 小时前
AI复刻街头霸王到 Unity
unity·游戏引擎
玖玥拾13 小时前
Lua 基础语法(六)xLua Lua 调用 C# 交互
开发语言·unity·c#·lua
Java后端的Ai之路14 小时前
Git pull弹出vim编辑器完整排查指南
开发语言·人工智能·git·编辑器·vim
卷土重去16 小时前
第 6 章 Linux 实操篇-Vi 和 Vim 编辑器
linux·编辑器·vim
xcLeigh1 天前
Unity基础:MonoBehaviour的生命周期——Awake、OnEnable、Start、Update执行顺序
unity·游戏引擎
qq_213157891 天前
其域lcc2丢失部分lod/远处显示空洞的解决方式
unity·lcc2
辻弋2011 天前
自动检测硬件生成驱动清单、实时监控FPS、120秒性能记录——30+项优化模块化开关,所有改动可精确复原
服务器·windows·游戏引擎·电脑·开源软件
点心的游戏开发世界1 天前
GDScript 入门笔记:目录
开发语言·笔记·游戏引擎·godot
XR技术研习社1 天前
关于 PICO 串流测试中报错 IndexOutOfRangeException: renderPassIndex 的两个排障方法
unity·ar·xr·vr