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

スクリプト言語

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

MaterialPropertyBlock.AddMatrix

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Sumbission failed

For some reason your suggested change could not be submitted. Please try again in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

public function AddMatrix(nameID: int, value: Matrix4x4): void;
public void AddMatrix(int nameID, Matrix4x4 value);
public def AddMatrix(nameID as int, value as Matrix4x4) as void

Description

Matrix4x4型のマテリアルプロパティを追加します

/nameID/ でこの関数を呼び出すほうが高速になります。もし、繰り返し同じ名前のプロパティを追加する場合は、 Shader.PropertyToIDを使用してプロパティ名のユニークIDを取得し、AddMatrixにIDを渡します。

	var rotateSpeed = 30;
	var texture : Texture;
	var aMesh : Mesh;

	// Create a new material with a shader
	// that rotates the texture. Texture rotation
	// is performed with a _Rotation matrix.
	var m : Material = new Material (
		"Shader \"Rotating Texture\" {" +
			"Properties { _MainTex (\"Base\", 2D) = \"white\" {} }" +
			"SubShader {" +
			"    Pass {" +
			"        Material { Diffuse (1,1,1,0) Ambient (1,1,1,0) }" +
			"        Lighting On" +
			"        SetTexture [_MainTex] {" +
			"            matrix [_Rotation]" +
			"            combine texture * primary double, texture" +
			"        }" +
			"    }" +
			"}" +
		"}"
	);
	m.mainTexture = texture;


	function Update() {
		var materialProperty : MaterialPropertyBlock = new MaterialPropertyBlock();
		// Construct a rotation matrix and set it for the shader
		var rot : Quaternion = Quaternion.Euler (0, 0, Time.time * rotateSpeed);
		var mtrx : Matrix4x4 = Matrix4x4.TRS (Vector3.zero, rot, Vector3(1,1,1) );

		// Update the rotation matrix.
		materialProperty.AddMatrix ("_Rotation", mtrx);
		Graphics.DrawMesh(aMesh, Vector3(-5,0,0), Quaternion.identity,
				  m, 0, null, 0, materialProperty);
	}