Unity 使用TexturePackerGUI打包图集 Sprite 图片边上有线

原来遇到的问题 保存下解决方法

修改Shape Padding图片间距的值为4

转载于:https://www.cnblogs.com/zouqiang/p/6844979.html

Unity中,当你创建一个Sprite Atlas并使用它来打包多个Sprite时,你可能需要获取这个图集在构建后占用的具体大小。这可以通过编写脚本来实现,以便在构建过程之后获取图集的大小信息。以下是如何通过脚本实现这一功能的基本步骤: 1. 在Unity编辑器中,创建一个新的C#脚本,命名为例如`SpriteAtlasSizeReporter.cs`。 2. 将这个脚本附加到一个空的GameObject上。 3. 在脚本中,你需要使用`Resources.Load`方法来加载你的Sprite Atlas资源。 4. 之后,使用Unity的`SpriteAtlas.GetPackedSheet`方法来获取图集的详细信息。 5. 通过这些信息,你可以计算出图集的总宽度和高度,这通常基于图集中的每个元素的大小以及它们如何被排列。 以下是一个简单的代码示例,展示了如何获取Sprite Atlas的打包后的图集大小: ```csharp using UnityEngine; using UnityEngine.U2D; using UnityEngine.SpriteRuntimeAtlas; public class SpriteAtlasSizeReporter : MonoBehaviour { void Start() { // 加载指定的Sprite Atlas资源 SpriteAtlas atlas = Resources.Load<SpriteAtlas>("YourSpriteAtlasName"); if (atlas == null) { Debug.LogError("Sprite Atlas not found!"); return; } // 获取图集打包信息 PackedSheet packedSheet = atlas.GetPackedSheet(); if (packedSheet == null) { Debug.LogError("Could not get packed sheet for the atlas."); return; } // 计算图集的大小 int totalWidth = packedSheet.rect.width; int totalHeight = packedSheet.rect.height; Debug.Log($"Sprite Atlas Size: {totalWidth} x {totalHeight}"); } } ``` 请将`"YourSpriteAtlasName"`替换为你的实际Sprite Atlas的名称。 在使用上述脚本之前,确保你的Sprite Atlas已经被正确添加到Resources文件夹中,以便可以通过`Resources.Load`方法加载。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值