Author Topic: Draggable window to not exceed screen edges? (solved)  (Read 2806 times)

ajdickson1208

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 7
    • View Profile
Draggable window to not exceed screen edges? (solved)
« on: October 30, 2013, 01:39:13 PM »
EDIT: NVM! I can actually use transform.localPosition to find the pixel position for the gui...derp!
Apologizing in advance for my English and that I'm new to programming, Unity 3D and NGUI.

Currently I'm trying to set my draggable window to stay within the screen and not exceed the edges of the width or height while dragging.
I've tried setting its transform.position, which doesn't quite work, instead it goes way out of sight.
I've then did some research and tried using the NGUIMath.CalculateAbsoluteWidgetBounds, and found out that my window's position are between -1.7 to 1.7 instead of the actual screen pixels?

Anyways, can someone please help me with this matter? I would like to know the max width and height that's relative to my draggable window's position.
I am able to script the built-in Unity OnGUI's drag window to not exceed the Screen.width and Screen.Height, but have no idea how to do it with NGUI! D:

I'm sorry if this is a newb question to ask and thanks all for the time in reading this! ;)
P.S. I bought NGUI, and it made my life so much easier.
« Last Edit: October 31, 2013, 09:44:38 AM by ajdickson1208 »

ajdickson1208

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 7
    • View Profile
Re: Draggable window to not exceed screen edges? HELP! :<
« Reply #1 on: October 31, 2013, 07:04:12 AM »
Bump!
In case I wasn't clear enough above with my english...I'd like to make something like this that would work with NGUI.
  1. public GameObject window;
  2. public float windowWidth = 100f;
  3. public float windowHeight = 100f;
  4.  
  5. void Update () {
  6.         if (window.transform.position.x <= 0) window.transform.position = new Vector3(0, window.transform.position.y, window.transform.position.z);
  7.         if (window.transform.position.y <= 0) window.transform.position = new Vector3(window.transform.position.x, 0, window.transform.position.z);
  8.         if (window.transform.position.x + windowWidth >= Screen.width) window.transform.position = new Vector3(Screen.width - windowWidth, window.transform.position.y, window.transform.position.z);
  9.         if (window.transform.position.y + windowHeight >= Screen.width) window.transform.position = new Vector3(window.transform.position.x, Screen.height - windowHeight, window.transform.position.z);
  10. }