Author Topic: Picture in picture Style layout  (Read 2011 times)

beforethelight

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 22
    • View Profile
Picture in picture Style layout
« on: June 16, 2014, 11:42:23 PM »
Hello I am attempting to setup a PIP style UI where I set a camera viewport Rect to the frame of a NGUI sprite.  I cannot get this to work.  I have tried nguimath CalculateAbsoluteWidgetBounds to get the bounds then convert them to viewport points but it puts my viewport all over the place.  I am really hoping someone can point me in the correct direction.  Tried setting up game objects on the ui but it is anchored and changes and then the game object is misplaced.  Thanks for any help!

EDIT
Ok so maybe my description wasn't the best.  I need to get a rect from a UIWidget in viewport coordinates. Then I can assign those values to my camera viewport.
« Last Edit: June 17, 2014, 08:14:12 AM by beforethelight »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Picture in picture Style layout
« Reply #1 on: June 17, 2014, 01:30:51 PM »
UIWidget.worldCorners will give you the 4 corners of a widget in world space. To convert world coordinates to view coordinates, use Camera.WorldToViewportPoint

beforethelight

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 22
    • View Profile
Re: Picture in picture Style layout
« Reply #2 on: June 18, 2014, 06:22:00 AM »
Thanks Aren! But having an issue where I have to enter the menu then exit the reenter to get the coordinates to work.  When I first enter the menu I get a little sliver showing on the screen nowhere near any of the corners.  Then I exit and enter the menu again and everything is perfect.  Below is my code.  My element is anchored to resize to the screen.  The object is disabled when the scene starts and enables when you enter this particular menu.

  1. function OnEnable()
  2. {
  3.         var windowSprite : UISprite = GetComponent(UISprite);
  4.        //Inserted this to try to get the corners to update to the resized positions.
  5.         windowSprite.UpdateAnchors();
  6.  
  7.         var bottomLeft : Vector3 = GUICam.WorldToViewportPoint(windowSprite.worldCorners[0]);
  8.         viewCam.rect.x = bottomLeft.x;
  9.         var bottomRight : Vector3 = GUICam.WorldToViewportPoint(windowSprite.worldCorners[3]);
  10.         viewCam.rect.width = bottomRight.x - bottomLeft.x;
  11. }
  12.  

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Picture in picture Style layout
« Reply #3 on: June 18, 2014, 04:24:42 PM »
OnEnable() is not the right place for this. Try Start().

beforethelight

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 22
    • View Profile
Re: Picture in picture Style layout
« Reply #4 on: June 19, 2014, 03:18:39 PM »
Thanks Aren this worked great.