[Unity工具]批量修改Texture
BatchModifyTexture.cs
using UnityEngine;
using System.Collections;
using UnityEditor;
using System.IO; public class BatchModifyTexture { [MenuItem("Assets/BatchModifyTexture")]
static void Init()
{
//获取Project视图中的选中目录下的所有图片
Object[] objects = Selection.GetFiltered(typeof(Object), SelectionMode.Unfiltered);
string dir = Application.dataPath.Substring(, Application.dataPath.LastIndexOf("/")) + "/" + AssetDatabase.GetAssetPath(objects[]);
//Debug.LogError(dir);
string[] paths = Directory.GetFiles(dir, "*.png", SearchOption.AllDirectories); //创建存放目录
string saveDir = Application.dataPath + "/BatchModifyTexture";
if (!Directory.Exists(saveDir))
{
Directory.CreateDirectory(saveDir);
} //图片处理
for (int i = ; i < paths.Length; i++)
{
string path = paths[i];
string assetPath = path.Substring(path.IndexOf("Assets/"));
string name = assetPath.Substring(assetPath.LastIndexOf("\\") + );
//Debug.LogWarning(assetPath);
//Debug.LogWarning(name); //设置成可读
TextureImporter textureImporter = AssetImporter.GetAtPath(assetPath) as TextureImporter;
textureImporter.textureType = TextureImporterType.Advanced;
textureImporter.isReadable = true;
AssetDatabase.ImportAsset(assetPath); //图片颜色变亮
Texture2D tex = AssetDatabase.LoadAssetAtPath<Texture2D>(assetPath);
Color[] colors = tex.GetPixels(, , tex.width, tex.height);
Texture2D texTemp = new Texture2D(tex.width, tex.height);
Color[] colorsTemp = new Color[colors.Length]; for (int j = ; j < colors.Length; j++)
{
colorsTemp[j] = colors[j] * 2f;
}
texTemp.SetPixels(, , tex.width, tex.height, colorsTemp);
texTemp.Apply();
byte[] bytes = texTemp.EncodeToPNG();
File.WriteAllBytes(saveDir + "/" + name, bytes);
} AssetDatabase.Refresh();
Debug.Log("BatchModifyTexture Finish");
}
}
[Unity工具]批量修改Texture的更多相关文章
- [Unity工具]批量修改字体
效果图: using System.IO; using System.Text; using UnityEditor; using UnityEngine; using UnityEngine.UI; ...
- ansible非root用户批量修改root密码
前言: 由于线上服务器密码长久没有更新,现领导要求批量更换密码.线上的之前部署过salt,但由于各种因素没有正常使用. 使用自动化工具批量修改的计划搁浅了,后来领导给了个python多线程修改密码脚本 ...
- unity工具IGamesTools之批量生成帧动画
unity工具IGamesTools批量生成帧动画,可批量的将指定文件夹下的帧动画图片自动生成对应的资源文件(Animation,AnimationController,Prefabs) unity工 ...
- C#代码生成工具:文本模板初体验 使用T4批量修改实体框架(Entity Framework)的类名
转自:http://www.cnblogs.com/huangcong/archive/2011/07/20/1931107.html 在之前的文本模板(T4)初体验中我们已经知道了T4的用处,下面就 ...
- unity批量修改AssetBundleName与Variant
批量修改指定路径下的资源的AssetBundleName与Variant. 脚本代码如下: using System.Collections; using System.Collections.Gen ...
- 批量修改vss工作目录
vss作为源代码版本控制工具,可以针对不同的文件夹设置不同的本地工作目录,这样可以方便我们不同的个性化需求.但是往往实际情况是,我们设置了不同的工作目录,后来却发现导致引用混乱,每个人每次获取项目文件 ...
- Unity3D Editor模式下批量修改prefab
最经遇到一个需要批量修改已经做好的prefab的问题,查了一些资料最终实现了但是还是不够完美,通过学习也发现unity的编辑器功能还是非常强大的.废话不多说直接上代码: [ExecuteInEditM ...
- MathType中如何批量修改公式字体和大小
MathType中如何批量修改公式字体和大小 关于MathType : MathType 是由美国Design Science公司开发的功能强大的数学公式编辑器,它同时支持Windows和Macint ...
- Unix时间戳转换怎样在Excel批量修改?
最近在操作项目的时候碰到一个Unix时间戳转换的问题."date_time":1393031347这个是什么,你知道吗?如果你对Unix时间戳了解的话一眼就看出来.但我们本着科普的 ...
随机推荐
- Git-配置difftool和mergetool
git自带的difftool和mergetool使用不习惯,配置difftool和mergetool为Beyond Compare 3. git的配置文件一般在C:\Users\用户名\.gitcon ...
- 阅读<Video Timing Controller>笔记
阅读<Video Timing Controller>笔记 1.Video Timing Controller Block Diagram 2.Example Video Timing ...
- 第一个NIOS II工程using Qsys-------Let Qsys Say Hello
1.新建工程 2.添加原理图文件 注:似乎Nios II工程都需要涉及到原理图编程. 3.进入Qsys进行内核设计 注:启动Qsys后,系统已经为内核默认添加了一个组件clk_0. 4.设置时钟名字和 ...
- 使用 Visual Studio 分析器找出应用程序瓶颈
VS的性能分析工具 性能分析工具的选择 打开一个“性能分析”的会话:Debug->Start Diagnotic Tools Without Debugging(或按Alt+F2),VS2013 ...
- [1] 注解(Annotation)-- 深入理解Java:注解(Annotation)基本概念
转载 http://www.cnblogs.com/peida/archive/2013/04/23/3036035.html 深入理解Java:注解(Annotation)基本概念 什么是注解(An ...
- Ubuntu 14.04 下安装 MongoDB 服务器 和 PHP MongoDB Driver 数据驱动
https://laravel-china.org/topics/309/install-mongodb-server-and-php-mongodb-driver-data-driver-under ...
- Django--bug--__init__() got an unexpected keyword argument 'qnique'
建立模型之后,执行迁移,报如下错误: __init__() got an unexpected keyword argument 'qnique' 错误原因:模型的属性的约束添加错误,这种错误一般就是 ...
- 【linux】之Centos6.x升级glibc
因为Centos比较保守依赖的glibc最高版本是2.12 rpm -qa|grep glibc strings /lib64/libc.so. |grep GLIBC_ 但是经常我们安装一些源码包, ...
- 【maven】之打包不带版本号的问题
今天在写maven项目的时候发现打包没有带版本号,只有包名 百思不得其解,我翻看之前的项目发现并没有这种情况,最后看了一下文档 发现是自己在build中写了fileName 导致的!删除自定义的fi ...
- Android开发之选项菜单(optinosMenu)
android一共有三种形式的菜单: 1.选项菜单(optinosMenu) 2.上下文菜单(ContextMenu) ...