Author Topic: UIPanel and Resizing windows  (Read 2849 times)

indiefreaks

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 27
    • View Profile
UIPanel and Resizing windows
« on: December 10, 2013, 09:20:07 PM »
Hi,

I'm moving from NGUI 2.x to 3.x and I want to make use of the library on the way it is supposed to be used.

With the recent changes, especially the anchoring system, I revamped my previous Window class design so that I could use its greatness to manage user resize by dragging the window corner as you would do with any window system.

Yet I'm unsure how to do so.

Basically, my current attempt is the following:

I created a hierarchy like so:

UIRoot
--- Camera
--- Window (uses UIPanel with clipping set to Alpha clipping)
------- Background (uses simple UISprite 32*32 white texture set to a black color in the inspector with half alpha)
------- Border (uses the same UISprite using Sliced version without the fill center and using a white color)
------- Title (uses UILabel)
------- Handle (uses a simple UISprite, a BoxCollider and a custom script reacting to OnPressed for now: I'll implement the OnDrag later on)

The Background and Border uses a Unified anchor using the Window as the anchored target and a fills the UIPanel clipping (verified to use the same size which is great).
The Handle uses the same target for the anchor but is anchored on the bottom right.

Now, what would you recommend me to change so that when I drag the handle, the whole window gets resized?

I tried to find a way to change the clipping region but all the public properties state that we shouldn't use the "set" property to change the clipping and use the clipOffset instead but this doesn't allow me to change the size of the actual clipped region.

I also tried to change the scale value of the transform but it breaks the uniform rule required for the clipping to work properly (by the way, it's great to see the warning in the inspector directly).

I would like to be sure that I'm taking the right direction as I mentionned earlier and I would be pretty disappointed if I would have to step back and simply make a reference to the Background and Border UISprites and update their width and height how I used to do with NGUI 2.x.

Thanks for all the help and advices you could come up with ;)
Best regards,

Philippe

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIPanel and Resizing windows
« Reply #1 on: December 10, 2013, 09:25:12 PM »
UIWindow should be a UIWidget rather than a panel. I'm not sure why you would make it a clipped panel and put the background inside that so that it gets clipped.

Set up the widget for the window and make everything relative to it (as a child of that widget).

indiefreaks

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 27
    • View Profile
Re: UIPanel and Resizing windows
« Reply #2 on: December 11, 2013, 04:10:30 AM »
I wanted the Window to be a UIPanel so that I would directly get the scroll view feature as a root feature of the gameobject.

Yet your recommendation on inheriting from UIWidget seems to be the way to go and just add a UIPanel to its children.

I believe a good tutorial video for you to make and thus spare some time would be your recommendation on how to create a custom control from scratch such as a window or a tabs panel or whatever else. How would you structure your gameobjects and related scripts would help a lot of devs trying to get the most out of your already great add-on to Unity.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIPanel and Resizing windows
« Reply #3 on: December 12, 2013, 02:05:02 AM »
In the NGUI 3.0.7 video I create a scroll view from scratch, then make it possible to move and resize it at run-time via dragging. I then add items to it that can be dragged outside of it, and dropped into another scroll view.

http://www.youtube.com/watch?v=B66xhIvYF00