Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

An optimized approach to lists with dozens of elements and a Pooling system

License

NotificationsYou must be signed in to change notification settings

Mukarillo/UnityDynamicScrollRect

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

An optimized approach to lists with dozens of elements.

Example

How to use

you can find a pratical example inside this repository in DynamicScrollScene scene

1 - Create a class to store all the information that each element of the list will need.

publicclassExampleData{publicintpostId;publicintid;publicstringname;publicstringemail;publicstringbody;}

2 - Create a class that extendsDynamicScrollObject<ExampleData> and implement its abstract members (make sure to callbase.updateScrollObject(item, index);) and set the object width and height incurrentWidth andcurrentHeight.

publicclassExampleDynamicObject:DynamicScrollObject<ExampleData>{publicoverridefloatcurrentHeight{get;set;}publicoverridefloatcurrentWidth{get;set;}privateTextidText;privateTextnameEmailText;privateTextbodyText;publicvoidAwake(){currentHeight=GetComponent<RectTransform>().rect.height;currentWidth=GetComponent<RectTransform>().rect.width;idText=transform.Find("PostId").GetComponent<Text>();nameEmailText=transform.Find("NameEmail").GetComponent<Text>();bodyText=transform.Find("Body").GetComponent<Text>();}publicoverridevoidupdateScrollObject(ExampleDataitem,intindex){base.updateScrollObject(item,index);idText.text=item.id.ToString();nameEmailText.text=string.Format("{0} ({1})",item.name,item.email);bodyText.text=item.body;}}

3 - Create a class to initiate the DynamicList (use DynamicScrollRect instead of ScrollRect)

publicclassExampleScroll:MonoBehaviour{publicDynamicScrollRectverticalScroll;publicGameObjectreferenceObject;privateDynamicScroll<ExampleData,ExampleDynamicObject>mVerticalDynamicScroll=newDynamicScroll<ExampleData,ExampleDynamicObject>();publicIEnumeratorStart(){WWWwww=newWWW(@"https://jsonplaceholder.typicode.com/comments");yieldreturnwww;vardata=JsonHelper.getJsonArray<ExampleData>(www.text);mVerticalDynamicScroll.spacing=5f;mVerticalDynamicScroll.Initiate(verticalScroll,data,0,referenceObject);}}

DynamicScroll<T, T1>public overview

Properties

nametypedescription
spacingfloatValue that represent the spacing between elements of the list
centralizeOnStopboolIf the list should centralize the closest element to the center of the viewport after stop moving
objectPoolreadonly Pooling < T1 >The elements of the list
OnDragEventAction < Vector2 >Event that triggers whenever the user scrolls the list, the parameter represent the velocity of the drag
OnBeginDragEventUnityEvent < PointerEventData >Event that triggers in the first frame of dragging
OnEndDragEventUnityEvent < PointerEventData >Event that triggers in the last frame of dragging

Methods

dynamicScroll.Initiate

  • Description: Initiate the scroll rect withobjReference objects applyinginfoList data.

  • Parameters:

nametypedescription
scrollRectScrollRecta reference to the scroll rect
infoListT[]the list with the data information
startIndexintthe item of indexstartindex will be the first element of the list
objReferenceGameObjecta reference of the object that will be inside the list
createMoreIfNeededboolif the list needs more itens, it will create more ifcreateMoreIfNeeded == true
forceAmountint?if setted, it will forceforceAmount objects to be created at start

dynamicScroll.ChangeList

  • Description:Change the current list of the scroll rect.

  • Parameters :

nametypedescription
infoListT[]the list with the data information
startIndexintthe item of indexstartindex will be the first element of the list. If -1, the current index will be setted.
resetContentPositionboolreset list position

dynamicScroll.RefreshPosition

  • Description: Repaint the whole scroll rect. This is useful if any item inside the scroll rect changes the size (currentWidth andcurrentHeight).

dynamicScroll.ToggleScroll

  • Description: Enable or Disable the ability to scroll the list.

  • Parameters :

nametypedescription
activeboolenable or Disable the ability to scroll the list

dynamicScroll.CanMove

  • Description: Returns true if all directions send thro parameter are available.

  • Parameters :

nametypedescription
directionsScrollDirectionEnum flag with all the directions you want to know if are available

dynamicScroll.MoveToIndex

  • Description: Tweens the content to centralize the object of index specified in the parameters.

  • Parameters :

nametypedescription
iintIndex of the element to be centralized
totalTimefloat?Total time to the animation happen (if you choose to input this value, the next one will be ignored)
timePerElementfloat?This value will be multiplied by the difference between the current centralized element and the target element to get the totalTime

dynamicScroll.GetCentralizedObject

  • Description: Returns the closest element to the center of the viewport.

dynamicScroll.GetLowest

  • Description: Returns the most left (if horizontal scroll) or most bottom (if vertical scroll) T1 object.

dynamicScroll.GetHighest

  • Description: Returns the most right (if horizontal scroll) or most upper (if vertical scroll) T1 object.

About

An optimized approach to lists with dozens of elements and a Pooling system

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

    Packages

    No packages published

    Contributors4

    •  
    •  
    •  
    •  

    Languages


    [8]ページ先頭

    ©2009-2025 Movatter.jp