美文网首页
UnityEditor脚本记录

UnityEditor脚本记录

作者: Kim_9527 | 来源:发表于2018-01-24 14:27 被阅读74次

自动对导入的Texture进行基础设置

using UnityEngine;
using UnityEditor;
using System.IO;
public class AutoAssetsImportSitting : AssetPostprocessor {

    /// <summary>
    /// Hook,用于自动设置导入Texture的设置
    /// 1.把导入的图片默认设置为Sprite
    /// 2.设置spriteMode默认为Single
    /// 3.设置Packing Tag为存放Texture的文件夹名
    /// 4.取消Mipmap的勾选
    /// 5.设置为带透明通道
    /// 6.设置Read/Write Enable状态为未勾选
    /// 7.设置wrapMode默认为Clamp
    /// </summary>
    /// <param name="texture"></param>
    void OnPostprocessTexture(Texture2D texture){
        string AtlasName = new DirectoryInfo(Path.GetDirectoryName(assetPath)).Name;
        TextureImporter textureImporter = assetImporter as TextureImporter;
        textureImporter.textureType = TextureImporterType.Sprite;
        textureImporter.spriteImportMode = SpriteImportMode.Single;
        textureImporter.spritePackingTag = AtlasName;
        textureImporter.mipmapEnabled = false;
        textureImporter.alphaIsTransparency = true;
        textureImporter.isReadable = false;
        textureImporter.wrapMode = TextureWrapMode.Clamp;
    }

}

相关文章

网友评论

      本文标题:UnityEditor脚本记录

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