Author Topic: Can I control NGUI through a script?  (Read 2658 times)

jordancregan

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 2
    • View Profile
Can I control NGUI through a script?
« on: May 13, 2014, 01:01:10 PM »
 After discovering the new Unity 4.6 GUI will be NGUI (or at least will be developed by the NGUI dev) I decided to try it for myself. Coming from UnityGUI it was a big change in terms of usage when trying to create a GUI for my upcoming project. It is also a change in functionality as the only way to position items correctly in different aspect ratios is to use anchors. The other problem is that there is no way to change the size of an object with different aspect ratios due to the width changing of the screen. I decided to create a handler for it myself but didn't want to spend all that time figuring out how to use the top-left to 0,0 and convert that to NGUI position without first asking if there is a way already.

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: Can I control NGUI through a script?
« Reply #1 on: May 13, 2014, 02:00:50 PM »
Ok, so, basically, it's way different than the OnGUI system. You can't really compare or translate the way the two operates. NGUI is closer to GUITextures in that you have a persistent state, where nothing changes until you tell it to change - this is different from OnGUI, where you have to tell it how to look every time the method runs.

Look at how UIRoot works for NGUI, that's where you can figure out sizes. With Screen.width and Screen.height, and the UIRoot pixelsizeadjustment, you can calculate where everything ought to be placed at. I would generally advice to use anchors and set the FixedSize on UIRoot though, to keep things simple.

jordancregan

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 2
    • View Profile
Re: Can I control NGUI through a script?
« Reply #2 on: May 13, 2014, 02:11:09 PM »
So no then. Well as I said anchors don't change the size based on width of different aspect ratio and if they o then I dont know how to get it to scale properly. I didnt mean create objects uing scripts. I mean changing properties through scripting. But thanks anyway. Ill get to work creating a utility to do that and maybe put it on the asset store.