您当前的位置: 首页 >  unity

十幺卜入

暂无认证

  • 5浏览

    0关注

    119博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

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

十幺卜入 发布时间:2021-07-09 17:53:56 ,浏览量:5

实现方式

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


      //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);
        
关注
打赏
1663314737
查看更多评论
立即登录/注册

微信扫码登录

0.1827s