Author Topic: UICamera for 2D events (Colliders order)  (Read 9047 times)

broken

  • Full Member
  • ***
  • Thank You
  • -Given: 1
  • -Receive: 4
  • Posts: 140
    • View Profile
UICamera for 2D events (Colliders order)
« on: December 08, 2014, 02:29:15 AM »
Hi!

I create 2D game with game levels map like in "candy crush saga".

Unity 4.5.5, NGUI 3.7.6, 3.7.7

UICamera event type 2D World.

But I do not quite understand how to determined the order of events for the colliders.

I have structure:

- Game Map (Box Collider 2D with size = Sum of Tiles colliders bounds, disabled now)
- - Map Camera (Ortho camera and UICamera)
- - Tiles
- - - Tile 1 (Sprite Renderer with Sorting Layer = Default + 1, Box Collider 2D)
- - - - Levels
- - - - - Level 1 (Sprite Renderer with Sorting Layer = Default + 2, Box Collider 2D)
- - - - - ....
.... (N Tiles with N Levels)

For test, I added next script for each game object (Game Map, Game Time, Game Level) and checked Debug Mode for UICamera:
  1. void OnClick()
  2. {
  3.     Debug.LogWarning("OnClick " + name);
  4. }
  5.  

Sometimes shows wrong object (see attach images). For example, I clicked on Game Level object, but Debug shows like I clicked on Game Tile.
Every time when I run project, Debug shows different events order for game objects. Looks like colliders order is different.

In attach: screenshots and simplified repro project.

Thanks!

broken

  • Full Member
  • ***
  • Thank You
  • -Given: 1
  • -Receive: 4
  • Posts: 140
    • View Profile
Re: UICamera for 2D events (Colliders order)
« Reply #1 on: December 08, 2014, 02:51:45 AM »
  1. void OnMouseDown()
  2. {
  3.     Debug.LogWarning("OnMouseDown " + name);
  4. }
  5.  

OnMouseDown also detect wrong collider order. I think I do something wrong. Setting sorting layer and order in layer doesn't help.

All works fine if I used Box Collider with custom Z order, instead Box Collider 2D and 3D World event type for UICamera.

But how to make that work properly with the Box Collider 2D and 2D World event type?
« Last Edit: December 08, 2014, 03:30:22 AM by broken »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UICamera for 2D events (Colliders order)
« Reply #2 on: December 09, 2014, 12:41:26 PM »
OnMouseDown is a Unity event, not an NGUI event.

NGUI's equivalent is OnHover (bool isOver).

World type events are not based on NGUI's depth. If you set the event type to UI, then it will be depth-based. World type means it's based on the Z position.

broken

  • Full Member
  • ***
  • Thank You
  • -Given: 1
  • -Receive: 4
  • Posts: 140
    • View Profile
Re: UICamera for 2D events (Colliders order)
« Reply #3 on: December 10, 2014, 01:53:05 AM »
OnMouseDown is a Unity event, not an NGUI event.

Yes, I know, I just checked OnMouseDown behavior too.

NGUI's equivalent is OnHover (bool isOver).

I think you mean OnPress(isDown = true) is equivalent for OnMouseDown, no?

World type events are not based on NGUI's depth. If you set the event type to UI, then it will be depth-based. World type means it's based on the Z position.

Yes, thanks, with 2D world and Z position all works fine.
« Last Edit: December 10, 2014, 02:09:02 AM by broken »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UICamera for 2D events (Colliders order)
« Reply #4 on: December 11, 2014, 08:33:26 AM »
Right, OnPress, sorry. :)