Asche Lib Recycle Scroll View by AscheLab - 1

GUI

Unity 2018.3.1f1MIT LicenseUpdated 212 days agoCreated on July 19th, 2019
Go to source

AscheLib.RecycleScrollView

Created by Syunta Washidu (AscheLab)

What’s RecycleScrollView?

RecycleScrollView is a library to easily implement a scroll view that can be recycled to reduce object generation cost when displaying a large amount of data

Using for RecycleScrollView

using UnityEngine;
using UnityEngine.UI;
using AscheLib.UI;
  1. Prepare the data class you want to display
// Test data class
class ExampleData {
	public string Text { private set; get; }
	public ExampleData (string text) {
		Text = text;
	}
}
  1. Prepare cell components for displaying data
// Cell component for displaying test data
class ExampleCell : MonoBehaviour, IScrollableCell<ExampleData> {
	[SerializeField]
	Text _textLabel;

	// Hold the set data
	ExampleData _cacheData = null;

	// Method to return the held data
	ExampleData IScrollableCell<ExampleData>.GetValue () {
		return _cacheData;
	}

	// Executed when data is set
	void IScrollableCell<ExampleData>.SetValue (ExampleData value) {
		_cacheData = value;
		_textLabel.text = value.Text;
	}
}
  1. Prepare cell Prefab to display data.
    please attach the cell component created in step 2

  2. Place a UI object with the RecycleScrollView component attached on the scene

  3. Set Prefab created in step 3 to CellPrefab of Grid Settings of RecycleScrollView component
    There are other items that can be set
    b3dadb508c3ff1f6a0417df127becd9c

  4. Set the list of data you want to display to RecycleScrollView

// Set Scroll View object to display data from Inspector
[SerializeField]
RecycleScrollView _scrollView;

// Number of test data
[SerializeField]
int _dataRange;

private void Start () {
    // Create test data.
    List<ExampleData> dataList = Enumerable.Range(0, _dataRange)
        .Select(v => new ExampleData ("Data" + v))
        .ToList();

    // Sets data in scroll view.
    // Then the data will be displayed according to the content set in ScrollView
    _scrollView.SetDatas(dataList);
}

License

This library is under the MIT License.

Show all projects by AscheLab