Material.Material 构造材质

static function Material (contents : string) : Material

Description描述

Create a temporary material from a shader source string.

从一个源Shader字符串创建一个材质。

If you have a script which implements a custom special effect, you implement all the graphic setup using shaders & materials. Use this function to create a custom shader & material inside your script. After creating the material, use SetColor, SetTexture, SetFloat, SetVector, SetMatrix to populate the shader property values.

如果您有一个用于实现自定义的特殊效果的脚本,您需要使用shader和材质实现所有图形设置。在您的脚本中使用此函数创建一个自定义shader和材质。创建材质后,使用 SetColor , SetTexture , SetFloat , SetVector , SetMatrix 来设置shader的属性值

// Creates an additive-blended material and uses it for rendering
//创建一个加色混合材质并用它来渲染。

var color = Color.white ;
function Start () {
	var shaderText =
	" Shader \"Alpha Additive\" {" +
	"Properties { _Color (\"Main Color \", Color ) = (1,1,1,0) }" +
	"SubShader {" +
	"    Tags { \"Queue\" = \"Transparent\" }" +
	"    Pass {" +
	"      Blend One One ZWrite Off ColorMask RGB" +
	"      Material { Diffuse [_Color] Ambient [_Color] }" +
	"      Lighting On" +
	"      SetTexture [_Dummy] { combine primary double, primary }" +
	"    }" +
	"}" +
	"}";
	renderer.material = new Material( shaderText );
	renderer.material.color = color;
}

• static function Material (shader : Shader) : Material

Description描述

Create a temporary Material from a Shader .

从一个源Shader字符串创建一个材质

If you have a script which implements a custom special effect, you implement all the graphic setup using shaders & materials. Use this function to create a custom shader & material inside your script. After creating the material, use SetColor , SetTexture , SetFloat , SetVector , SetMatrix to populate the shader property values.

如果您有一个用于实现自定义的特殊效果的脚本,您需要使用shader和材质实现所有图形设置。在您的脚本中使用此函数创建一个自定义shader和材质。创建材质后,使用 SetColor , SetTexture , SetFloat , SetVector , SetMatrix 来设置shader的属性值

// Creates a material from shader&texture references
//使用shader和纹理创建一个材质

var shader : Shader ;
var texture : Texture ;
var color : Color ;
function Start () {
	renderer.material = new Material (shader);
	renderer.material.mainTexture = texture;
	renderer.material.color = color;
}
// Creates a cube and assigns a material with a builtin Glossy shader.
//创建一个cube并且赋予它一个内建的Glossy shader材质

function Start () {
	var cube = GameObject.CreatePrimitive ( PrimitiveType.Cube );
	cube.renderer.material = new Material ( Shader.Find (" Glossy"));
}

• static function Material (source : Material) : Material

Description描述

Create a temporary Material by copying the shader and all properties from the source Material.

通过从源材质复制shader以及其所有属性创建一个实时材质。

Page last updated: 2011-1-22