unity批量修改图片

   这个Unity3D批量修改贴图导入设置工具脚本十分小巧,但是威力大。特别针对大批量贴图要调整尺寸等等的时候作用尤为明显。在菜单中添加“Custom→Texture”的方式来批量改变所选的贴图导入设置。Unity本身只能一次打开一张图片进行导入设置,目前这个脚本可以批量更改贴图格式,是否开启MipMap,调整纹理最大尺寸,是否可读等等。

    用法是把脚本放在你项目的资源目录的Editor文件夹下。然后选择你要批处理的纹理。到菜单中选择要处理的类型就可以了。

    ChangeTextureImportSettings。csforUnity2.x

    程序代码csharp代码:

using UnityEngine;
using UnityEditor;
 

public class ChangeTextureImportSettings : ScriptableObject {
 
    [MenuItem ("Custom/Texture/Change Texture Format/Auto")]
    static void ChangeTextureFormat_Auto() {
        SelectedChangeTextureFormatSettings(TextureImporterFormat.Automatic);
    }
 
    [MenuItem ("Custom/Texture/Change Texture Format/RGB Compressed DXT1")]
    static void ChangeTextureFormat_RGB_DXT1() {
        SelectedChangeTextureFormatSettings(TextureImporterFormat.DXT1);
    }
 
    [MenuItem ("Custom/Texture/Change Texture Format/RGB Compressed DXT5")]
    static void ChangeTextureFormat_RGB_DXT5() {
        SelectedChangeTextureFormatSettings(TextureImporterFormat.DXT5);
    }
 
    [MenuItem ("Custom/Texture/Change Texture Format/RGB 16 bit")]
    static void ChangeTextureFormat_RGB_16bit() {
        SelectedChangeTextureFormatSettings(TextureImporterFormat.RGB16);
    }
 
    [MenuItem ("Custom/Texture/Change Texture Format/RGB 24 bit")]
    static void ChangeTextureFormat_RGB_24bit() {
        SelectedChangeTextureFormatSettings(TextureImporterFormat.RGB24);
    }
 
    [MenuItem ("Custom/Texture/Change Texture Format/Alpha 8 bit")]
    static void ChangeTextureFormat_Alpha_8bit() {
        SelectedChangeTextureFormatSettings(TextureImporterFormat.Alpha8);
    }
 
    [MenuItem ("Custom/Texture/Change Texture Format/RGBA 16 bit")]
    static void ChangeTextureFormat_RGBA_16bit() {
        SelectedChangeTextureFormatSettings(TextureImporterFormat.ARGB16);
    }
 
    [MenuItem ("Custom/Texture/Change Texture Format/RGBA 32 bit")]
    static void ChangeTextureFormat_RGBA_32bit() {
        SelectedChangeTextureFormatSettings(TextureImporterFormat.ARGB32);
    }
 
    // ----------------------------------------------------------------------------
 
    [MenuItem ("Custom/Texture/Change Texture Size/Change Max Texture Size/32")]
    static void ChangeTextureSize_32() {
        SelectedChangeMaxTextureSize(32);
    }
 
    [MenuItem ("Custom/Texture/Change Texture Size/Change Max Texture Size/64")]
    static void ChangeTextureSize_64() {
        SelectedChangeMaxTextureSize(64);
    }
 
    [MenuItem ("Custom/Texture/Change Texture Size/Change Max Texture Size/128")]
    static void ChangeTextureSize_128() {
        SelectedChangeMaxTextureSize(128);
    }
 
    [MenuItem ("Custom/Texture/Change Texture Size/Change Max Texture Size/256")]
    static void ChangeTextureSize_256() {
        SelectedChangeMaxTextureSize(256);
    }
 
    [MenuItem ("Custom/Texture/Change Texture Size/Change Max Texture Size/512")]
    static void ChangeTextureSize_512() {
        SelectedChangeMaxTextureSize(512);
    }
    //Unity3D教程手册:www.unitymanual.com
    [MenuItem ("Custom/Texture/Change Texture Size/Change Max Texture Size/1024")]
    static void ChangeTextureSize_1024() {
        SelectedChangeMaxTextureSize(1024);
    }
 
    [MenuItem ("Custom/Texture/Change Texture Size/Change Max Texture Size/2048")]
    static void ChangeTextureSize_2048() {
        SelectedChangeMaxTextureSize(2048);
    }
 
    // ----------------------------------------------------------------------------
 
    [MenuItem ("Custom/Texture/Change MipMap/Enable MipMap")]
    static void ChangeMipMap_On() {
        SelectedChangeMimMap(true);
    }
 
    [MenuItem ("Custom/Texture/Change MipMap/Disable MipMap")]
    static void ChangeMipMap_Off() {
        SelectedChangeMimMap(false);
    }
 
    // ----------------------------------------------------------------------------
 
    static void SelectedChangeMimMap(bool enabled) {
 
        Object[] textures = GetSelectedTextures();
        Selection.objects = new Object[0];
        foreach (Texture2D texture in textures)  {
            string path = AssetDatabase.GetAssetPath(texture);
            TextureImporter textureImporter = AssetImporter.GetAtPath(path) as TextureImporter;
            textureImporter.mipmapEnabled = enabled;    
            AssetDatabase.ImportAsset(path);
        }
    }
    //Unity3D教程手册:www.unitymanual.com
    static void SelectedChangeMaxTextureSize(int size) {
 
        Object[] textures = GetSelectedTextures();
        Selection.objects = new Object[0];
        foreach (Texture2D texture in textures)  {
            string path = AssetDatabase.GetAssetPath(texture);
            TextureImporter textureImporter = AssetImporter.GetAtPath(path) as TextureImporter;
            textureImporter.maxTextureSize = size;  
            AssetDatabase.ImportAsset(path);
        }
    }
 
    static void SelectedChangeTextureFormatSettings(TextureImporterFormat newFormat) {
 
        Object[] textures = GetSelectedTextures();
        Selection.objects = new Object[0];
        foreach (Texture2D texture in textures)  {
            string path = AssetDatabase.GetAssetPath(texture);
            //Debug.Log("path: " + path);
            TextureImporter textureImporter = AssetImporter.GetAtPath(path) as TextureImporter;
            textureImporter.textureFormat = newFormat;  
            AssetDatabase.ImportAsset(path);
        }
    }
 
    static Object[] GetSelectedTextures()
    {
        return Selection.GetFiltered(typeof(Texture2D), SelectionMode.DeepAssets);
    }
}
 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
你可以使用Unity自带的重命名功能来批量更改预算节点的名称。 1. 在“Hierarchy”窗口中选择要更改名称的预算节点。 2. 右键单击所选预算节点并选择“Rename”。 3. 输入新名称并按下“Enter”键。 4. Unity会自动将所选的所有预算节点重命名为新名称。 如果你想要进一步自动化这个过程,你可以使用C#脚本来批量更改预算节点的名称。以下是一个简单的脚本示例: ```csharp using UnityEngine; using UnityEditor; public class RenameBones : EditorWindow { [MenuItem("Tools/Rename Bones")] public static void ShowWindow() { GetWindow<RenameBones>("Rename Bones"); } private string oldName = ""; private string newName = ""; private void OnGUI() { GUILayout.Label("Rename Bones", EditorStyles.boldLabel); oldName = EditorGUILayout.TextField("Old Name", oldName); newName = EditorGUILayout.TextField("New Name", newName); if (GUILayout.Button("Rename")) { foreach (GameObject obj in Selection.gameObjects) { if (obj.GetComponent<SkinnedMeshRenderer>() != null) { SkinnedMeshRenderer skinnedMeshRenderer = obj.GetComponent<SkinnedMeshRenderer>(); Transform[] bones = skinnedMeshRenderer.bones; for (int i = 0; i < bones.Length; i++) { string name = bones[i].name.Replace(oldName, newName); bones[i].name = name; } } } } } } ``` 将此脚本添加到Unity项目中,然后在Unity编辑器菜单中选择“Tools > Rename Bones”以打开重命名窗口。在窗口中输入原始名称和新名称,然后单击“Rename”按钮即可批量更改预算节点名称。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值