前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Unity-工具-资源批处理

Unity-工具-资源批处理

作者头像
祝你万事顺利
发布2019-07-15 14:37:03
9130
发布2019-07-15 14:37:03
举报
文章被收录于专栏:Unity游戏开发

对某个文件夹下的Asset进行批处理,设置这些资源的部分属性,这些属性需要通过代码进行设置


目前版本可以批处理Texture和Audio类型的资产 都是通过设置Setting类对资产进行设置

代码语言:javascript
复制
  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
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2019.07.13 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档