shader的属性类型总共有Int,Float,Color,Range,Vector,2D,Cube,3D总共8中类型,下面按类型来介绍:
Int属性定义的格式:
name ("display name", Int) = number
Float属性定义的格式:
name ("display name", Float) = number
Range属性定义的格式:
name ("display name", Range (min, max)) = number
Color属性定义的格式:
name ("display name", Color) = (number,number,number,number)
Vector属性定义的格式:
name ("display name", Vector) = (number,number,number,number)
2D属性定义的格式:
name ("display name", 2D) = "defaulttexture" {}
Cube属性定义的格式:
name ("display name", Cube) = "defaulttexture" {}
3D属性定义的格式:
name ("display name", 3D) = "defaulttexture" {}
下面我们来看一下完整的测试代码:
Shader "Hidden/TestVertex"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_TestInt("TestInt",Int)=1
_TestFloat("TestFloat",Float)=2.0
_TestVector4("TestVector4",Vector)=(0,0,0,0)
_TestColor("TestColor",Color) = (1,0,0,1)
_TestRange("TestRange",Range(0,100))=100
_Test2D("Test2D",2D) = ""{}
_TestCube("TestCube",Cube) = ""{}
_Test3D("Test3D",3D) = ""{}
}
SubShader
{
}
}
这样,我们定义的属性就显示在了unity面板上了。效果图: