Unity --- 在原目录中,将选中的Texture剥离为rgb和alpha
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System;
using UObject = UnityEngine.Object;
using System.IO; public class lgs
{
[MenuItem("Assets/AlphaSpliter ")]
static void AlphaSpliter()
{
UObject[] objs = Selection.objects;
for (int i = ; i < objs.Length; i++)
{
Texture tex = objs[i] as Texture;
CreateRGBTexture(tex);
CreateAlphaTexture(tex as Texture2D);
}
} static void CreateAlphaTexture(Texture2D src)
{
if (null == src)
throw new ArgumentNullException("src"); //create alpha texture
var srcPixels = src.GetPixels();
var targetPixels = new Color[srcPixels.Length];
for (int i = , iMax = srcPixels.Length; i < iMax; ++i)
{
float r = srcPixels[i].a;
targetPixels[i] = new Color(r, r, r);
} Texture2D alphaTex = new Texture2D(src.width, src.height, TextureFormat.ARGB32, false);
alphaTex.SetPixels(targetPixels);
alphaTex.Apply(); //save alpha texture
string srcPath = AssetDatabase.GetAssetPath(src);
string ext = Path.GetExtension(srcPath);
string newPath = string.Format("{0}{1}{2}", srcPath.Substring(, srcPath.Length - ext.Length), "_alpha", ext);
string fullPath = GetFullPath(newPath);
var bytes = alphaTex.EncodeToPNG();
File.WriteAllBytes(fullPath, bytes); AssetDatabase.SaveAssets();
AssetDatabase.Refresh(); int size = Mathf.Max(src.width, src.height, );
Setting(newPath, size, TextureImporterFormat.ETC_RGB4, TextureImporterFormat.PVRTC_RGB4);
} static void CreateRGBTexture(Texture src)
{
if (null == src)
throw new ArgumentNullException("src"); string srcPath = AssetDatabase.GetAssetPath(src);
string ext = Path.GetExtension(srcPath);
string newPath = string.Format("{0}{1}{2}", srcPath.Substring(, srcPath.Length - ext.Length), "_rgb", ext); AssetDatabase.DeleteAsset(newPath);
AssetDatabase.CopyAsset(srcPath, newPath);
AssetDatabase.ImportAsset(newPath); int size = Mathf.Max(src.width, src.height, );
Setting(newPath, size, TextureImporterFormat.ETC_RGB4, TextureImporterFormat.PVRTC_RGB4);
} static void Setting(string assetPath, int maxSize, TextureImporterFormat androidFormat, TextureImporterFormat iosFormat)
{
var texImporter = AssetImporter.GetAtPath(assetPath) as TextureImporter;
{
texImporter.npotScale = TextureImporterNPOTScale.ToNearest;
texImporter.isReadable = false;
texImporter.mipmapEnabled = false;
texImporter.alphaIsTransparency = true;
texImporter.wrapMode = TextureWrapMode.Clamp;
texImporter.filterMode = FilterMode.Bilinear;
texImporter.anisoLevel = ; //纹理的各向异性滤波水平
texImporter.SetPlatformTextureSettings("Android", maxSize, androidFormat);
texImporter.SetPlatformTextureSettings("iPhone", maxSize, iosFormat);
texImporter.SetPlatformTextureSettings("Standalone", maxSize, TextureImporterFormat.ARGB32);
} AssetDatabase.ImportAsset(assetPath);
AssetDatabase.SaveAssets();
} /// <summary>
/// asset path 转 full path
/// </summary>
public static string GetFullPath(string assetPath)
{
if (string.IsNullOrEmpty(assetPath))
return ""; string p = Application.dataPath + assetPath.Substring();
return p.Replace("\\", "/");
} /// <summary>
/// full path 转 asset path
/// </summary>
public static string GetAssetPath(string fullPath)
{
if (string.IsNullOrEmpty(fullPath))
return ""; fullPath = fullPath.Replace("\\", "/");
return fullPath.StartsWith("Assets/") ?
fullPath :
"Assets" + fullPath.Substring(Application.dataPath.Length);
}
}
Unity --- 在原目录中,将选中的Texture剥离为rgb和alpha的更多相关文章
- 因为此控件已在 web.config 中注册并且与该页位于同一个目录中
在web.config文件配置了用户控件 <pages> <controls> <add tagPrefix="my" tagName="l ...
- Word2003中如何使封面和目录中不插入页码
Word2003中如何使封面和目录中不插入页码?? 转载自: http://blog.zzedu.net.cn/user1/zhaoweijie/archives/2010/187266.html ...
- C# Unity游戏开发——Excel中的数据是如何到游戏中的 (四)2018.4.3更新
本帖是延续的:C# Unity游戏开发--Excel中的数据是如何到游戏中的 (三) 最近项目不算太忙,终于有时间更新博客了.关于数据处理这个主题前面的(一)(二)(三)基本上算是一个完整的静态数据处 ...
- python找递归目录中文件,并移动到一个单独文件夹中,同时记录原始文件路径信息
运营那边有个需求. 下载了一批视频文件,由于当时下载的时候陆陆续续创建了很多文件夹,并且,每个文件夹下面还有子文件夹以及视频文件,子文件夹下面有视频文件或者文件夹 现在因为需要转码,转码软件只能对单个 ...
- Android sdk安装目录中没有platform-tools目录问题详解
sdk下载地址 http://tools.android-studio.org/index.php/sdk 安装步骤很简单,百度即可. 下面详细说一下,在安装中遇到android sdk下没有plat ...
- Step by step 活动目录中添加一个子域
原创地址:http://www.cnblogs.com/jfzhu/p/4006545.html 转载请注明出处 前面介绍过如何创建一个域,下面再介绍一下如何在该父域中添加一个子域. 活动目录中的森林 ...
- 【Tip】如何让引用的dll随附的xml注释文档、pdb调试库等文件不出现在项目输出目录中
项目输出目录(bin/debug|release)中经常是这个样子: main.exemain.pdb a.dll a.xml b.dll b.pdb b.xml ... 其中xml是同名dll的注释 ...
- 79 umount-卸除目前挂在Linux目录中的文件系统
Linux umount命令用于卸除文件系统. umount可卸除目前挂在Linux目录中的文件系统. 语法 umount [-ahnrvV][-t <文件系统类型>][文件系统] 参数: ...
- linux复制指定目录下的全部文件到另一个目录中
linux复制指定目录下的全部文件到另一个目录中复制指定目录下的全部文件到另一个目录中文件及目录的复制是经常要用到的.linux下进行复制的命令为cp.假设复制源目录 为 dir1 ,目标目录为dir ...
随机推荐
- Hadoop组件
---------Hive--------------------------zooKeeper-------------------------------kafka---------------- ...
- PeopleSoft translate value 排序
这个function 可以对record.field 的dropdownlist 排序,也可以把描述前边加个数字.但是有时候用户不接受.所以调用这个方法是比较好的选择. Function Order_ ...
- mysql添加用户,授权,刷新权限
创建用户 CREATE USER 'test'@'localhost' IDENTIFIED BY '123456'; 赋权 GRANT ALL PRIVILEGES ON *.* TO 'test' ...
- eclipse导出可供项目引用的jar
有两种,一种是导出直接可以运行的jar,一种是导出来供其他项目引用的.在这里,说的是第二种,第一种在我博客上面也有一篇转载的.1选中项目,选择Export 2选择JAR file 然后Next 3 s ...
- Asp.Net Core WebApi 和Asp.Net WebApi上传文件
public class UpLoadController : ControllerBase { private readonly IHostingEnvironment _hostingEnviro ...
- Hadoop HDFS 用java API 进行读写
public class HdfsApp { public static FileSystem getFileSystem() throws Exception { Configuration con ...
- python中split()的用法
Python split() 通过指定分隔符对字符串进行切片,如果参数 num 有指定值,则仅分隔 num 个子字符串. 语法: str.split(str="", num=str ...
- es6中的模块化
在之前的javascript中是没有模块化概念的.如果要进行模块化操作,需要引入第三方的类库.随着技术的发展,前后端分离,前端的业务变的越来越复杂化.直至ES6带来了模块化,才让javascript第 ...
- Springboot 配置cors 跨域的几种方法
作记录用 请参考https://blog.csdn.net/lizc_lizc/article/details/81155895 第一种: 在每个controller上添加 @CrossOrigin ...
- javascript面向对象知识
<html> <head> <script></script> </head> <body> <!-- <scrip ...