Infinite Scroll View by howtungtung - 1

ToolsGUIExtensions

InfiniteScrollView is made for Unity extension, that support use as less as possible gameObject count to achieve large infinite scrolling content. Developed by native UGUI system, no any magical code inside, so you can easily modify and extend by yourself.

Unity 2019.4.4f1MIT LicenseUpdated 12 days agoCreated on July 24th, 2020
Go to source

InfiniteScrollView

InfiniteScrollView is made for Unity extension, that support use as less as possible gameObject count to achieve large infinite scrolling content. Developed by native UGUI system, no any magical code inside, so you can easily modify and extend by yourself.

It’s support all platform which Unity supported. Tested on Unity 2019 LTS
You can also get compatible version with older Unity from the link below
2018 LTS
2017 LTS

Features

  1. Easy customize by OOP concept
  2. Support diffirent cell height or width
  3. Full sourcecode and example include

How to use

  1. Download this project and copy Assets/InfiniteScrollView to your own project

  2. There are three class you have to inherit and implement by your own context
    InfiniteCellData
    InfiniteCell
    VerticalInfiniteScrollView, HorizontalInfiniteScrollView or VerticalGridInfiniteScrollView

  3. Create CSharp script named DemoVerticalDate and inherit InfiniteCellData

using HowTungTung;
public class DemoVerticalData : InfiniteCellData
{
    public DemoVerticalData(float height)
    {
        cellSize.y = height;
    }
}
  1. Create CSharp script named DemoVerticalCell and inherit InfiniteCell<DemoVeritcalData>
using UnityEngine;
using UnityEngine.UI;
using HowTungTung;
public class DemoVerticalCell : InfiniteCell<DemoVerticalData>
{
    public Text text;

    public override void OnUpdate()
    {
        RectTransform.sizeDelta = new Vector2(RectTransform.sizeDelta.x, CellData.cellSize.y);
        text.text = CellData.cellSize.y.ToString();
    }
}
  1. Create CSharp script named DemoVerticalScrollView and inherit VerticalInfiniteScrollView<DemoVerticalData>
using HowTungTung;
public class DemoVerticalScrollView : VerticalInfiniteScrollView<DemoVerticalData>
{
    
}
  1. Create CSharp script named Tester only for test purpose
using HowTungTung;
public class Tester : MonoBehavior
{
   private void Start()
   {
       var infiniteScrollView = FindObjectOfType<DemoVerticalScrollView>();
       for (int i = 0; i < 100; i++)
       {
           var data = new DemoVerticalData(Random.Range(50, 300));
           infiniteScrollView.Add(data);
       }
   }
}
  1. Right click on Hierarchy and create UI/Scroll View
  2. Select Content at Scroll View/Viewport/Content on Hierarchy
  3. Right click and create UI/Button
  4. Click Anchor Preset on the Button object, and select left top preset with press shift and Alt key
  5. Attach DemoVerticalCell on this Button and drag into Project window to make to Prefab
  6. Delete the Button from Hierarchy
  7. Select Scroll View and attach DemoVerticalScrollView then drag the prefab we just created on Cell Prefab field of the DemoVerticalScrollView component
  8. Attach Tester to any other gameObject in scene and test it!

For more detail of the example please refer to Assets/Examples

Example

Show all projects by howtungtung