Author Topic: pull Down and Pull Up events  (Read 1739 times)

aammfe

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 22
    • View Profile
pull Down and Pull Up events
« on: September 06, 2016, 04:59:15 AM »
How can we add pull up/down events along with such visual indicators?
 
https://www.smashingmagazine.com/wp-content/uploads/2013/10/Twitter.gif
« Last Edit: September 07, 2016, 08:50:26 AM by aammfe »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: pull Down and Pull Up events
« Reply #1 on: September 09, 2016, 01:55:02 PM »
UIScrollView's Drag() function calls CalculateConstrainOffset on line 865 of UIScrollView.cs. This tells you whether the scroll view should be constrained on X or Y. Value of '0' means it won't be. A non-zero value means it should be. The scroll view then proceeds to reduce the drag's effect on line 883, but you can add custom code there that would do something else as well -- such as show a sprite just above the scroll view's content.

aammfe

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 22
    • View Profile
Re: pull Down and Pull Up events
« Reply #2 on: September 09, 2016, 07:33:21 PM »
Plz check this event Class



  1. using UnityEngine;
  2. using System.Collections;
  3. using System;
  4.  
  5.  
  6. public class ScrollEvents : MonoBehaviour
  7. {
  8.  
  9.     public Action OnPullDown;
  10.     public Action OnPullUp;
  11.  
  12.  
  13.  
  14.  
  15.  
  16.     [Range(0 ,250)]
  17.     public int PullDownThreshold;
  18.  
  19.  
  20.     [Range(0, 250)]
  21.     public int PullUpThreshold;
  22.  
  23.  
  24.     private UIScrollView ScrollView;
  25.     private UIPanel Panel;
  26.  
  27.  
  28.  
  29.  
  30.  
  31.     void Awake()
  32.     {
  33.  
  34.         Panel = GetComponent<UIPanel>();
  35.         ScrollView = GetComponent<UIScrollView>();
  36.  
  37.  
  38.         ScrollView.onDragFinished += DragFinished;
  39.     }
  40.  
  41.  
  42.  
  43.    
  44.  
  45.  
  46.  
  47.     private void DragFinished()
  48.     {
  49.         Bounds b = ScrollView.bounds;
  50.         Vector3 constraint = Panel.CalculateConstrainOffset(b.min, b.max);
  51.  
  52.  
  53.         if (constraint.y > PullDownThreshold)
  54.         {
  55.             if (OnPullDown != null) OnPullDown.Invoke();
  56.         }
  57.         else  if (constraint.y < -PullUpThreshold)
  58.         {
  59.            if (OnPullUp != null) OnPullUp.Invoke();
  60.         }
  61.     }
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80.     void OnDestroy()
  81.     {
  82.         ScrollView.onDragFinished -= DragFinished;
  83.     }
  84. }
  85.