{"id":13731381,"url":"https://github.com/Mukarillo/UnityDynamicScrollRect","last_synced_at":"2025-05-08T04:33:17.472Z","repository":{"id":39229141,"uuid":"134061878","full_name":"Mukarillo/UnityDynamicScrollRect","owner":"Mukarillo","description":"An optimized approach to lists with dozens of elements and a Pooling system","archived":false,"fork":false,"pushed_at":"2021-11-15T11:55:39.000Z","size":10820,"stargazers_count":479,"open_issues_count":1,"forks_count":46,"subscribers_count":14,"default_branch":"master","last_synced_at":"2024-10-29T23:55:23.432Z","etag":null,"topics":["scroll","scrollview","ui","ui-components","unity","unity2d","unity3d-plugin"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Mukarillo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":null,"patreon":null,"open_collective":null,"ko_fi":"mukarillo","tidelift":null,"community_bridge":null,"liberapay":"mukarillo","issuehunt":null,"otechie":null,"custom":null}},"created_at":"2018-05-19T12:56:10.000Z","updated_at":"2024-10-27T01:47:34.000Z","dependencies_parsed_at":"2022-07-20T02:03:22.042Z","dependency_job_id":null,"html_url":"https://github.com/Mukarillo/UnityDynamicScrollRect","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mukarillo%2FUnityDynamicScrollRect","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mukarillo%2FUnityDynamicScrollRect/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mukarillo%2FUnityDynamicScrollRect/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mukarillo%2FUnityDynamicScrollRect/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Mukarillo","download_url":"https://codeload.github.com/Mukarillo/UnityDynamicScrollRect/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224315392,"owners_count":17290991,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["scroll","scrollview","ui","ui-components","unity","unity2d","unity3d-plugin"],"created_at":"2024-08-03T02:01:28.847Z","updated_at":"2024-11-14T22:31:04.320Z","avatar_url":"https://github.com/Mukarillo.png","language":"C#","readme":"# UnityDynamicScrollRect\nAn optimized approach to lists with dozens of elements.\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://github.com/Mukarillo/UnityDynamicScrollRect/blob/master/ReadmeAssets/dynamic_list_example.gif?raw=true\" alt=\"Example\"/\u003e\n\u003c/p\u003e\n\n## How to use\n*you can find a pratical example inside this repository in DynamicScrollScene scene*\n\n### 1 - Create a class to store all the information that each element of the list will need.\n```c#\npublic class ExampleData\n{\n      public int postId;\n      public int id;\n      public string name;\n      public string email;\n      public string body;\n}\n```\n### 2 - Create a class that extends `DynamicScrollObject\u003cExampleData\u003e` and implement its abstract members (make sure to call `base.updateScrollObject(item, index);`) and set the object width and height in `currentWidth` and `currentHeight`.\n```c#\npublic class ExampleDynamicObject : DynamicScrollObject\u003cExampleData\u003e\n{\n  public override float currentHeight { get; set; }\n  public override float currentWidth { get; set; }\n\n  private Text idText;\n  private Text nameEmailText;\n  private Text bodyText;\n\n  public void Awake()\n  {\n    currentHeight = GetComponent\u003cRectTransform\u003e().rect.height;\n    currentWidth = GetComponent\u003cRectTransform\u003e().rect.width;\n\n    idText = transform.Find(\"PostId\").GetComponent\u003cText\u003e();\n    nameEmailText = transform.Find(\"NameEmail\").GetComponent\u003cText\u003e();\n    bodyText = transform.Find(\"Body\").GetComponent\u003cText\u003e();         \n  }\n\n  public override void updateScrollObject(ExampleData item, int index)\n  {\n    base.updateScrollObject(item, index);\n\n    idText.text = item.id.ToString();\n    nameEmailText.text = string.Format(\"{0} ({1})\", item.name, item.email);\n    bodyText.text = item.body;\n  }\n}\n```\n### 3 - Create a class to initiate the DynamicList (use DynamicScrollRect instead of ScrollRect)\n```c#\npublic class ExampleScroll : MonoBehaviour\n{\n  public DynamicScrollRect verticalScroll;\n  public GameObject referenceObject;\n\n  private DynamicScroll\u003cExampleData, ExampleDynamicObject\u003e mVerticalDynamicScroll = new DynamicScroll\u003cExampleData, ExampleDynamicObject\u003e();\n\n  public IEnumerator Start()\n  {\n    WWW www = new WWW(@\"https://jsonplaceholder.typicode.com/comments\");\n    yield return www;\n    var data = JsonHelper.getJsonArray\u003cExampleData\u003e(www.text);\n\n    mVerticalDynamicScroll.spacing = 5f;\n    mVerticalDynamicScroll.Initiate(verticalScroll, data, 0, referenceObject);\n  }      \n}\n```\n\n## DynamicScroll\u003cT, T1\u003e `public` overview\n### Properties\n|name  |type  |description  |\n|--|--|--|\n|`spacing` |**float** |*Value that represent the spacing between elements of the list*  |\n|`centralizeOnStop` |**bool** |*If the list should centralize the closest element to the center of the viewport after stop moving*  |\n|`objectPool` |**readonly Pooling \u003c T1 \u003e** |*The elements of the list*  |\n|`OnDragEvent` |**Action \u003c Vector2 \u003e** |*Event that triggers whenever the user scrolls the list, the parameter represent the velocity of the drag*  |\n|`OnBeginDragEvent` |**UnityEvent \u003c PointerEventData \u003e** |*Event that triggers in the first frame of dragging*  |\n|`OnEndDragEvent` |**UnityEvent \u003c PointerEventData \u003e** |*Event that triggers in the last frame of dragging*  |\n\n### Methods\n\n\u003e `dynamicScroll.Initiate`\n- *Description*: Initiate the scroll rect with `objReference` objects applying `infoList` data.\n\n- *Parameters*:\n\n|name  |type  |description  |\n|--|--|--|\n|`scrollRect` |**ScrollRect** |*a reference to the scroll rect*  |\n|`infoList` |**T[]** |*the list with the data information*  |\n|`startIndex` |**int** |*the item of index `startindex` will be the first element of the list*  |\n|`objReference` |**GameObject** |*a reference of the object that will be inside the list*  |\n|`createMoreIfNeeded` |**bool** |*if the list needs more itens, it will create more if `createMoreIfNeeded` == true*  |\n|`forceAmount` |**int?** |*if setted, it will force `forceAmount` objects to be created at start*  |\n\n\n\u003e `dynamicScroll.ChangeList`\n- *Description*:\nChange the current list of the scroll rect.\n\n- *Parameters* :\n\n|name  |type  |description  |\n|--|--|--|\n|`infoList` |**T[]** |*the list with the data information*  |\n|`startIndex` |**int** |*the item of index `startindex` will be the first element of the list. If -1, the current index will be setted.*  |\n|`resetContentPosition` |**bool** |*reset list position*  |\n\n\n\u003e `dynamicScroll.RefreshPosition`\n- *Description*: Repaint the whole scroll rect. This is useful if any item inside the scroll rect changes the size (`currentWidth` and `currentHeight`).\n\n\n\u003e `dynamicScroll.ToggleScroll`\n- *Description*: Enable or Disable the ability to scroll the list.\n\n- *Parameters* :\n\n|name  |type  |description  |\n|--|--|--|\n|`active` |**bool** |*enable or Disable the ability to scroll the list*  |\n\n\n\u003e `dynamicScroll.CanMove`\n- *Description*: Returns true if all directions send thro parameter are available.\n\n- *Parameters* :\n\n|name  |type  |description  |\n|--|--|--|\n|`directions` |**ScrollDirection** |*Enum flag with all the directions you want to know if are available*  |\n\n\n\u003e `dynamicScroll.MoveToIndex`\n- *Description*: Tweens the content to centralize the object of index specified in the parameters.\n\n- *Parameters* :\n\n|name  |type  |description  |\n|--|--|--|\n|`i` |**int** |*Index of the element to be centralized*  |\n|`totalTime` |**float?** |*Total time to the animation happen (if you choose to input this value, the next one will be ignored)*  |\n|`timePerElement` |**float?** |*This value will be multiplied by the difference between the current centralized element and the target element to get the totalTime*  |\n\n\u003e `dynamicScroll.GetCentralizedObject`\n- *Description*: Returns the closest element to the center of the viewport.\n\n\u003e `dynamicScroll.GetLowest`\n- *Description*: Returns the most left (if horizontal scroll) or most bottom (if vertical scroll) T1 object.\n\n\u003e `dynamicScroll.GetHighest`\n- *Description*: Returns the most right (if horizontal scroll) or most upper (if vertical scroll) T1 object.\n","funding_links":["https://ko-fi.com/mukarillo","https://liberapay.com/mukarillo"],"categories":["C#"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FMukarillo%2FUnityDynamicScrollRect","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FMukarillo%2FUnityDynamicScrollRect","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FMukarillo%2FUnityDynamicScrollRect/lists"}