当前位置: 首页 > news >正文

Unity 批量将图片从默认类型改为Sprite类型

先将该脚本放到Editor目录下

如何使用:选中目录,然后点击Tool里面的批量修改按钮

using System;
using UnityEngine;
using UnityEditor;
using System.IO;
using System.Linq;/// <summary>
/// 此工具可以批量将图片类型修改为精灵
/// </summary>
public class TextureTypeModifier
{[MenuItem("Tools/批量修改图片为Sprite(2D and UI)", false, 20)]private static void ConvertSelectedFolderToSprite(){// 获取选中的文件夹路径string folderPath = AssetDatabase.GetAssetPath(Selection.activeObject);if (!AssetDatabase.IsValidFolder(folderPath)){EditorUtility.DisplayDialog("错误", "请选择一个文件夹!", "确定");return;}// 递归获取所有图片文件string[] imagePaths = Directory.GetFiles(folderPath, "*.*", SearchOption.AllDirectories).Where(file => file.EndsWith(".png", StringComparison.OrdinalIgnoreCase) ||file.EndsWith(".jpg", StringComparison.OrdinalIgnoreCase) ||file.EndsWith(".jpeg", StringComparison.OrdinalIgnoreCase)).ToArray();int modifiedCount = 0;// 批量修改foreach (string imagePath in imagePaths){if (imagePath.EndsWith(".meta")) continue;TextureImporter importer = AssetImporter.GetAtPath(imagePath) as TextureImporter;if (importer != null&& importer.textureType==TextureImporterType.Default && importer.textureType != TextureImporterType.Sprite){importer.textureType = TextureImporterType.Sprite;importer.spriteImportMode = SpriteImportMode.Single;importer.mipmapEnabled = false;importer.SaveAndReimport();modifiedCount++;}}AssetDatabase.Refresh();EditorUtility.DisplayDialog("完成", $"已将 {modifiedCount} 张图片转换为 Sprite(2D and UI)\n目录: {folderPath}", "确定");}// 验证菜单项是否可用(仅当选中文件夹时显示)[MenuItem("Tools/批量修改图片为Sprite(2D and UI)", true, 20)]private static bool ValidateConvertSelectedFolderToSprite(){return Selection.activeObject != null && AssetDatabase.IsValidFolder(AssetDatabase.GetAssetPath(Selection.activeObject));}
}
http://www.dtcms.com/a/195543.html

相关文章:

  • 【Linux网络】详解应用层http协议
  • 基于大数据的租房信息可视化系统的设计与实现【源码+文档+部署】
  • 深度学习中的归一化:提升模型性能的关键因素
  • 城市综合管廊监测与维护一体化解决方案
  • C++运算符重载练习
  • 【python编程从入门到到实践】第十章 文件和异常
  • 遥感图像非法采矿矿区识别分割数据集labelme格式1818张3类别
  • 人脸表情识别检测数据集VOC+YOLO格式9400张8类别
  • linux环境下 安装svn并且创建svn版本库详细教程
  • python中元组的操作
  • 149.WEB渗透测试-MySQL基础(四)
  • 三轴云台之智能分析与识别技术篇
  • 蒟蒻编程日志
  • 腾讯云代码助手CodeBuddy使用体验
  • 第八章 模板项目生成
  • Matrix-Game:键鼠实时控制、实时生成的游戏生成模型(论文代码详细解读)
  • SPL做量化---MTM(动量指数)
  • Linux!启动~
  • 大模型对比
  • Grafana分布统计:Heatmap面板
  • 计算机视觉----感兴趣区域(ROI)、非极大值抑制
  • 探究电阻分压的带负载能力
  • DeepEval:快速搭建 LLM 评估框架实战「喂饭教程」
  • 机器学习数据预处理回归预测中标准化和归一化
  • C语言单链表应用详解
  • 【程序员AI入门:模型】19.开源模型工程化全攻略:从选型部署到高效集成,LangChain与One-API双剑合璧
  • 【目标检测】RT-DETR
  • PT2031K单触控单输出触摸IC
  • 【数据结构】线性表--栈
  • 网络攻防模拟:城市安全 “数字预演”