Author Topic: changing UIDraggable for direction bounding  (Read 1253 times)

huminado

  • Guest
changing UIDraggable for direction bounding
« on: May 02, 2013, 03:03:55 PM »
I added the following lines of code to let UIDraggable only drag in one direction.  Maybe worth folding in?  Of course is it isn't used it adds a few instructions.  The purpose was to allow swiping a menu to make it disappear and it should never swipe the other way.


UIDraggable (lines with ">" were inserted):

   public Vector3 scale = Vector3.one;
   
>   public Vector3 dirBound   =   Vector3.zero;   // x=0 allows free movement, x=1 only allows positive movement, x=-1 only negative, etc all axis


...   void OnDrag (Vector2 delta)
   {
      if (enabled && NGUITools.GetActive(gameObject) && target != null)
      {
         UICamera.currentTouch.clickNotification = UICamera.ClickNotification.BasedOnDelta;

         Ray ray = UICamera.currentCamera.ScreenPointToRay(UICamera.currentTouch.pos);
         float dist = 0f;

         if (mPlane.Raycast(ray, out dist))
         {
            Vector3 currentPos = ray.GetPoint(dist);
            Vector3 offset = currentPos - mLastPos;
            mLastPos = currentPos;
            
>            if ( ( dirBound.x > 0 && offset.x < 0 ) || ( dirBound.x < 0 && offset.x > 0 ) )   {
>               offset.x=0;
>            }
>            if ( ( dirBound.y > 0 && offset.y < 0 ) || ( dirBound.y < 0 && offset.y > 0 ) )   {
>               offset.y=0;
>            }

            if ( (offset.x != 0f || offset.y != 0f) )
            {...