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

相关推荐
沉默金鱼2 小时前
Unity实用技能-模型
unity·游戏引擎
阿里云云原生3 小时前
AgentRun:如何利用 AI Agent 构建现代化的舆情分析解决方案?
人工智能·unity·游戏引擎
在路上看风景4 小时前
2.8 预渲染
unity
老朱佩琪!4 小时前
Unity代理模式
unity·游戏引擎·代理模式
技术小甜甜5 小时前
【Godot】【入门】GDScript 快速上手(只讲游戏里最常用的 20% 语法)
android·游戏·编辑器·游戏引擎·godot
GDAL7 小时前
vscode 使用正则查找替换
ide·vscode·正则表达式·编辑器
拆房老料7 小时前
文档能力中台化实践:一份面向自研Office处理产品的理性技术选型说明
编辑器·开源软件
老朱佩琪!8 小时前
Unity命令模式
unity·游戏引擎·命令模式
世洋Blog8 小时前
Unity编辑器基础
unity·c#·编辑器·游戏引擎
爱喝热水的呀哈喽9 小时前
子模代数。
算法·编辑器