Version: 2022.3
言語: 日本語
遅延バインディング
スプライトパッカー

さまざまなスプライトアトラスのシナリオの解決

Unity がスプライトとスプライトアトラス間の相互作用を解決する方法は、さまざまな条件に依存します。以下の例では、最も一般的なシナリオを詳しく説明しています。

シナリオ 1: 基本的なスプライトアトラスの使用法

  1. Sprite Atlas A contains Sprite 1.
  2. Sprite Atlas A has Include in Build enabled.
  3. Result: The Project’s published build includes Sprite Atlas A. Sprite 1 renders with the Texture from Sprite Atlas A.

シナリオ 2: ‘Include in Build’ は無効

  1. Sprite Atlas A contains Sprite 1.
  2. Sprite Atlas A has Include in Build disabled.
  3. Result: The Project’s published build does not include Sprite Atlas A, and does not include Sprite 1’s Texture. Sprite 1 appears invisible in the build at run time, because the Texture it refers to is not available and is not loaded.

シナリオ 3: 2 つのスプライトアトラス内に 1 つのスプライト

  1. Sprite Atlas A and Sprite Atlas B both include Sprite 1 in their Objects for Packing lists.
  2. Both Sprite Atlas A and Sprite Atlas B have Include in Build enabled.
  3. Both Sprite Atlases have different Texture output settings in this example.
  4. Result: The Project’s published build includes both Sprite Atlases. Unity randomly chooses which Texture to render Sprite 1 with, in an internal process that is out of your control.

このシナリオで、意図するスプライトアトラスからのテクスチャでスプライトをレンダリングするには、以下の手順を行います。

  1. Disable ‘Include in Build’ for both Sprite Atlases.
  2. ランタイムにスプライトを初期化するときに、SpriteAtlas.GetSprite を使って 1 つのアトラスから直接スプライトをリクエストします。これにより、常に正しいスプライトアトラスからスプライトテクスチャを描画できます。
遅延バインディング
スプライトパッカー