Author Topic: UIDraggablePanel : how to determine user is at the end of the list  (Read 2594 times)

ankit khetrapal

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 16
    • View Profile
Hi,

i am adding data dynamically on a UIDraggablePanel, now suppose i added 10 widgets and now the user is scrolling down and down to see all the widgets, now how can i determine that the user has reached the end so that i can add more data to the list.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIDraggablePanel : how to determine user is at the end of the list
« Reply #1 on: July 08, 2013, 12:10:26 PM »
Keep in mind that the draggable panel isn't meant to have dynamically added content like that, so I suggest you make a copy of the draggable panel script and modify it to suit your needs.

You will want to look at UIDraggablePanel.RestrictWithinBounds function -- particularly the "if (constraint.magnitude > 0.001f)" part.

ankit khetrapal

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 16
    • View Profile
Re: UIDraggablePanel : how to determine user is at the end of the list
« Reply #2 on: July 09, 2013, 04:06:25 AM »
if Draggable panel isn't meant to have dynamically added content, then what other alternative does NGUI provide for dynamic entries.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIDraggablePanel : how to determine user is at the end of the list
« Reply #3 on: July 09, 2013, 08:34:35 AM »
Let me clarify: draggable panel isn't meant to have content added while you are dragging. It works with fixed size content dimensions.

As I said, if you need something that adds content while you are dragging the panel, write your own custom draggable panel script.

ankit khetrapal

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 16
    • View Profile
Re: UIDraggablePanel : how to determine user is at the end of the list
« Reply #4 on: July 19, 2013, 08:12:48 AM »
well i guess writing custom drag-able panel script might have taken a lot of time and i didn't pay NGUI to write custom code so i modified UIDraggablePanel to match my requirement

Just change the RestrictWithinBounds to this add some global declarations at the top

         /// <summary>
   /// Bool to determine whether to inform other object when the user has reached top limit or bottom limit of a dragable panel
   /// </summary>
   [SerializeField]   private bool postLimitEvent;
   
   /// <summary>
   /// Reciever game object to send Limit notification.
   /// </summary>
   [SerializeField]   private GameObject recieverGameObject;

   /// <summary>
   /// Method to be called when top limit reached
   /// </summary>   
   [SerializeField]   private string topLimitMethodName;
   
   /// <summary>
   /// Method to be called when bottom limit reached
   /// </summary>
   [SerializeField]   private string bottomLimitMethodName;

   public bool RestrictWithinBounds (bool instant)
   {
      Vector3 constraint = mPanel.CalculateConstrainOffset(bounds.min, bounds.max);
      
      if(postLimitEvent)
      {
         if(constraint.y > 0)
               recieverGameObject.SendMessage(topLimitMethodName,SendMessageOptions.RequireReceiver);
         if(constraint.y < 0)
            recieverGameObject.SendMessage(bottomLimitMethodName,SendMessageOptions.RequireReceiver);   
      }
            

      if (constraint.magnitude > 0.001f)
      {
         if (!instant && dragEffect == DragEffect.MomentumAndSpring)
         {
            // Spring back into place
            SpringPanel.Begin(mPanel.gameObject, mTrans.localPosition + constraint, 13f);
         }
         else
         {
            // Jump back into place
            MoveRelative(constraint);
            mMomentum = Vector3.zero;
            mScroll = 0f;
         }
         return true;
      }
      return false;
   }


Hope other might find it help full.