Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: Arcanor on February 11, 2014, 10:31:18 AM

Title: UISlider event listener missing for foreground sprite
Post by: Arcanor on February 11, 2014, 10:31:18 AM
I've created a UISlider with background, foreground and thumb sprites.  All three of them have Box Colliders.  When I hit Play, I can drag the thumb and it responds, I can click or drag in the background area (the black area on the right) and it responds, but when I click or drag on the foreground area of the slider (the blue area to the left) it doesn't respond.

(http://content.screencast.com/users/waltenstein/folders/Snagit/media/8f4d7bdd-e169-46d3-8b30-c21d6d90ddb0/02.11.2014-10.33.png)
I noticed in the Inspector that my thumb and background sprite gameobjects are having UIEventListener.Get() called on them, but the foreground sprite isn't getting any event listener added.  Here is what I think is the relevant code in UISlider.cs:

  1.    protected override void OnStart ()
  2.    {
  3.       GameObject bg = (mBG != null && mBG.collider != null) ? mBG.gameObject : gameObject;
  4.       UIEventListener bgl = UIEventListener.Get(bg);
  5.       bgl.onPress += OnPressBackground;
  6.       bgl.onDrag += OnDragBackground;
  7.  
  8.       if (thumb != null && thumb.collider != null && (mFG == null || thumb != mFG.cachedTransform))
  9.       {
  10.          UIEventListener fgl = UIEventListener.Get(thumb.gameObject);
  11.          fgl.onPress += OnPressForeground;
  12.          fgl.onDrag += OnDragForeground;
  13.       }
  14.    }
  15.  

Why isn't the foreground sprite registering to receive events?

Thanks in advance!
Title: Re: UISlider event listener missing for foreground sprite
Post by: ArenMook on February 11, 2014, 07:57:08 PM
Remove the box collider from the foreground image.
Title: Re: UISlider event listener missing for foreground sprite
Post by: Arcanor on February 11, 2014, 09:19:22 PM
Thanks, that's fixed it.  It's a little unintuitive, but I understand why it's done this way.