zoukankan      html  css  js  c++  java
  • unity修改所选路径下的,对象的importer属性

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

    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也可以好像。
  • 相关阅读:
    firefox native extension -- har export trigger
    配置jenkins slave 问题,ERROR: Couldn't find any revision to build. Verify the repository and branch configuration for this job.
    尝试用selenium+appium运行一个简单的demo报错:could not get xcode version. /Library/Developer/Info.plist doest not exist on disk
    ruby 除法运算
    ERB预处理ruby代码
    ruby self.included用法
    ruby include和exclude区别
    symfony安装使用
    解决git中文乱码
    读《微软的软件测试之道》有感(上)
  • 原文地址:https://www.cnblogs.com/Shaojunping/p/12332697.html
Copyright © 2011-2022 走看看