textures | 要打包到图集中的纹理的数组。 |
padding | 打包的纹理之间的像素填充。 |
maximumAtlasSize | 生成的纹理的最大大小。 |
makeNoLongerReadable | 是否应将纹理标记为不再可读? |
Rect[] 包含每个输入纹理在图集中的 UV 坐标的矩形数组,如果打包失败,则为 null。
将多个纹理打包到一个纹理图集中。
该函数将使用由提供的纹理制作的图集替换当前纹理。
打包后,任何纹理的大小、格式和多级渐进纹理都可能发生更改。
生成的纹理图集的大小将满足所有输入纹理的需求,
但每个维度最多只能达到 /maximumAtlasSize/。如果无法将输入纹理全部装入所需大小的纹理图集,
则将输入纹理缩小后装入。
如果所有输入纹理都使用 DXT1 格式压缩,则图集将采用 DXT1 格式。
如果所有输入纹理都使用 DXT1 或 DXT5 格式压缩,
则图集将采用 DXT5 格式。如果所有输入纹理都未压缩过,
则图集将采用 RGBA32 未压缩格式。
如果所有输入纹理都没有多级渐进纹理,则图集也没有多级渐进纹理。
如果使用非零填充、图集经过压缩并且具有多级渐进纹理,则由于压缩限制,
较低级别的多级渐进纹理可能与原始纹理中的不完全相同。
如果 makeNoLongerReadable
为 makeNoLongerReadable
,则纹理将被标记为不再可读取,
并且在上传到 GPU 后内存将被释放。
默认情况下,makeNoLongerReadable
被设置为 /false/。
using UnityEngine;
public class Example : MonoBehaviour { // Source textures. Texture2D[] atlasTextures;
// Rectangles for individual atlas textures. Rect[] rects;
void Start() { // Pack the individual textures into the smallest possible space, // while leaving a two pixel gap between their edges. Texture2D atlas = new Texture2D(8192, 8192); rects = atlas.PackTextures(atlasTextures, 2, 8192); } }
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.