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

スクリプト言語

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

Texture2D.SetPixels

public function SetPixels(colors: Color[], miplevel: int = 0): void;

Description

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

この関数は、色の配列を使って全体のピクセルの色を変更する 実際に変更アップロードするApplyを呼び出す グラフィックカードのピクセルに colorsの平面2次元配列、ピクセルは、右から左にレイアウトする 下から上(行の後の行)。\n配列サイズは使用されるMIPレベルのheightできまり、最低限のwidthの量でなければなりません。 デフォルトのミップレベルはゼロ(ベーステクスチャ)です\nその場合、サイズはテクスチャのサイズにぴたりと一致します。 一般的にミップレベルのサイズは\nmipWidth=max(1,width>>miplevel) そして高さも同様です。 この関数の機能はARGB32、RGB32、Alpha8のテクスチャフォーマットのみに対応しています。 その他のフォーマットの場合、SetPixelsは無視します。 テクスチャもインポート設定で読み取り可能フラグが設定されている必要があります。 setPixelsを使用すると、特に大規模なテクスチャ、繰り返し同操作を呼び出すよりも高速になります。 さらに、個々のsetPixelsはミップマップレベルにアクセスすることができる。 See Also: 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 Color[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.GetPixels( mip );
			for( var i = 0; i < cols.Length; ++i ) {
				cols[i] = Color.Lerp( cols[i], colors[mip], 0.33 );
			}
			texture.SetPixels( cols, mip );
		}

		// actually apply all SetPixels, don't recalculate mip levels
		texture.Apply( false );
	}
public function SetPixels(x: int, y: int, blockWidth: int, blockHeight: int, colors: Color[], miplevel: int = 0): void;

Description

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

この関数は、上記のSetPixelsの拡張版です。\n 全体ミップレベルだけでなくyとxで始まるblockHeightとblockWidthを返します。 colors配列はblockWidth*blockHeightのサイズでなければならず、 変更されたブロックは使用ミップレベルに適合しなければなりません。