unity 編輯器下 批量設置ab 與 圖片設置圖集packing tag

using UnityEngine;
using UnityEditor;

public class Tools : Editor
{
    [MenuItem("Tools/SetAB_Tag")]
    static void SetABAndTag()
    {
        string assetPath = "Assets/ab";


        string[] uids = AssetDatabase.FindAssets("t:Prefab t:Texture", new string[] { assetPath });
        if (uids == null)
        {
            return;
        }
        string uid, filePath, abName, tag;
        TextureImporter textureImporter;
        AssetImporter assetImporter;
        string[] files;


        for (int i = 0; i < uids.Length; i++)
        {
            uid = uids[i];
            filePath = AssetDatabase.GUIDToAssetPath(uid);

            assetImporter= AssetImporter.GetAtPath(filePath);
            if (assetImporter == null){
                continue;
            }            
            abName = filePath.Remove(0, assetPath.Length + 1);
            files = abName.Split('/');
            if (files.Length <= 1){
                continue;
            }

            abName = files[0];  tag = files[files.Length - 2];
            assetImporter.assetBundleName = abName;
            assetImporter.assetBundleVariant = "";

            if(assetImporter is TextureImporter)//Texture
            {
                textureImporter = (TextureImporter)assetImporter;
                if (textureImporter == null)
                {
                    continue;
                }
                textureImporter.spritePackingTag = tag;
            }

            //Debug.Log(Strings.Join("filePath  :", filePath));
        }


        AssetDatabase.SaveAssets();
        AssetDatabase.Refresh();

        EditorUtility.DisplayDialog("MyTool", "Have Set All", "OK", "");
    }
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章