美文网首页
【Unity】资源导入前的操作

【Unity】资源导入前的操作

作者: 木心Sepith | 来源:发表于2019-01-12 13:34 被阅读10次

可以通过继承AssetPostprocessor来进行


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System.IO;

public class UISpriteImporter : AssetPostprocessor
{

    //导入图片资源
    void OnPreprocessTexture()
    {
        //判断目录
        if (!assetPath.Contains("UI/UISprites")) return;
        string tag = Path.GetFileName(Path.GetDirectoryName(assetPath));

        //自动设置类型;
        TextureImporter textureImporter = (TextureImporter)assetImporter;
        textureImporter.textureType = TextureImporterType.Sprite;
        textureImporter.wrapMode = TextureWrapMode.Clamp;
        textureImporter.npotScale = TextureImporterNPOTScale.None;
        textureImporter.isReadable = true;
        textureImporter.mipmapEnabled = false;
        textureImporter.maxTextureSize = 2048;
        textureImporter.spritePackingTag = tag;
        textureImporter.spriteImportMode = SpriteImportMode.Single;
    }
}

相关文章

网友评论

      本文标题:【Unity】资源导入前的操作

      本文链接:https://www.haomeiwen.com/subject/tubqdqtx.html