Shader.Find 查找

static function Find (name : string) : Shader

Description描述

Finds a shader with the given name.

查找名为name的着色器。

Shader.Find can be used to switch to another shader without having to keep a reference to the shader. name is the name you can see in the shader popup of any material. Common names are: "Diffuse", "Bumped Diffuse", "VertexLit", "Transparent/Diffuse" etc.

Shader.Find能够用来切换到另一个着色器,而不必保持一个到该着色的引用。name是你可以在任意材质的shader弹出窗口看到。通常的名称是:"Diffuse", "Bumped Diffuse", "VertexLit", "Transparent/Diffuse"等等。

When building a player, a shader will only be included if it is assigned to a material that is used in any scene or if the shader is placed in a "Resources" folder.

在编译时,只包含那些使用中的shader或位置在"Resources"文件夹中shader。

参见: Material

using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
	void Start() {
		renderer.material.shader = Shader.Find("Transparent/Diffuse");
	}
}
// Switch the shader from code
//从代码切换着色器
function Start () {
	// Switch to the transparent diffuse shader
	//切换到transparent diffuse着色器
	renderer.material.shader = Shader.Find ("Transparent/Diffuse");
}

另一个例子:

using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
	void Start() {
		Material material = new Material(Shader.Find("Transparent/Diffuse"));
		material.color = Color.green;
		renderer.material = material;
	}
}
// Create a material from code
//从代码创建一个材质
function Start () {
	// Create a material with transparent diffuse shader
	//创建一个带有transparent diffuse着色器的材质
	var material = new Material (Shader.Find ("Transparent/Diffuse"));
	material.color = Color.green;
	// assign the material to the renderer
	//指定材质到渲染器
	renderer.material = material;
}
最后修改:2011年3月31日 Thursday 17:56

本脚本参考基于Unity 3.4.1f5

英文部分版权属©Unity公司所有,中文部分© Unity圣典 版权所有,未经许可,严禁转载 。