实现方式
主要的实现方式就是如下两种方式,更建议使用方式二:
//Tex就是用于赋值的贴图
int TexID = Shader.PropertyToID("_MainTex");//获取属性名称ID
Mat.SetTexture(TexID, Tex); //方式一设置贴图
Mat.SetTexture("_MainTex", Tex); //方式二设置贴图
注意!!
这里的属性的名称,而不是显示的名称,如下面的Standard着色器应该使用“_MainTex”:
其它接口
可以参考一下其它的实现接口,只是参数有点差异:
//
// 摘要:
// Sets a named texture.
//
// 参数:
// nameID:
// 属性名称ID,使用Shader.PropertyToID 来获取它。
//
// name:
// 属性名称, 如: "_MainTex".
//
// value:
// 设置的纹理
//
// element:
// 可选参数,指定从RenderTexture设置的数据类型。
public void SetTexture(int nameID, RenderTexture value, RenderTextureSubElement element);
public void SetTexture(string name, RenderTexture value, RenderTextureSubElement element);
public void SetTexture(int nameID, Texture value);
public void SetTexture(string name, Texture value);