目录索引
译文
枚举(Enum)跟关键词枚举(KeywordEnum)很像,不同之处在于枚举可以定义一个 “值/id “作为参数,并传递到着色器命令中使用,从而从检查器中动态更改其功能。
声明语法如下所示:
[Enum(valor, id_00, valor, id_01, etc … )]
_PropertyName ("Display Name", Float) = 0
枚举并不依赖着色器变体,它通过命令或函数进行声明。为了理解这个概念,让我们看看下面这个例子:
Shader "InspectorPath/shaderName"
{
Properties
{
// declare drawer
[Enum(Off, 0, Front, 1, Back, 2)]
_Face ("Face Culling", Float) = 0
}
SubShader
{
// we use the property as a command
Cull [_Face]
Pass { … }
}
}
在这个例子中,我们声明了一个叫做“_Face”的枚举属性,并定义了三个参数:关闭/0、前/1、后/2,接着我们将参数应用到了子着色器中的剔除(Cull)里,这样我们就可以在材质的检查器中更改我们想剔除的方向了。在后续的3.2.1小节中,我们会详细介绍剔除命令。
原文对照
This drawer is very similar to the KeywordEnum with the difference that it can define a “value/id” as an argument and pass this property to a command in our shader to change its functionality dynamically from the inspector.
Its syntax is as follows:
[Enum(valor, id_00, valor, id_01, etc … )]
_PropertyName ("Display Name", Float) = 0
Enums do not use shader variants but are declared by command or function. To understand their implementation, we will perform the following operation:
Shader "InspectorPath/shaderName"
{
Properties
{
// declare drawer
[Enum(Off, 0, Front, 1, Back, 2)]
_Face ("Face Culling", Float) = 0
}
SubShader
{
// we use the property as a command
Cull [_Face]
Pass { … }
}
}
As presented in this example, we declare a property type “Enum” called “_Face” and we pass as an argument the values: Off, 0, Front, 1, Back and 2. Then we add the property to the command “Cull” found in the SubShader; this way we can change the object face we want to render from the material inspector. In section 3.2.1 we will talk about the Cull command in detail.
暂无评论内容