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的更多相关文章

  1. [Unity工具]批量修改字体

    效果图: using System.IO; using System.Text; using UnityEditor; using UnityEngine; using UnityEngine.UI; ...

  2. ansible非root用户批量修改root密码

    前言: 由于线上服务器密码长久没有更新,现领导要求批量更换密码.线上的之前部署过salt,但由于各种因素没有正常使用. 使用自动化工具批量修改的计划搁浅了,后来领导给了个python多线程修改密码脚本 ...

  3. unity工具IGamesTools之批量生成帧动画

    unity工具IGamesTools批量生成帧动画,可批量的将指定文件夹下的帧动画图片自动生成对应的资源文件(Animation,AnimationController,Prefabs) unity工 ...

  4. C#代码生成工具:文本模板初体验 使用T4批量修改实体框架(Entity Framework)的类名

    转自:http://www.cnblogs.com/huangcong/archive/2011/07/20/1931107.html 在之前的文本模板(T4)初体验中我们已经知道了T4的用处,下面就 ...

  5. unity批量修改AssetBundleName与Variant

    批量修改指定路径下的资源的AssetBundleName与Variant. 脚本代码如下: using System.Collections; using System.Collections.Gen ...

  6. 批量修改vss工作目录

    vss作为源代码版本控制工具,可以针对不同的文件夹设置不同的本地工作目录,这样可以方便我们不同的个性化需求.但是往往实际情况是,我们设置了不同的工作目录,后来却发现导致引用混乱,每个人每次获取项目文件 ...

  7. Unity3D Editor模式下批量修改prefab

    最经遇到一个需要批量修改已经做好的prefab的问题,查了一些资料最终实现了但是还是不够完美,通过学习也发现unity的编辑器功能还是非常强大的.废话不多说直接上代码: [ExecuteInEditM ...

  8. MathType中如何批量修改公式字体和大小

    MathType中如何批量修改公式字体和大小 关于MathType : MathType 是由美国Design Science公司开发的功能强大的数学公式编辑器,它同时支持Windows和Macint ...

  9. Unix时间戳转换怎样在Excel批量修改?

    最近在操作项目的时候碰到一个Unix时间戳转换的问题."date_time":1393031347这个是什么,你知道吗?如果你对Unix时间戳了解的话一眼就看出来.但我们本着科普的 ...

随机推荐

  1. JavaScript学习总结(二、隐式类型转换、eval())

    一.(避免)隐式类型转换 console.log(false == 0);   //logs true; console.log(false === 0);   //logs false; conso ...

  2. C/C++基础----动态内存

    why 管理较难,忘记释放会内存泄漏,提早释放可能非法引用,重复释放. 为了更容易,更安全的使用动态内存,提供智能指针,其默认初始化保存一个空指针. what shared_ptr允许多个指针指向同一 ...

  3. C++进阶--拥有资源句柄的类(浅拷贝,深拷贝,虚构造函数)

    // Person通过指针拥有string class Person { public: Person(string name) { pName_ = new string(name); } ~Per ...

  4. 【占位符替换】替换String中的占位符标志位{placeholder}

    概述 占位符替换, 占位符表示为:{placeholder}; 示例:替换如下{xxx}占位符中的内容 "名字:{name},年龄:{age},学校:{school}" 提供了两种 ...

  5. IE10 下系统出现Unable to get property 'PageRequestManager' of undefined or null reference错误

    在本地调试时没有任何问题,上传到测试服务器(win2003 framework 4.0)后打开网站出现Unable to get property 'PageRequestManager' of un ...

  6. bzoj5052: 繁忙的财政官

    求区间内相差最小的两个数的差 分sqrt(n)块,预处理两个数在块内,以及一个数在块内一个数在零散部分的情况,询问时归并排序处理两个数都在零散部分的情况,时间复杂度$O((n+q)\sqrt{n})$ ...

  7. july 大神 要向他学习的东西(已学了)

    交换礼物代码 库 permutations 库 product https://www.cnblogs.com/kaibindirver/p/10714375.html https://www.cnb ...

  8. 服务网关zuul之四:zuul网关配置

    禁用过滤器在Zuul中特别提供了一个参数来禁用指定的过滤器,该参数的配置格式如下:zuul.AccessFilter.pre.disable=true动态加载动态路由通过结合Spring Cloud ...

  9. Sequentially-consistent ordering

    先引入cppreference中的描述: Atomic operations tagged memory_order_seq_cst not only order memory the same wa ...

  10. Linux下自制回收站

    Linux下自制回收站 相信熟悉linux系统的人都知道rm的厉害,也大都听说过有rm造成的生产事故,本文将详细介绍如何在linux环境下制作回收站以避免数据误删除,如何恢复回收站中的数据,如何查看回 ...