Support => NGUI 3 Support => Topic started by: Maxii on September 17, 2014, 11:52:50 AM
Title: UICamera.current vs UICamera.currentCamera
Post by: Maxii on September 17, 2014, 11:52:50 AM
I have a Camera2D limited to the UI layer, set to orthogonal with depth = 1. It has a UICamera script with the eventType set to 2D UI and an event mask also limited to the UI layer.
I also have a MainCamera that excludes the UI layer, set to perspective with depth = -1. It also has a UICamera script with the eventType set to 3D World and an event mask that excludes the UI layer.
When I click on a 3D gameObject (not on the UI layer), I print out UICamera.current.name, UICamera.current.eventType and UICamera.currentCamera.name.
I get back, in order: "Camera2D", "2D UI", and "MainCamera". I was expecting MainCamera, 3D World and MainCamera. Shouldn't UICamera.current be the mainCamera's UICamera that can see the gameObject, rather than the Camera2D which can't? How can UICamera.current and UICamera.currentCamera refer to 2 separate cameras immediately after an event is received?
EDIT: I've also now printed out the event mask from both UICamera.current and UICamera.currentCamera yielding respectively: UI layer only, and other layers excluding UI. This seems to confirm that the event must be coming from the MainCamera, even though UICamera.current returns Camera2D.
Title: Re: UICamera.current vs UICamera.currentCamera
Post by: ArenMook on September 17, 2014, 01:15:52 PM
Event processing is done using only one UICamera (the first one). Others are just ignored. If you need to know which camera saw the object, use UICamera.FindCameraForLayer(yourGameObject.layer);
Edit: I just realized you were talking about UICamera.currentCamera, not UICamera.current. That one indeed should point to the actual camera that saw the object.
Edit #2: 1. New scene. 2. ALT+SHIFT+S, ALT+SHIFT+C. 3. Attached UICamera to the Main Camera as well. 4. Added a cube, and attached the following script to both the cube and the sprite:
usingUnityEngine;
publicclass Test : MonoBehaviour
{
void OnClick ()
{
Debug.Log(UICamera.currentCamera.name);
}
}
5. Clicked Play, clicked on the cube -- "Main Camera". Clicked on the widget - "Camera".
Title: Re: UICamera.current vs UICamera.currentCamera
Post by: Maxii on September 17, 2014, 01:30:45 PM
The first one you are referring to here then would be the one that processes first, aka the one with the lower depth, in my case being the UICamera on the World3D camera, or do you mean the first one I referred to in my message, that being the UICamera on the UI2D camera?
Title: Re: UICamera.current vs UICamera.currentCamera
Post by: ArenMook on September 17, 2014, 01:34:53 PM
The first camera in the UICamera.list is the one that processes all events and is going to be UICamera.current.