unity在unity制作游戏过程程中,我们为什么要打包图集,打包图集的好处是啥?

参考地址:
http://blog.csdn.net/cjsen/article/details/
今天做项目大佬看我在做图集,就跟我说可以用工具打包图集,也就是TexturePacker,但是呢,好像他发的版本比较老吧,是3.0.9的,打包图集选项只有这个unity3D选项,没有什么unity-json/texture选项,所以我把打包好的导入unity那个TP工具也没有自动帮我分割好,只能用spriteEditor了
也get到了一个比较好的技能,分割不准确的时候可以自己拖动,ctrl+D复制那个框框,然后拉伸就好了
但是我还是弃用了,因为不方便,比如动画,顺序已经乱了,没办法直接拖,多不方便。
阅读(...) 评论()&求助&项目里面的图集乱了_unity3d吧_百度贴吧
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&签到排名:今日本吧第个签到,本吧因你更精彩,明天继续来努力!
本吧签到人数:0成为超级会员,使用一键签到本月漏签0次!成为超级会员,赠送8张补签卡连续签到:天&&累计签到:天超级会员单次开通12个月以上,赠送连续签到卡3张
关注:76,549贴子:
&求助&项目里面的图集乱了收藏
生成图集时,里面的图片不定时间会乱一次,然后apply N下图集就会正常,有人遇到这样的问题么?怎么解决的?求大神解答~~~~~~~
达内unity3d培训全程&实战教学&,unity3d金牌讲师授课.免费unity3d课程试听中!到达内unity3d学院学习unity3d,只需4个月速成unity3d游戏工程师.
比如可能去浏览个网页,听首歌切换回u3ds时候可能图集就乱了
图集乱的时候毫无规律怎么办啊?大神求救啊
你们的版本是不是用得asset server啊,我们之前用asset server就出现过这种问题,就是新建个项目之后,从asset server上下载项目,就有可能,我们用U盘拷贝的,需要重新下载项目的时候
不如换用svn做项目管理?
是原生的精灵图集还是ngui的
登录百度帐号推荐应用UGUI的原理则是,让开发者彻底模糊图集的概念,让开发者不要去关心自己的图集。做界面的时候只用小图,而在最终打包的时候unity才会把你的小图和并在一张大的图集里面。Editor-&Project Settings 下面有sprite packer的模式。Disabled表示不启用它,Enabled For Builds 表示只有打包的时候才会启用它,Always Enabled 表示永远启用它。 这里的启用它就表示是否将小图自动打成图集。如下图:
将需要打到一个图集的所有图片的packing tag设置成同一个名称,如下图,打包的时候unity就会把packing tag相同的图片打到一个图集上面。
但是打过图集的图片,如果有其他prefab用到其中某个图片的话,其他prefab在打包的时候就会把这个图集也打进去,所以很多公共资源就没办法打图集。为了让公共资源既能打图集,而用到这个图集里的图片的prefab打包的时候又不把这个图集打进去,所以就用TexturePacker工具打出图集给UGUI使用,具体如下:
1,从Asset Store里下载TexturePackerImporter ,然后导入到项目中。
2,下载Texturepacker工具
3,安装好之后,打开Texturepacker,把需要打包到一个图集的散图拖进去,然后设置设置 Data file和Texture file,路径是项目中放图集的文件夹路径,如下图:
然后点击导入,然后在unity中就能看到一张单独的大图,大图下面是一张张小图,这是之前导入unity的TexturePackerImporter插件帮我们做好的事情。另外注意这张大图不需要Mipmaps,因为没有镜头的拉远拉近效果,所以把勾选去掉。导入unity的除了一张大图之外还有一个.tpsheet文件,这个文件里记录了每一张小图在这张图集中的位置及其大小等信息。
本文已收录于以下专栏:
相关文章推荐
首先最暴力的方法有两个:
1.把Applications目录下的整个unity文件夹  copy 一份。
2.装两个版本的Unity。
这两个方法虽然都使用,但真的不是我们想要的。
倒是有一个靠谱的方...
UGUI的Atlas和NGUI的Atlas的区别,NGUI是必须先打出图集然后才能开始做界面。这一点很烦,因为始终都要去考虑你的UI图集。比如图集会不会超1024 ,图集该如何来规划等等。而UGUI的...
本站文章转载务必在明显处注明:原文链接 
在用UGUI时,我们也需要将一个个小图打包成图集,以减小Drawcall(类似coco2d-x一样,打包成图集一次性加载以内存换取图片读取效率),...
TexturePacker是一款非常牛逼的打图集软件,是一款收费软件。这是它的官网:/texturepacker,大家可以下到最新版本。即便如此,网...
在学习UGUI的过程中,一直使用小图也就是散图,一个按钮一个图片,一个图标一个图片,这样每一个图片都有一个Drawcall。
之前公司的游戏都是使用Unity4.3+NGUI,在NGUI中可以使用Te...
继上一篇说的更新了一张图集对应多个Text的功能,为了节省资源嘛
这里,但是也没有舍弃之前的一个Text一个图集,因为我感觉应该两个都有用,于是我重新写了一个脚本
1.其实大体跟前面的都没变,解析...
参考链接:
/archives/3304
/archives/3315
Sprite Pack...
1、将所需要的图片导入Unity中,注意不能放在Resources文件夹下
2、选择需要打包成图集的图片(可以多选)在inspector面板里选择“Texture Type“为“Sprite (2D...
自从Unity 提供 Sprite Packer 方案,精灵图片就不需要自己来合并图集了,而是设置 Packing Tag 就会使得 Unity 自动帮我们合并图集。但是做资源更新的时候,自动生成的图...
他的最新文章
讲师:姜飞俊
讲师:汪木铃
您举报文章:
举报原因:
原文地址:
原因补充:
(最多只允许输入30个字)Unity UGUI图集与TP打包结合 - 简书
Unity UGUI图集与TP打包结合
如果本文章对您有帮助,请不要吝啬您的赞
之前在没使用Lua框架的时候一直都在使用NGUI, Atlas图集其实用的很爽。但是改到UGUI之后呢没有Atlas这个东西了,挺不习惯的。遂根据NGUI的形式写了这个工具
我简单的说下UGUI动态更改sprite的方法,一般情况是在Reasouce里面加载图片然后转成sprite,然后改变Image的sprite,但是这样做其实很麻烦。而且结合TP打包图集也不是很好做,因为这样你需要LoadAll。如果把TP的png放在Resouce里面也会产生*2的包大小,他会重新打包两边。
相当于自己建立一个Atlas的工具类,然后用所有图片都是保存在prefab上,把prefab放在Resouce下。这样打包出来的体积也会小很多。接下来就开始上代码咯为了方便,我把从png转化为prefab的过程写了个插件。ps:TP打包出来png图片必须是sprite格式。
using UnityE
using System.C
using UnityE
public class UIAtalsEditor
[MenuItem("Assets/Create/创建当前选中图集")]
public static void CreateAtlasPrefab()
if(Selection.activeObject !=null)
string path = AssetDatabase.GetAssetPath(Selection.activeObject);
TextureImporter importer =AssetImporter.GetAtPath(path) as TextureI
if(importer != null && importer.textureType ==TextureImporterType.Sprite &&importer.spriteImportMode == SpriteImportMode.Multiple)
UIAtals atlas = ScriptableObject.CreateInstance&UIAtals&();
object[] objs = AssetDatabase.LoadAllAssetsAtPath(path);
atlas.spriteLists.Clear();
foreach (object o in objs)
if(o.GetType() == typeof(Texture2D))
atlas.mainText = o as Texture2D;
else if(o.GetType() == typeof (Sprite))
atlas.spriteLists.Add(o as Sprite);
AssetDatabase.CreateAsset(atlas, path.Replace(".png", "_Atlas.prefab"));
AssetDatabase.Refresh();
Debug.Log("当前选中的不是图集图片");
using UnityE
using System.C
using UnityE
[CustomEditor(typeof(UIAtals))]
public class UIAtlasInspector : Editor
public override void OnInspectorGUI()
UIAtals atlas = target as UIA
atlas.mainText = EditorGUILayout.ObjectField("MainTextture", atlas.mainText, typeof(Texture2D)) as Texture2D;
if (GUILayout.Button("刷新数据"))
if (atlas.mainText == null)
string path = EditorUtility.OpenFilePanel("选着一张图集", Application.dataPath, "png");
if (!string.IsNullOrEmpty(path))
atlas.mainText = AssetDatabase.LoadAssetAtPath(path, typeof(Texture2D)) as Texture2D;
if (atlas.mainText != null)
string path = AssetDatabase.GetAssetPath(atlas.mainText);
TextureImporter importer = AssetImporter.GetAtPath(path) as TextureI
if (importer != null && importer.textureType == TextureImporterType.Sprite
&& importer.spriteImportMode == SpriteImportMode.Multiple)
Object[] objs = AssetDatabase.LoadAllAssetsAtPath(AssetDatabase.GetAssetPath(atlas.mainText));
atlas.spriteLists.Clear();
foreach (Object o in objs)
if (o.GetType() == typeof(Texture2D))
atlas.mainText = o as Texture2D;
else if (o.GetType() == typeof(Sprite))
atlas.spriteLists.Add(o as Sprite);
atlas.mainText =
if (atlas.spriteLists.Count & 0)
foreach (Sprite s in atlas.spriteLists)
EditorGUILayout.ObjectField(s.name, s, typeof(Sprite));
以上两个类都是编辑器类, 需要放在Editor特殊文件夹里面,放进去之后,对着打包好的tppng图片邮件,create就有创建当前这个选项了。会在当前目录下 生成一个atlas,放入resouce.
using UnityE
using System.C
using UnityEngine.UI;
using System.Collections.G
public class UIAtals : ScriptableObject
public Texture2D mainT
public List&Sprite& spriteLists = new List&Sprite&();
/// &summary&
/// 根据图片名称获取sprite
/// &/summary&
/// &param name="spritename"&图片名称&/param&
/// &returns&&/returns&
public Sprite GetSprite(string spritename)
return spriteLists.Find((Sprite s) =& { return s.name == });
/// &summary&
/// 设置Image的Sprite
/// &/summary&
/// &param name="im"&Image&/param&
/// &param name="spritename"&图片名称&/param&
public void SetSprite(ref Image im, string spritename)
if(im == null)
Sprite sp = GetSprite(spritename);
if(sp !=null)
im.overrideSprite =
Debug.Log("图集没有对应的图片:"+ spritename);
这是一个图集管理类,其中有获取sprite 和 设置sprite的方法。
测试类如下:
using UnityE
using System.C
using System.Collections.G
using UnityEngine.UI;
public class DrawNote
public static Dictionary&string, UIAtals& atlasmanage = new Dictionary&string, UIAtals&();
/// &summary&
/// 设置滑动条宽度
/// &/summary&
/// &param name="obj"&滑动条&/param&
/// &param name="posx"&x坐标&/param&
/// &param name="posy"&y坐标&/param&
public static void SetContent(GameObject obj,int posx,int posy)
obj.gameObject.GetComponent&RectTransform&().sizeDelta =new Vector2(posx,posy);
/// &summary&
/// 动态生成图片
/// &/summary&
/// &param name="spitename"&图片名称&/param&
/// &returns&&/returns&
public static Image LoadImage(Sprite sprite,Transform parenttrs,int posx ,int posy,float offsetX)
GameObject go = new GameObject(sprite.name);
go.layer = LayerMask.NameToLayer("UI");
go.transform.parent =
Image image = go.AddComponent&Image&();
image.sprite =
image.rectTransform.pivot = new Vector2(0, 0);
image.rectTransform.localPosition = new Vector3(posx+ offsetX, posy, 0);
image.SetNativeSize();
/// &summary&
/// 加载图集
/// &/summary&
/// &param name="spriteName"&图集名称&/param&
public static UIAtals LoadAtals(string atlasName)
UIAtals atlas = Resources.Load&UIAtals&(atlasName);
atlasmanage.Add(atlasName, atlas);
/// &summary&
/// 生成note图片
/// &/summary&
/// &param name="atlasName"&Altas名称&/param&
/// &param name="spriteName"&精灵名称&/param&
/// &param name="parenttrs"&父节点&/param&
/// &param name="posx"&x坐标&/param&
/// &param name="posy"&y坐标&/param&
public static Image CreateImage(string atlasName,string spriteName,Transform parenttrs,string posx ,string posy ,float offsetX)
int iposx = int.Parse(posx);
int iposy = int.Parse(posy);
if(!atlasmanage.ContainsKey(atlasName))
atlas=LoadAtals(atlasName);
atlas = atlasmanage[atlasName];
Image img=LoadImage(atlas.GetSprite(spriteName),parenttrs, iposx,iposy, offsetX);
atlas.SetSprite(ref img, spriteName);
img.raycastTarget =
/// &summary&
/// 小节线图片生成
/// &/summary&
/// &param name="atlasName"&图集名称&/param&
/// &param name="spriteName"&图片名称&/param&
/// &param name="parenttrs"&父节点&/param&
/// &param name="posx"&坐标&/param&
/// &param name="offsetX"&偏移量&/param&
/// &param name="wight"&图片宽度&/param&
/// &param name="height"&图片高度&/param&
/// &returns&&/returns&
public static Image CreateMeasure(string atlasName, string spriteName,Transform parenttrs, string posx, float offsetX, float wight, float height)
int iposx = int.Parse(posx);
if (!atlasmanage.ContainsKey(atlasName))
atlas = LoadAtals(atlasName);
atlas = atlasmanage[atlasName];
Sprite sprite = atlas.GetSprite(spriteName);
GameObject go = new GameObject(sprite.name);
go.layer = LayerMask.NameToLayer("UI");
go.transform.parent =
Image image = go.AddComponent&Image&();
image.sprite =
image.rectTransform.pivot = new Vector2(0, 0);
image.rectTransform.localPosition = new Vector3(iposx + offsetX, 0, 0);
image.SetNativeSize();
image.rectTransform.sizeDelta = new Vector2(wight, height);
大家可以根据我这个测试类改,我是因为需要导入lua所以写的繁琐了一点,不过相信代码还是很清楚的。
宏愿纵未了,奋斗也不太晚。

我要回帖

更多关于 unity打包过程 的文章

 

随机推荐