Author Topic: 2D Event type and scrollview  (Read 4286 times)

lzt120

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 68
    • View Profile
2D Event type and scrollview
« on: September 11, 2014, 07:44:05 AM »
How can I make one scroll view with 2D collides and my UI use 2D event system?
I make one collides with drag scroll view component and then the event of the elements in scroll view do not fire up.
One new 2D scroll view example is welcome.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: 2D Event type and scrollview
« Reply #1 on: September 12, 2014, 03:49:35 AM »
You need to make the UICamera to use 2D UI event mode.

Switching from 3D to 2D and vice versa is easy -- you can do it via the NGUI menu -> Extras.

lzt120

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 68
    • View Profile
Re: 2D Event type and scrollview
« Reply #2 on: September 17, 2014, 04:21:44 AM »
Just testing the example(Example 7 - Scroll View (Panel) , if I switch it to 2D and then add one OnPress Event by custom script on the item, it is not fire up the  OnPress event.I think it is one bug and you can test yourself.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: 2D Event type and scrollview
« Reply #3 on: September 17, 2014, 12:46:53 PM »
1. Opened example 7.
2. NGUI menu -> Extras -> Switch to 2D Colliders
3. Hit Play, press on the "Click Me" button in the bottom right corner. It gets the pressed state as expected.

lzt120

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 68
    • View Profile
Re: 2D Event type and scrollview
« Reply #4 on: September 21, 2014, 08:44:32 PM »
What I mean is the items inside the scrollview,you can have the "Some Itme " Label with OnClick event, and the event will not fire up.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: 2D Event type and scrollview
« Reply #5 on: September 22, 2014, 10:10:05 AM »
Those labels don't have colliders, so how can they receive events?

lzt120

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 68
    • View Profile
Re: 2D Event type and scrollview
« Reply #6 on: September 23, 2014, 04:02:31 AM »
I did add the colliders to it and still not event received.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: 2D Event type and scrollview
« Reply #7 on: September 23, 2014, 12:20:53 PM »
Did you enable Debug on the UICamera to see what's intercepting the events?

When I add colliders to the labels, they are able to receive them, provided I actually remove colliders from the game object above them. Colliders on game objects go on top of everything underneath them, and since label is a child, the game object's collider will effectively cover it.

lzt120

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 68
    • View Profile
Re: 2D Event type and scrollview
« Reply #8 on: September 23, 2014, 09:06:20 PM »
"Outline" Object is on top of items so that 2D event will not fire up on the label. I wonder what is to determine the last hit object when there some object overlay each other ? If I can make the drag scroll view underneath of labels then drag scroll view and Click event on labels can both works.

Here is the code I use for testing:
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class TestClick : MonoBehaviour {
  5.  
  6.     public GameObject[] itmes;
  7.  
  8.     void Awake()
  9.     {
  10.         for (int i = 0 ; i < itmes.Length ; i++)
  11.         {
  12.             UIEventListener.Get(itmes[i]).onPress += CustPressed;
  13.         }
  14.        
  15.     }
  16.     void CustPressed(GameObject go,bool pressed)
  17.     {
  18.         Debug.Log("Heelo");
  19.     }
  20. }

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: 2D Event type and scrollview
« Reply #9 on: September 24, 2014, 01:32:40 PM »
Outline object is drawn by a different panel that has a lower depth than the scroll view. Scroll view panel is on top, so its widgets will always get the events first.

All this assumes you've actually set UICamera to "3D UI" mode (or "2D UI" if you switched to 2D colliders). If it's using "World" type then all events will use Z position instead.

lzt120

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 68
    • View Profile
Re: 2D Event type and scrollview
« Reply #10 on: September 24, 2014, 10:13:25 PM »
By Switch to 2D World Event from 2D UI Evet , all works as expected.