码迷,mamicode.com
首页 > 编程语言 > 详细

unity修改所选路径下的,对象的importer属性

时间:2020-02-19 20:38:32      阅读:225      评论:0      收藏:0      [点我收藏+]

标签:editor   else   unit   base   sele   item   proc   text   cti   

遍历文件夹下的对象,并修改其导入设置:

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


public class TextureOperation
{
    [MenuItem("Assets/Texture/DisableMipmapAndRW")]
    static void DisableMipmapAndRW()
    {
        UnityEngine.Object[] objs = Selection.GetFiltered(typeof(UnityEngine.Object), SelectionMode.DeepAssets);
        for (int i = 0; i < objs.Length; i++)
        {
            UnityEngine.Object obj = objs[i];
            Texture2D tex = obj as Texture2D;
            if (tex)
            {
                string texturePath = AssetDatabase.GetAssetPath(tex);
                TextureImporter ti = AssetImporter.GetAtPath(texturePath) as TextureImporter;
                if (ti)
                {
                    ti.mipmapEnabled = false;
                    ti.isReadable = false;
                    ti.SaveAndReimport();
                }
                else
                {
                    UnityEngine.Debug.LogError("========Fail to batch " + texturePath);
                }
            }
        }

    } }

  遍历所选文件夹下的 对象

 UnityEngine.Object[] objs = Selection.GetFiltered(typeof(UnityEngine.Object), SelectionMode.DeepAssets);
通过对象,拿到它的路径
 string texturePath = AssetDatabase.GetAssetPath(tex);
通过它的路径,拿到它的importer,设置其属性;然后,保存并重新导入。

AssetsProcessor类也能处理对象,然后运行reimportAll也可以好像。

unity修改所选路径下的,对象的importer属性

标签:editor   else   unit   base   sele   item   proc   text   cti   

原文地址:https://www.cnblogs.com/Shaojunping/p/12332697.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!