《Unity着色器圣经》3.1.2 | MPD空白与标题

目录索引

译文

这是我们最后介绍的两种绘制器,可以帮助我们让检查器中的属性们更有条理。“空白(Space)”允许我们在两个属性之间加入空白占位,可以方便我们在材质检查器中分隔开特定的属性。

图片[1]-《Unity着色器圣经》3.1.2 | MPD空白与标题-软件开发学习笔记
[Space(10)]
图片[2]-《Unity着色器圣经》3.1.2 | MPD空白与标题-软件开发学习笔记
没有声明空白

它的声明语法如下:

_PropertyName01 ("Display name", Float ) = 0 
// 加上权重为10的空白
[Space(10)] 
_PropertyName02 ("Display name", Float ) = 0

在上面的例子中,我们在_PropertyName01 和 _PropertyName02 两个属性中加入了一个十点大小的空白。“标题(Header)”就是在材质检查器中添加一行加粗的字,可以帮助我们对属性进行分类。

图片[3]-《Unity着色器圣经》3.1.2 | MPD空白与标题-软件开发学习笔记
[Header(Color)]

它的声明语法如下:

// 加上标题
[Header(Category name)] 
_PropertyName01 ("Display name", Float ) = 0 
_PropertyName02 ("Display name", Float ) = 0

在这个例子中,我们在属性前添加了一个标题“Category name”,它最终会显示在材质检查器上。为了理解空白和标题,让我们看看下面的例子:

Shader "InspectorPath/shaderName" 
{ 
    Properties 
    { 
        [Header(Specular properties)] 
        _Specularity (“Specularity”, Range (0.01, 1)) = 0.08 
        _Brightness (“Brightness”, Range (0.01, 1)) = 0.08 
        _SpecularColor (“Specular Color”, Color) = (1, 1, 1 , 1) 
        [Space(20)] 
        [Header(Texture properties)] 
        _MainTex (“Texture”, 2D) = “white” {} 
    } 
    SubShader { … } 
}

原文对照

Finally, these drawers help a lot in organization tasks. “Space” allows us to add space between one property and another. If we wish that our properties appear separate in the material inspector, we can add space between them.

Its syntax is as follows:

_PropertyName01 ("Display name", Float ) = 0 
// we add the space 
[Space(10)] 
_PropertyName02 ("Display name", Float ) = 0

In this case, we are adding ten points of space between the property _PropertyName01 and the property _PropertyName02. Equally, as its name says, “Header” adds a header in the Unity Inspector. This is very useful when generating categories in our properties.

Its syntax is as follows:

// we add the header 
[Header(Category name)] 
_PropertyName01 ("Display name", Float ) = 0 
_PropertyName02 ("Display name", Float ) = 0

In this example, we have added a small header before starting our properties, which will be visible in the Inspector. To understand both properties, we will perform the following operation:

Shader "InspectorPath/shaderName" 
{ 
    Properties 
    { 
        [Header(Specular properties)] 
        _Specularity (“Specularity”, Range (0.01, 1)) = 0.08 
        _Brightness (“Brightness”, Range (0.01, 1)) = 0.08 
        _SpecularColor (“Specular Color”, Color) = (1, 1, 1 , 1) 
        [Space(20)] 
        [Header(Texture properties)] 
        _MainTex (“Texture”, 2D) = “white” {} 
    } 
    SubShader { … } 
}
© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容