unity3d 批量修改Texture属性 两种方式加载贴图
来源:互联网 发布:迅雷会员试用一天淘宝 编辑:程序博客网 时间:2024/05/22 15:48
批量修改Texture属性
两种方式加载贴图,通过Resources.LoadAll Directoy
获取项目路径:Application.dataPath;
using UnityEngine;
using System.Collections;
using UnityEditor;
using System.IO;
public class ModifyTextureType : AssetPostprocessor
{
private static string PATH = "E:\\tcb\\program\\tcb\\tcbclient\\";
/// <summary>
/// 批量修改
/// </summary>
[MenuItem("Custom/ModifyTexture/Texture Import Settings")]
private static void Init()
{
LoopSetTexture2();
}
/// <summary>
/// 获取贴图设置
/// </summary>
public static TextureImporter GetTextureSettings(string path)
{
TextureImporter textureImporter = AssetImporter.GetAtPath(path) as TextureImporter;
//Texture Type
textureImporter.textureType = TextureImporterType.Advanced;
//Non power of2
textureImporter.npotScale = TextureImporterNPOTScale.ToNearest;
//PlatformTextureSettings
textureImporter.SetPlatformTextureSettings("iPhone", 1024, TextureImporterFormat.PVRTC_RGBA4);
textureImporter.SetPlatformTextureSettings("Android", 1024, TextureImporterFormat.ETC2_RGBA8);
return textureImporter;
}
/// <summary>
/// 循环设置选择的贴图
/// </summary>
private static void LoopSetTexture()
{
Object[] textures = GetSelectedTextures();
foreach (Texture2D texture in textures)
{
//获取资源路径
string path = AssetDatabase.GetAssetPath(texture);
TextureImporter texImporter = GetTextureSettings(path);
TextureImporterSettings tis = new TextureImporterSettings();
texImporter.ReadTextureSettings(tis);
texImporter.SetTextureSettings(tis);
AssetDatabase.ImportAsset(path);
}
}
/// <summary>
/// 获取Resources下的贴图
/// </summary>
/// <returns></returns>
private static Object[] GetSelectedTextures()
{
Object[] textureAll;
var textures = Resources.LoadAll("", typeof(Texture2D));
int countAll = textures.Length;
textureAll = new Object[countAll];
for (int i = 0; i < countAll; i++)
{
textureAll[i] = textures[i] as Object;
}
return textureAll;
}
private static void LoopSetTexture2()
{
string[] fileInfo = GetTexturePath();
int length = fileInfo.Length;
for (int i = 0; i < length; i++)
{
//获取资源路径
string path = fileInfo[i];
TextureImporter texImporter = GetTextureSettings(path);
TextureImporterSettings tis = new TextureImporterSettings();
texImporter.ReadTextureSettings(tis);
texImporter.SetTextureSettings(tis);
AssetDatabase.ImportAsset(path);
}
}
private static string[] GetTexturePath()
{
//jpg
ArrayList jpgList = GetResourcesPath("*.jpg");
int jpgLength = jpgList.Count;
//png
ArrayList pngList = GetResourcesPath("*.png");
int pngLength = pngList.Count;
//tga
ArrayList tgaList = GetResourcesPath("*.tga");
int tgaLength = tgaList.Count;
string[] filePath = new string[jpgLength + pngLength + tgaLength];
for (int i = 0; i < jpgLength; i++)
{
filePath[i] = jpgList[i].ToString();
}
for (int i = 0; i < pngLength; i++)
{
filePath[i + jpgLength] = pngList[i].ToString();
}
for (int i = 0; i < tgaLength; i++)
{
filePath[i + jpgLength + pngLength] = tgaList[i].ToString();
}
return filePath;
}
/// <summary>
/// 获取指定后掇后的文件路径
/// </summary>
/// <param name="fileType"></param>
/// <returns></returns>
private static ArrayList GetResourcesPath(string fileType)
{
DirectoryInfo directoryInfo = new DirectoryInfo(PATH + "Assets\\Resources");
ArrayList filePath = new ArrayList();
foreach (FileInfo fi in directoryInfo.GetFiles(fileType, SearchOption.AllDirectories))
{
string path = fi.DirectoryName + "\\" + fi.Name;
path = path.Remove(0, PATH.Length);
path = path.Replace("\\", "/");
filePath.Add(path);
}
return filePath;
}
}
http://blog.csdn.net/highning0007/article/details/37991287
0 0
- unity3d 批量修改Texture属性 两种方式加载贴图
- 批量修改Texture属性 两种方式加载贴图,通过Resources.LoadAll Directoy 获取项目路径:Application.dataPath; using UnityEn
- Unity3D批量修改Texture属性
- Unity3d 批量修改贴图导入设置工具脚本
- Opencv贴图的两种方式
- Unity3D Lightmap贴图加载替换
- Unity3D批量修改纹理
- Unity3D ShaderLab 混合两张贴图(Blend)
- Unity3D预制体光照贴图加载
- Unity3D 批处理修改LightMap烘培贴图
- 批量修改贴图导入设置工具脚本
- 两种方式加载配置文件
- UIImage两种加载方式
- 两种加载数据库方式
- 两种方式管理属性
- Unity3D之两种方式播放视频
- unity3d两种播放视频的方式
- 批量修改控件属性
- [学习记录]NSSetUncaughtExceptionHandler异常捕获
- typedef常见用法
- 设计模式系列——三个工厂模式(简单工厂模式,工厂方法模式,抽象工厂模式)
- offsetX、clientX、pageX等位置的计算
- (KVM连载) 5.1.3 使用virtio_balloon(KVM中的Ballooning)(上)
- unity3d 批量修改Texture属性 两种方式加载贴图
- 【vs2005学习】
- 值传递、指针传递、引用传递的区别
- Android开发环境部署
- iOS - ASI与AFN
- 《Linux开发环境搭建一》在VMware虚拟机上安装Ubuntu 10.04
- scala 及eclipse 插件安装
- Virtio:针对 Linux 的 I/O 虚拟化框架
- 一分钟实现 Android textview 跑马灯文字滚动效果