Author Topic: Changing UITexture Material Property in 2.7  (Read 4637 times)

sybixsus

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 14
    • View Profile
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 :

  1. _Alpha ("Panel Alpha", Range(0,1)) = 0.1
  2.  

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.

  1. DynamicMaterial = GameObject.Instantiate(DynamicPortrait.material) as Material;
  2. DynamicPortrait.material = DynamicMaterial;
  3.  

I set the texture at various points because it's dynamic :

  1. DynamicPortrait.mainTexture = HT.GetTexture();
  2.  

And then finally I try to change the material property:

  1. DynamicMaterial.SetFloat("_Alpha", 1f);
  2.  

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 :

  1. Material M = DynamicPortrait.material;
  2. M.SetFloat("_Alpha", 1f);
  3. DynamicPortrait.material = M;
  4.  

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.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Changing UITexture Material Property in 2.7
« Reply #1 on: April 05, 2014, 11:48:51 AM »
Sorry, NGUI 2 is free and doesn't come with support.

sybixsus

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 14
    • View Profile
Re: Changing UITexture Material Property in 2.7
« Reply #2 on: April 05, 2014, 02:58:44 PM »
Maybe you made it free now, but it sure wasn't free when I paid for it. If you would like my invoice, just tell me where to send it.

EDIT: I emailed it to your support email address. I hope that was the correct place to send it. i was under the impression that you had asked to see my invoice before registering me on this forum in the first place, but perhaps I am mistaken.
« Last Edit: April 05, 2014, 03:08:10 PM by sybixsus »

sybixsus

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 14
    • View Profile
Re: Changing UITexture Material Property in 2.7
« Reply #3 on: April 05, 2014, 03:50:05 PM »
Just to add, that I'm already using vertex colors for something else, so that's not an option.
« Last Edit: April 05, 2014, 04:18:14 PM by sybixsus »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Changing UITexture Material Property in 2.7
« Reply #4 on: April 06, 2014, 02:26:28 AM »
Not sure where you sent it to but I see nothing in support at tasharen.com.

In any case the reason NGUI 2 isn't supported anymore is because it is from September last year (2.7.0), and NGUI today is a completely different beast compared to back then. Pretty much everything has changed, including the handling of materials. I could answer your question for NGUI 3, but in all honesty I just don't remember what it was doing in NGUI 2.