Author Topic: Change UILabel Material in Real-time  (Read 3850 times)

sandolkakos

  • Newbie
  • *
  • Thank You
  • -Given: 16
  • -Receive: 1
  • Posts: 17
    • View Profile
Change UILabel Material in Real-time
« 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.  

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Change UILabel Material in Real-time
« Reply #1 on: September 06, 2014, 02:07:58 AM »
Is it a dynamic font label? Bitmap fonts always use the material of their atlas.

sandolkakos

  • Newbie
  • *
  • Thank You
  • -Given: 16
  • -Receive: 1
  • Posts: 17
    • View Profile
Re: Change UILabel Material in Real-time
« Reply #2 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.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Change UILabel Material in Real-time
« Reply #3 on: September 07, 2014, 08:45:26 AM »
I am not able to view that video. May I suggest uploading to youtube instead?

sandolkakos

  • Newbie
  • *
  • Thank You
  • -Given: 16
  • -Receive: 1
  • Posts: 17
    • View Profile
Re: Change UILabel Material in Real-time
« Reply #4 on: September 07, 2014, 06:49:00 PM »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Change UILabel Material in Real-time
« Reply #5 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.         }

sandolkakos

  • Newbie
  • *
  • Thank You
  • -Given: 16
  • -Receive: 1
  • Posts: 17
    • View Profile
Re: Change UILabel Material in Real-time
« Reply #6 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 :)