言語: 日本語
  • C#
  • JS
  • Boo

スクリプト言語

お好みのスクリプト言語を選択すると、サンプルコードがその言語で表示されます。

Texture2D.SetPixels32

public function SetPixels32(colors: Color32[], miplevel: int = 0): void;

Description

ピクセルカラー配列を設定します

この関数は、Color32配列を受け取り、テクスチャ全体のミップレベルのピクセル色を変更します。 実際に変更アップロードするApplyを呼び出す グラフィックカードのピクセルに colorsの平面2次元配列、ピクセルは、右から左にレイアウトする 下から上(行の後の行)。\n配列サイズは使用されるMIPレベルのheightできまり、最低限のwidthの量でなければなりません。 デフォルトのミップレベルはゼロ(ベーステクスチャ)です\nその場合、サイズはテクスチャのサイズにぴたりと一致します。 一般的にミップレベルのサイズは\nmipWidth=max(1,width>>miplevel) そして高さも同様です。 この関数ARGB32のテクスチャフォーマットでのみ使用できます。 その他のフォーマットではSetPixels32は無視されます。 テクスチャもインポート設定で読み取り可能フラグが設定されている必要があります。 SetPixels32を使用するとSetPixelsよりも早く呼び出されます。 See Also: SetPixels, GetPixels32, GetPixels, Apply, mipmapCount.

	// This script will tint texture's mip levels in different colors
	// (1st level red, 2nd green, 3rd blue). You can use it to see
	// which mip levels are actually used and how.

	function Start () {
		// duplicate the original texture and assign to the material
		var texture : Texture2D = Instantiate(renderer.material.mainTexture);
		renderer.material.mainTexture = texture;

		// colors used to tint the first 3 mip levels
		var colors = new Color32[3];
		colors[0] = Color.red;
		colors[1] = Color.green;
		colors[2] = Color.blue;
		var mipCount = Mathf.Min( 3, texture.mipmapCount );

		// tint each mip level
		for( var mip = 0; mip < mipCount; ++mip ) {
			var cols = texture.GetPixels32( mip );
			for( var i = 0; i < cols.Length; ++i ) {
				cols[i] = Color32.Lerp( cols[i], colors[mip], 0.33 );
			}
			texture.SetPixels32( cols, mip );
		}

		// actually apply all SetPixels32, don't recalculate mip levels
		texture.Apply( false );
	}