Author Topic: UISlider event listener missing for foreground sprite  (Read 2987 times)

Arcanor

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 46
    • View Profile
UISlider event listener missing for foreground sprite
« 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.


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!
« Last Edit: February 11, 2014, 10:51:36 AM by Arcanor »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UISlider event listener missing for foreground sprite
« Reply #1 on: February 11, 2014, 07:57:08 PM »
Remove the box collider from the foreground image.

Arcanor

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 46
    • View Profile
Re: UISlider event listener missing for foreground sprite
« Reply #2 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.