Author Topic: NGUI subclassing/Extending practice  (Read 3642 times)

Genhain

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 38
    • View Profile
NGUI subclassing/Extending practice
« on: May 23, 2014, 01:12:34 AM »
So I am Attempting to follow the SOLID Principles while using NGUI...Particularly when it comes to the O part the Open/Closed principle and extending any NGUI class that i need a little extra functionality from. Generally the scripts seem to have been made with this in mind, quite a few virtual functions sitting around...However i recently subclassed from UIScrollView and i noticed the Awake function was not protected virtual, and my question is, is this by design or do you think the dev(s) never got round to it? The subclass is working without a hitch...Until of course i want to instantiate my own subclass member variables via Awake() or Start(), then i am out of luck.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: NGUI subclassing/Extending practice
« Reply #1 on: May 23, 2014, 04:00:42 PM »
It's best to do it in Start() rather than Awake(). Awake() is for local member initialization, and is also generally fired before the object is parented properly. Most people seem oblivious of this fact.

Genhain

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 38
    • View Profile
Re: NGUI subclassing/Extending practice
« Reply #2 on: May 25, 2014, 10:38:56 PM »
@ArenMook Yeah i did read into the whole Awake() Start() difference. My question though is that i have subclassed UIScrollView The aforementioned Awake and Start were private so i could not call base.start() from my class, which is kind of needed as you have a lot of stuff going on in both. Easy fix would be to obviously to set them to protected but this violates open/closed principle and i am not sure if it's what you intended or not.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: NGUI subclassing/Extending practice
« Reply #3 on: May 26, 2014, 10:43:47 PM »
Start() is a protected virtual function. Only Awake() is private.