unity修改所选路径下的,对象的importer属性
Posted shaojunping
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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也可以好像。
以上是关于unity修改所选路径下的,对象的importer属性的主要内容,如果未能解决你的问题,请参考以下文章