Author Topic: Get the current Camera  (Read 1266 times)

aholla

  • Newbie
  • *
  • Thank You
  • -Given: 4
  • -Receive: 0
  • Posts: 40
    • View Profile
Get the current Camera
« on: May 23, 2014, 09:50:56 AM »
Hi, I would like to get the current camera so I can tween a panel in from outside the camera view/bounds.

I have tried various methods: UICamera.current return null, NGUITools.FindInParents<UICamera>( gameObject ) returns null.

To make things a little more confusing I have two UIRoots and therefore two UICamera.

UIRoot1
- UIPanel
- UICamera

UIRoot2
-UIPanel
-UICamera

SO just to reiterate what I am doing. In code I am trying to tween an existing object in the hierarchy. I want to position it outside the view of the camera and tween/slide it in.

Any suggestions?

Also related to my issues I have managed to get my panel to appear offscreen with the following code:

  1. int paneloffset = Mathf.FloorToInt( UIRoot.GetPixelSizeAdjustment( gameObject ) * ( Screen.width / 2f ) ) + 1;
  2. paneloffset += 480;
  3. gameObject.transform.localPosition = new Vector3( -paneloffset, 0, 0 );
  4.  

My Panels have been designed to be 960px wide so I am adding 480 pixels to the offset. Is this okay or will I run into problems with this approach?


Thanks
« Last Edit: May 23, 2014, 10:11:07 AM by aholla »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Get the current Camera
« Reply #1 on: May 23, 2014, 04:40:37 PM »
Assuming your UIRoot is set to pixel perfect, yes -- it's a fine approach. Otherwise you need to take UIRoot's pixelSizeAdjustment into consideration.