1
NGUI 3 Support / Changing UITexture Material Property in 2.7
« on: April 05, 2014, 08:02:10 AM »
Hi,
I'm trying to change a material property of a UITexture object. I'm using NGUI 2.7, as I'm deep in a complex project.
I'm using a custom shader which has the following property :
And this is confirmed working. Whatever value I put as the default value is the final alpha value of the shader.
I create and apply my own material to the UITexture.
I set the texture at various points because it's dynamic :
And then finally I try to change the material property:
But it doesn't work.
I thought perhaps the UITexture might be creating a new material internally when I changed the main texture, so I tried :
But that doesn't work either.
Could you tell me what I'm doing wrong here please? I'm not going to be able to switch to 2.7, and the custom shader is unavoidable as it does some fancy gradients.
I'm trying to change a material property of a UITexture object. I'm using NGUI 2.7, as I'm deep in a complex project.
I'm using a custom shader which has the following property :
- _Alpha ("Panel Alpha", Range(0,1)) = 0.1
And this is confirmed working. Whatever value I put as the default value is the final alpha value of the shader.
I create and apply my own material to the UITexture.
- DynamicMaterial = GameObject.Instantiate(DynamicPortrait.material) as Material;
- DynamicPortrait.material = DynamicMaterial;
I set the texture at various points because it's dynamic :
- DynamicPortrait.mainTexture = HT.GetTexture();
And then finally I try to change the material property:
- DynamicMaterial.SetFloat("_Alpha", 1f);
But it doesn't work.
I thought perhaps the UITexture might be creating a new material internally when I changed the main texture, so I tried :
- Material M = DynamicPortrait.material;
- M.SetFloat("_Alpha", 1f);
- DynamicPortrait.material = M;
But that doesn't work either.
Could you tell me what I'm doing wrong here please? I'm not going to be able to switch to 2.7, and the custom shader is unavoidable as it does some fancy gradients.