Unity - 도구 - 리소스 배치

2294 단어
폴더 아래의 Asset을 일괄 처리하여 코드로 설정해야 하는 리소스의 일부 속성을 설정합니다.
현재 버전에서 Texture와 Audio 유형의 자산을 일괄 처리할 수 있는 것은 모두 Setting 클래스를 설정하여 자산을 설정하는 것이다
  using UnityEditor;
using UnityEngine;

using System.Collections;
using System.Collections.Generic;
using System.Linq;

public class AssetImporterTool  : Texture{
    //texture
    public delegate void texSetImporterHandler(TextureImporterSettings settings);
    [MenuItem("Tools/Assets(Texture) Set Batch",false,300)]
    static private void RunTextureAssetsSetBatch()
    {
        string selectFilePath = AssetDatabase.GetAssetPath(Selection.activeObject);

        IEnumerator enumerator = TextureAssetsSetBatch((defTexImporterSettings)=> {
            defTexImporterSettings.textureType = TextureImporterType.Sprite;
            defTexImporterSettings.wrapMode = TextureWrapMode.Clamp;
            defTexImporterSettings.mipmapEnabled = false;
        }, selectFilePath).GetEnumerator();

        EditorApplication.update = delegate ()
        {
            if (!enumerator.MoveNext())
            {
                EditorUtility.ClearProgressBar();
                EditorApplication.update = null;
            }
        };

    }
    public static IEnumerable TextureAssetsSetBatch(texSetImporterHandler setImporterHandler, string selectFilePath)
    {
        string[] texPaths = AssetDatabase.FindAssets("t:Texture", new string[] { selectFilePath })
            .Select(guid => AssetDatabase.GUIDToAssetPath(guid)).ToArray();

        for (int i = 0; i < texPaths.Length; i++)
        {
            if (EditorUtility.DisplayCancelableProgressBar("Setting... ...", texPaths[i], (float)i / (float)texPaths.Length))
            {
                yield break;
            }

            TextureImporter textureImporter = (TextureImporter)TextureImporter.GetAtPath(texPaths[i]);

            TextureImporterSettings texImporterSettings = new TextureImporterSettings();

            textureImporter.ReadTextureSettings(texImporterSettings);
            setImporterHandler(texImporterSettings);
            textureImporter.SetTextureSettings(texImporterSettings);

            textureImporter.SaveAndReimport();

            yield return null;
        }
    }

    //Model

    //Anim

    //Audio

좋은 웹페이지 즐겨찾기