Author Topic: Allow UILabel extension  (Read 5488 times)

kittikun

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 5
  • Posts: 46
    • View Profile
Allow UILabel extension
« on: June 02, 2014, 03:23:44 AM »
Hi,

We are using fixed font size, so I have replaced the UILabel size filed by an enum (Small, Medium, Large).

It was easier to extend UILabel but I had to modify UILabelInspector to allow my class to use it. And i'd rather not modify NGUI source code so could you possibly make it easier to extend it ?

1) [CustomEditor(typeof(UILabelAOE), true)]

to

[CustomEditor(typeof(UILabelAOE), false)]

otherwise it will always use UILabelInspector

2) Make mFontTypeAoE and mLabelAoE protected

3) Also make OnNGUIFont and OnUnityFont protected

I had to copy/paste ShouldDrawProperties to add my changes but that is not a big deal

Thank you

kittikun

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 5
  • Posts: 46
    • View Profile
Re: Allow UILabel extension
« Reply #1 on: June 02, 2014, 11:02:18 PM »
Hum, it seems things are not that simple even with the editor working, I wanted to add a menu button to switch like you did for box collider -> 2d box collider

I did use the replace class utility (NGUIEditorTools.ReplaceClass) but this breaks the ngui font/unity font selection dropdown.

It look like this value is based on mFont which is private so I cannot copy it manually.

I tried to do that with a SerializedProperty with no success

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Allow UILabel extension
« Reply #2 on: June 02, 2014, 11:29:25 PM »
[CustomEditor(typeof(UILabel), true)] <-- this means that the custom inspector will be used unless you have your own higher level custom inspector that derives from UILabelInspector. So derive from it and overwrite whatever functionality you need. Although I wouldn't do it like this if I were you. I'd simply have a stand-alone script that would adjust the size of the label based on some enum setting of this stand-alone script.

kittikun

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 5
  • Posts: 46
    • View Profile
Re: Allow UILabel extension
« Reply #3 on: June 03, 2014, 02:09:28 AM »
I see, it will be easier after a version upgrade this way, thanks