Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var lerping : boolean = false;
  2.  
  3. var someRowHeight : float = 152.0;
  4.  
  5. var scrollViewPosYPre : float = scrollViewPos.y;
  6.  
  7. scrollViewPos = GUI.BeginScrollView (rectScrollBox, scrollViewPos, rectScrollView, false, true);
  8.  
  9. for (var i:int=0; i < scrollItems.length; i++) {
  10.  
  11.     rectUnlocksItem.y = someRowHeight * i;
  12.  
  13.     GUI.Label (rectUnlocksItem, guiContentUnlocksItem, emptyGUIStyle);
  14.  
  15. }
  16.  
  17. GUI.EndScrollView();
  18.  
  19.  
  20.  
  21. var scrollViewPosYPost : float = scrollViewPos.y;  
  22.  
  23.  
  24.  
  25. // not scrolling
  26.  
  27. if( !lerping) {
  28.  
  29.     if (scrollViewPosYPre == scrollViewPosYPost) {
  30.  
  31.         // Debug.Log ("not scrolling...");
  32.  
  33.          if (scrollViewPosYPost % someRowHeight != 0) {
  34.  
  35.             Debug.Log (Time.time.ToString("f2") + ", " + gameObject.name + ": "+ "scrollViewPosYPost % someRowHeight: " + (scrollViewPosYPost % someRowHeight).ToString());
  36.  
  37.    
  38.  
  39.                 lerping = true;
  40.  
  41.                 myLerpFunction( scrollViewPosYPost, (int)(Mathf.Round(scrollPosition / (float)rowHeight) * rowHeight) );
  42.  
  43.         }
  44.  
  45.     }
  46.  
  47. }
  48.  
  49.  
  50.  
  51. function MyLerpFunction( startHeight : float, targetHeight : int )
  52.  
  53. {
  54.  
  55.     var delta : float = targetHeight - startHeight;
  56.  
  57.     var index : float = 0.0;
  58.  
  59.     var rate : float = 1.0 / 0.5 //0.5 = time to lerp in seconds
  60.  
  61.     while( index < 1.0 )
  62.  
  63.     {
  64.  
  65.         index += Time.deltaTime * rate;
  66.  
  67.         currentHeight = startHeight + delta*index;
  68.  
  69.         yield;
  70.  
  71.     }
  72.  
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement