unity3d 代码改变贴图压缩格式

using UnityEngine;
using System.Collections;
using UnityEditor;
using System;
using System.Collections.Generic;
public class ChangeFormat : EditorWindow {
    TextureImporterFormat format = TextureImporterFormat.AutomaticCompressed;
    int size = 512;
    string platform = "Android";
    bool autoSize = false;
    [MenuItem("Image/ChangeFormat")]
    static void SetReadWriteTrue() {
        ChangeFormat changeFormat = EditorWindow.GetWindow(typeof(ChangeFormat)) as ChangeFormat;
    }

    void OnGUI() {
        GUILayout.BeginHorizontal();
        GUILayout.Label("格式:");
        format = (TextureImporterFormat)EditorGUILayout.EnumPopup(format);
        GUILayout.EndHorizontal();

        GUILayout.BeginHorizontal();
        GUILayout.Label("贴图大小:");
        size = EditorGUILayout.IntField(size);
        GUILayout.EndHorizontal();

        //GUILayout.BeginHorizontal();
        //GUILayout.Label("使用贴图原始大小:");
        //autoSize = EditorGUILayout.Toggle(autoSize);
        //GUILayout.EndHorizontal();

        GUILayout.BeginHorizontal();
        GUILayout.Label("平台:");
        platform = EditorGUILayout.TextField(platform);
        GUILayout.EndHorizontal();

        if (GUILayout.Button("开始")) {
            Execute();
        }

    }


    void Execute() {
        Debug.LogWarning("开始");
        UnityEngine.Object[] selectedAsset = Selection.GetFiltered(typeof(Texture), SelectionMode.DeepAssets);
        int currentSize = size;
        for (int i = 0; i < selectedAsset.Length; i++) {
            Texture2D tex = selectedAsset[i] as Texture2D;
            TextureImporter ti = (TextureImporter)TextureImporter.GetAtPath(AssetDatabase.GetAssetPath(tex));

            //if (autoSize) {
            //    currentSize = ti.maxTextureSize;
            //}
            ti.SetPlatformTextureSettings(platform, currentSize, format);
            AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(tex));
        }
        Debug.LogWarning("结束");
    }
}

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值