Author Topic: UICamera.current vs UICamera.currentCamera  (Read 3909 times)

Maxii

  • Jr. Member
  • **
  • Thank You
  • -Given: 4
  • -Receive: 0
  • Posts: 55
    • View Profile
    • Strategic Forge
UICamera.current vs UICamera.currentCamera
« 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.
« Last Edit: September 17, 2014, 12:17:24 PM by Maxii »
I'm looking for an artist partner to complement my programming skill in developing a space-based Civilization-like empire building game, ala GalCiv2 or Distant Worlds based on Unity3D.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UICamera.current vs UICamera.currentCamera
« Reply #1 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:
  1. using UnityEngine;
  2.  
  3. public class Test : MonoBehaviour
  4. {
  5.         void OnClick ()
  6.         {
  7.                 Debug.Log(UICamera.currentCamera.name);
  8.         }
  9. }
5. Clicked Play, clicked on the cube -- "Main Camera". Clicked on the widget - "Camera".
« Last Edit: September 17, 2014, 01:21:29 PM by ArenMook »

Maxii

  • Jr. Member
  • **
  • Thank You
  • -Given: 4
  • -Receive: 0
  • Posts: 55
    • View Profile
    • Strategic Forge
Re: UICamera.current vs UICamera.currentCamera
« Reply #2 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?
I'm looking for an artist partner to complement my programming skill in developing a space-based Civilization-like empire building game, ala GalCiv2 or Distant Worlds based on Unity3D.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UICamera.current vs UICamera.currentCamera
« Reply #3 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.

UICamera.currentCamera is not the same thing.