Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: sandolkakos on September 06, 2014, 12:22:22 AM

Title: Change UILabel Material in Real-time
Post by: sandolkakos on September 06, 2014, 12:22:22 AM
Hello ArenMook,

I'm trying to change the Material of my UILabel in real-time. The Material is changed but the effect does not happen.

The effect happens when I set the Material Manually via Inspector, so I can't understand my mistake :(

I'm setting it like this:
  1. this.GetComponent<UILabel>().material = newMaterial;
  2.  
Title: Re: Change UILabel Material in Real-time
Post by: ArenMook on September 06, 2014, 02:07:58 AM
Is it a dynamic font label? Bitmap fonts always use the material of their atlas.
Title: Re: Change UILabel Material in Real-time
Post by: sandolkakos on September 06, 2014, 09:28:37 PM
yes, I'm using dynamic font in the UILabel.

In the Attachment Files I've uploaded a file with the video showing the error.

Thank you for the attention, ArenMook.
Title: Re: Change UILabel Material in Real-time
Post by: ArenMook on September 07, 2014, 08:45:26 AM
I am not able to view that video. May I suggest uploading to youtube instead?
Title: Re: Change UILabel Material in Real-time
Post by: sandolkakos on September 07, 2014, 06:49:00 PM
Here you are :)
http://youtu.be/2CHTupWka8E
Title: Re: Change UILabel Material in Real-time
Post by: ArenMook on September 08, 2014, 08:43:27 PM
I don't recommend using OnGUI with NGUI.

Regardless, this seems to be a bug. You can fix it by changing UILabel's material property to this:
  1.         public override Material material
  2.         {
  3.                 get
  4.                 {
  5.                         if (mMaterial != null) return mMaterial;
  6.                         if (mFont != null) return mFont.material;
  7.                         if (mTrueTypeFont != null) return mTrueTypeFont.material;
  8.                         return null;
  9.                 }
  10.                 set
  11.                 {
  12.                         if (mMaterial != value)
  13.                         {
  14.                                 RemoveFromPanel();
  15.                                 mMaterial = value;
  16.                                 MarkAsChanged();
  17.                         }
  18.                 }
  19.         }
Title: Re: Change UILabel Material in Real-time
Post by: sandolkakos on September 09, 2014, 01:39:32 PM
Thank you, ArenMook. It is now fixed.

About the OnGUI, I just used it to show you how the problem was happening :)