unity3d脚本批量更改图片属性 编辑器插件 TextureImportSetting

通过在Unity3D的Assets Editor文件夹中创建并使用TextureImportSetting.cs脚本,可以实现批量设置贴图的导入参数。用户只需选择要处理的图片,然后在菜单栏选择Custom/Texture Import Settings,调整所需参数,点击应用即可完成批量设置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

使用说明: 在Assets文件夹下创建Editor文件夹,将复制或拷贝该代码保存成TextureImportSetting.cs放入Editor文件夹,将该脚本放入该文件夹选择需要批量设置的贴图,单击Costom/Texture Import Settings,打开窗口后选择对应参数,点击Set Texture ImportSettings,稍等片刻,批量设置成功。

unity3d脚本批量更改图片属性 编辑器插件 TextureImportSetting

using UnityEngine;
 
using System.Collections;
 
using UnityEditor;
 
///
 
///
 
///
 
///
 
///
 
///
 
///
 
///
 
public class TextureImportSetting : EditorWindow
 
{
 
///
 
/// 临时存储int[]
 
///
 
private int[] IntArray = new int[] { 0, 1, 2, 3, 4, 5, 6, 7 };
 
//AnisoLevel
 
private int AnisoLevel = 1;
 
//Filter Mode
 
private int FilterModeInt = 0;
 
private string[] FilterModeString = new string[] { “Point”, “Bilinear”, “Trilinear” };
 
//Wrap Mode
 
private int WrapModeInt = 0;
 
private string[] WrapModeString = new string[] { “Repeat”, “Clamp” };
 
//Texture Type
 
private int TextureTypeInt = 0;
 
private string[] TextureTypeString = new string[] { “Texture”, “Normal Map”, “GUI”, “Refelection”, “Cookie”, “Lightmap”, “Advanced” };
 
//Max Size
 
private int MaxSizeInt = 5;
 
private string[] MaxSizeString = new string[] { “32”, “64”, “128”, “256”, “512”, “1024”, “2048”, “4096” };
 
//Format
 
private int FormatInt = 0;
 
private string[] FormatString = new string[] { “Compressed”, “16 bits”, “true color” };
 
///
 
/// 创建、显示窗体
 
///
 
[@MenuItem(“Custom/Texture Import Settings”)]
 
private static void Init()
 
{
 
TextureImportSetting window = (TextureImportSetting)GetWindow(typeof(TextureImportSetting), true, “TextureImportSetting”);
 
window.Show();
 
}
 
///
 
/// 显示窗体里面的内容
 
///
 
private void OnGUI()
 
{
 
//AnisoLevel
 
GUILayout.BeginHorizontal();
 
GUILayout.Label(“Aniso Level  ”);
 
AnisoLevel = EditorGUILayout.IntSlider(AnisoLevel, 0, 9);
 
GUILayout.EndHorizontal();
 
//Filter Mode
 
FilterModeInt = EditorGUILayout.IntPopup(“Filter Mode”, FilterModeInt, FilterModeString, IntArray);
 
//Wrap Mode
 
WrapModeInt = EditorGUILayout.IntPopup(“Wrap Mode”, WrapModeInt, WrapModeString, IntArray);
 
//Texture Type
 
TextureTypeInt = EditorGUILayout.IntPopup(“Texture Type”, TextureTypeInt, TextureTypeString, IntArray);
 
//Max Size
 
MaxSizeInt = EditorGUILayout.IntPopup(“Max Size”, MaxSizeInt, MaxSizeString, IntArray);
 
//Format
 
FormatInt = EditorGUILayout.IntPopup(“Format”, FormatInt, FormatString, IntArray);
 
if (GUILayout.Button(“Set Texture ImportSettings”))
 
LoopSetTexture();
 
}
 
///
 
/// 获取贴图设置
 
///
 
public TextureImporter GetTextureSettings(string path)
 
{
 
TextureImporter textureImporter = AssetImporter.GetAtPath(path) as TextureImporter;
 
//AnisoLevel
 
textureImporter.anisoLevel = AnisoLevel;
 
//Filter Mode
 
switch (FilterModeInt)
 
{
 
case 0:


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值