Sprite Editor 图集切片精灵
切图需求
假设有一张大的UI的图集,我们想把它里面的小图一张一张地切割出来,如果有plist文件,请查阅我的另一篇文章《还原TexturePacker plist 文件 切开各小图片》
今天我们使用 Unity4.3或更高版本自带的 Sprite Editor 来导出切片精灵
切图效果



步骤
1、准备一张大的图集,导入Unity的Asset/Resources/XXX/文件夹下(注意:图集文件一定要放在Resources文件下)

2、该图集默认是Texture,我们需要把它的Type修改成Sprite


3、接着修改Sprite Mode为Multiple,应用。然后点击 Sprite Editor

4、在打开的Sprite Edirot 窗口中把图集切成多个Sprite


插件代码
5、编写TestExportSprite.cs,放在Editor目录下
using UnityEngine;
using UnityEditor; public class TestExportSprite
{ [MenuItem("Assets/导出选中图片为单独png")]
static void ExportSelSprite()
{
string resourcesPath = "Assets/Resources/";
foreach (Object obj in Selection.objects)
{
string selectionPath = AssetDatabase.GetAssetPath(obj); // 必须最上级是"Assets/Resources/"
if (selectionPath.StartsWith(resourcesPath))
{
string selectionExt = System.IO.Path.GetExtension(selectionPath);
if (selectionExt.Length == )
{
continue;
} // 得到导出路径
string loadPath = selectionPath.Remove(selectionPath.Length - selectionExt.Length);
loadPath = loadPath.Substring(resourcesPath.Length); // 加载此文件下的所有资源
Sprite[] sprites = Resources.LoadAll<Sprite>(loadPath);
if (sprites.Length > )
{
// 创建导出文件夹
string outPath = Application.dataPath + "/outSprite/" + loadPath;
System.IO.Directory.CreateDirectory(outPath); foreach (Sprite sprite in sprites)
{
// 创建单独的纹理
Texture2D tex = new Texture2D((int)sprite.rect.width, (int)sprite.rect.height, sprite.texture.format, false);
tex.SetPixels(sprite.texture.GetPixels((int)sprite.rect.xMin, (int)sprite.rect.yMin,
(int)sprite.rect.width, (int)sprite.rect.height));
tex.Apply(); // 写入成PNG文件
System.IO.File.WriteAllBytes(outPath + "/" + sprite.name + ".png", tex.EncodeToPNG());
}
Debug.Log(string.Format("Export {0} to {1}",loadPath,outPath));
}
}
}
Debug.Log("Export All Sprites Finished");
}
}
5、使用Sprite Editor把图集切割成Sprite之后,修改图集的属性为Advanced,并勾选 Read/Write Enabled 和Transpare

否则当你导出切片时会报错
UnityException: Texture 'UIAtlas' is not readable, the texture memory can not be accessed from scripts. You can make the texture readable in the Texture Import Settings.
UnityEngine.Texture2D.GetPixels (Int32 x, Int32 y, Int32 blockWidth, Int32 blockHeight) (at C:/BuildAgent/work/aeedb04a1292f85a/artifacts/EditorGenerated/TextureBindings.cs:)
TestSaveSprite.SaveSprite () (at Assets/Editor/TestSaveSprite.cs:)
5、在Resources目录下选中UIAtlas.psd,右键,选择“导出选中图片为单独png

说明
部分内容参考自:http://blog.csdn.net/akof1314/article/details/38845933
Sprite Editor 图集切片精灵的更多相关文章
- Unity 导出切片精灵
http://blog.csdn.net/akof1314/article/details/38845933 设有一张png/tga图集,导入到Unity,放置目录"Assets/Resou ...
- Sprite Editor
[Sprite Editor] 在Unity3D中,一个图片可以有多种类型(如下图).对于2D游戏开发,最常用的类型就是Sprite. 下图是Sprite Texture的属性,Packing Tag ...
- 15、Cocos2dx 3.0游戏开发找小三之Sprite:每一个精灵都是上辈子折翼的天使
重开发人员的劳动成果,转载的时候请务必注明出处:http://blog.csdn.net/haomengzhu/article/details/30475395 Sprite Sprite 能够说是 ...
- NGUI使用图集的精灵换图片
创建了一个sprite,选择的是某一个图集下的sprite,现在我想点击它来换图片.前提是你的sprite已经加了UIButton 代码如下: public void OnClick() { if ( ...
- [置顶]
Unity2d引入新功能SpriteAtlas,Sprite新的图集方式
孙广东 2017.8.3 http://blog.csdn.NET/u010019717 在Unity 2017.1.0f3中引入了 SpriteAtlas 官方文档: https://docs. ...
- cocos2d-x 3.1.1 学习笔记[2]Sprite 精灵
Sprite应该是用到最多的一个类吧.无法想像一个游戏没有精灵将怎样进行愉快的玩耍. Sprite继承于Node 和 TextureProtocol. Sprite是一个2d的图像. Sprite能够 ...
- unity sprite怎么获取切割后的图
学习了一段时间的unity,对里面的组件有一个大致的了解,但是具体操作来说还不是很熟悉,今天看了一片关于unity sprite怎么获取切割后的图的文章,感觉还不错. 假设有一张png/tga图集,导 ...
- NGUI中Button与原生2D精灵的混合使用
一些废话 每一篇的首段都是这个“一些废话”,原因是我太能逼逼了,不逼逼一些废话我就觉得难受.这是我第四篇关于Unity的博文,前两篇还是去年写的,“从一点儿不会开始”系列,类似教程和学习笔记的博文,这 ...
- unity3d插件Daikon Forge GUI 中文教程3-基础控件Button和Sprite的使用
2.2添加一个按钮Button 来看看特有的属性:Button Properties Data 显示的文本 Behavior 中的几个: Aoto Size 选中时就是按钮的背景会根据Data中的文本 ...
随机推荐
- 单例(Singleton pattern)模式的七种写法
转载请注明出处:http://www.cnblogs.com/smbk/ One: public class Singleton { private static Singleton instance ...
- C#生成条形码 Code128算法
条形有很多种,Code128是比较常用的一种,是一种高密度条码, CODE128 码可表示从 ASCII 0 到ASCII 127 共128个字符,故称128码.其中包含了数字.字母和符号字符. Co ...
- SQL 语句日期用法及函数
SQL 语句日期用法及函数 --DAY().MONTH().YEAR()——返回指定日期的天数.月数.年数:select day(cl_s_time) as '日' from class --返回天 ...
- 0728关于html的几个基础知识点
1.文本的格式化. 文本的格式包括粗体,斜体等.<b></b>定义粗体,<i>定义斜体</i>,<del></del> 定义删除 ...
- Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Widget.Button.Inverse'.
改下build.gradle文件,将里面的compileSdkVersion改为23即可 apply plugin: 'com.android.application' android { compi ...
- Sharepoint学习笔记—习题系列--70-573习题解析 -(Q94-Q96)
Question 94You need to create a custom application that provides users with the ability to create a ...
- 《C程序设计的抽象思维》2.10编程练习(未完)
本文地址:http://www.cnblogs.com/archimedes/p/programming-abstractions-in-c-2.html,转载请注明源地址. 2.按照规定求圆柱的表面 ...
- Undefined symbols for architecture i386:和"_OBJC_CLASS_$_xx", referenced from:问题解决方法
多个人共同操作同一个项目或拷贝项目时,经常会出现类似这样的问题: Undefined symbols for architecture i386: "_OBJC_CLASS_$_xx文件名& ...
- C语言-04-函数
函数 函数是一组一起执行任务的语句,函数是一个可执行C程序必不可少的条件(至少一个main()函数),函数的定义形式 returnType functionName() { bodyOf of the ...
- 附带详细注释的log4net的app.config文件配置例子
<?xml version="1.0" encoding="utf-8" ?> <configuration> <configSe ...