Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: rxmarcus on October 19, 2014, 10:08:18 PM

Title: Positioning Scroll View off screen
Post by: rxmarcus on October 19, 2014, 10:08:18 PM
Hello guys,
The main menu of my app is 3 sections wide (These are 2D background images in the 3D world space). The camera starts on the first section, when a user selected "Lets Go!" the camera slides to the next section over. On the 3rd section I want to have a NGUI Scroll View.  The issue is that NGUI's camera is always on screen no matter what the unity game world camera does. So I have my Scroll View created, but its visible even on the 1st section of my apps main menu, but I want it to be on the 3rd only.  How can I accomplish this?  I purchased the NGUI Hud Text add on just so I could use the UIFollowTarget script which works but that freezes my scroll view in place when I try to slide it around.  Please see the included image to hopefully understand better what I'm wanting to do.
Title: Re: Positioning Scroll View off screen
Post by: rxmarcus on October 20, 2014, 02:54:10 PM
Bump,
I can't imagine that other users haven't wanted to do something like this?
Title: Re: Positioning Scroll View off screen
Post by: BenMPG on October 20, 2014, 03:20:26 PM
I'm not 100% if I understand your issue, but it sounds like you need to position your NGUI Scroll view relative to your main camera view and update that position when your main camera view changes.

So, off the top of my head:

Vector3 nguiPos = nguiCamera.ViewportToWorldPoint(Camera.main.WorldToViewportPoint(worldPosition));

You can place a dummyObject in the main scene where you want the scroll view to appear and then use that position as worldPosition above.
Title: Re: Positioning Scroll View off screen
Post by: rxmarcus on October 20, 2014, 05:07:20 PM
Thanks for the response,
unfortunately using that idea its acting exactly the same as the UIFollowTarget script. The scrollview is in the correct place but the content inside the scroll view is locked in place and can't be dragged, I assume because the code is somehow keeping it in place....

Here is my code, which is attached to the scrollView object (the parent, not the children objects).

  1. public Transform worldTarget;
  2.         public Camera gameCamera;
  3.         public Camera nguiCamera;
  4.  
  5.         // Use this for initialization
  6.         void Start () {
  7.        
  8.         }
  9.        
  10.         // Update is called once per frame
  11.         void Update () {
  12.                 Vector3 nguiPos = nguiCamera.ViewportToWorldPoint(gameCamera.WorldToViewportPoint(worldTarget.position));
  13.                 transform.localPosition = nguiPos;
  14.         }
Title: Re: Positioning Scroll View off screen
Post by: ArenMook on October 20, 2014, 11:44:59 PM
I'm confused by why any of this is needed?

So you want to have 3 screens, side by side. Start with the left-most screen, then move the camera so that it's on the center screen, then on the right screen, correct? So what difficulty are you running into? Nothing is preventing you from moving the UI camera around. As long as you don't anchor anything, you're fine. Even if you do anchor something, use "Offset By Anchors" option on the panels, and move the panels instead of the camera. In your case I wouldn't anchor anything just to make it easier.
Title: Re: Positioning Scroll View off screen
Post by: rxmarcus on October 21, 2014, 03:38:19 PM
Wow, I guess I just never thought about moving the UI Camera around, it just has always been static and in one place in all the examples I had seen for using NGUI. Thanks Aren, should be able to make this much simpler now.