Version: 2019.3
public Rect[] PackTextures (Texture2D[] textures, int padding, int maximumAtlasSize, bool makeNoLongerReadable);

パラメーター

texturesアトラス内でパックされたテクスチャの配列
paddingパックされたテクスチャ間のパディングピクセル数。
maximumAtlasSize結果のテクスチャの最大サイズ
makeNoLongerReadableテクスチャをあらかじめ読みやすくマークしておくかどうか

戻り値

Rect[] アトラス内にある各テクスチャの UV 座標を含む長方形の配列、パッキングに失敗した場合は null。

説明

テクスチャアトラスに複数のテクスチャをパックします

This function will replace the current texture with the atlas made from the supplied textures. The size, format and mipmaps of any of the textures can change after packing.

The resulting texture atlas will be as large as needed to fit all input textures but only up to maximumAtlasSize in each dimension. If the input textures can't all fit into a texture atlas of the desired size then they will be scaled down to fit.

The atlas will have DXT1 format if all input textures are DXT1 compressed. If all input textures are compressed in DXT1 or DXT5 formats then the atlas will be in DXT5 format. If any input texture is not compressed then the atlas will be in RGBA32 uncompressed format.

入力テクスチャのどれもミップマップを持っていない場合は、アトラスもミップマップがありません。

If you use non-zero padding and the atlas is compressed and has mipmaps then the lower-level mipmaps might not be exactly the same as in the original texture due to compression restrictions.

If makeNoLongerReadable is true then the texture will be marked as no longer readable and memory will be freed after uploading to the GPU. By default makeNoLongerReadable is set to 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); } }