700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > Unity3d C# 代码动态设置(SetTexture)材质球(Material)贴图纹理(Texture)

Unity3d C# 代码动态设置(SetTexture)材质球(Material)贴图纹理(Texture)

时间:2020-07-18 15:09:00

相关推荐

Unity3d C# 代码动态设置(SetTexture)材质球(Material)贴图纹理(Texture)

实现方式

主要的实现方式就是如下两种方式,更建议使用方式二

//Tex就是用于赋值的贴图int TexID = Shader.PropertyToID("_MainTex");//获取属性名称IDMat.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);

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。