Author Topic: Disable click while scrolling  (Read 2144 times)

Abe_ForkTech

  • Guest
Disable click while scrolling
« on: May 13, 2013, 02:44:47 AM »
Hello all,

We have couple of scroll lists in our game which are working just fine. But there is this one little bittle thing which is bothering me. The thing is when I am scrolling the list, the item on which I click and start scrolling gets selected. Most of our lists are in the same following hierarchy.

-> UIPanel (Main panel containing our script to handle other stuff, it also knows which scroll it has under it)
    -> UIPanel (Containing our scroll list script to add and remove items from the list, it knows which item prefab it has under it, this item prefab is actually the item in the scroll list)
        -> UIDragPanelContents (and a collider attached to it)
            -> UIDraggablePanel (and a UIPanel also attached to it)
                -> UIGrid

Now the item prefabs which I just mentioned has their own scripts on them to handle their own stuff like OnPress(bool isDown) function, in which we usually send a message to a target (usually parent) to updated the selection (disable a sprite from the previously pressed item and turn on a sprite for the currently selected item).

So I want to know if there is anything, anything, anything which can tell me that the user is scrolling the list and i don't need to updated the selection? If not please give a hint on how I can implement it.
Oh one more thing, I wont be able to change the hierarchy or something like that cauz we are way deep into the development now. :(

Thanks.
Abe


Abe_ForkTech

  • Guest
Re: Disable click while scrolling
« Reply #1 on: May 13, 2013, 07:53:39 AM »
Hi,

I didn't get any answer but I figured out what can be done. Here is how I did it, some one may find it helpful:

So, in the OnPress(bool isDown) function I mentioned, the "isDown" is true as long as the mouse button is in pressed state. I kept on storing the mouse position until it is released. And when it is released I compared its position. If the Y position is same, it means the user did not scroll and might need to update the selection else not. :D

private static Vector3 oldPos = Vector3.zero;

void OnPress(bool isDown) {
      if (isDown) {
         oldPos.y = Input.mousePosition.y;
         return;
      }
      
      Vector3 NewPos = Input.mousePosition;
      
      if (NewPos.y == oldPos.y) {
         //update selection; :D
      }
   }