Legacy Documentation: Version 2017.1 (Go to current version)
言語English
  • C#
  • JS

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

Texture2D.PackTextures

フィードバック

ありがとうございます

この度はドキュメントの品質向上のためにご意見・ご要望をお寄せいただき、誠にありがとうございます。頂いた内容をドキュメントチームで確認し、必要に応じて修正を致します。

閉じる

送信に失敗しました

なんらかのエラーが発生したため送信が出来ませんでした。しばらく経ってから<a>もう一度送信</a>してください。ドキュメントの品質向上のために時間を割いて頂き誠にありがとうございます。

閉じる

キャンセル

マニュアルに切り替える
public function PackTextures(textures: Texture2D[], padding: int, maximumAtlasSize: int = 2048, makeNoLongerReadable: bool = false): Rect[];
public Rect[] PackTextures(Texture2D[] textures, int padding, int maximumAtlasSize = 2048, bool makeNoLongerReadable = false);

パラメーター

textures Array of textures to pack into the atlas.
padding Padding in pixels between the packed textures.
maximumAtlasSize Maximum size of the resulting texture.
makeNoLongerReadable Should the texture be marked as no longer readable?

戻り値

Rect[] An array of rectangles containing the UV coordinates in the atlas for each input texture, or null if packing fails.

説明

Packs multiple Textures into a texture atlas.

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 none of the input textures have mipmaps then the atlas will also have no mipmaps.

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.

    // Source textures.
    var atlasTextures: Texture2D[];

// Rectangles for individual atlas textures. var rects: Rect[];

function Start () { // Pack the individual textures into the smallest possible space, // while leaving a two pixel gap between their edges. var atlas = new Texture2D(8192, 8192); rects = atlas.PackTextures(atlasTextures, 2, 8192); }
using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour { public Texture2D[] atlasTextures; public Rect[] rects; void Start() { Texture2D atlas = new Texture2D(8192, 8192); rects = atlas.PackTextures(atlasTextures, 2, 8192); } }