Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
131 changes: 124 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# What is this?

UITableViewForUnity is a componet which can be used for implementing various of list UI views with Unity engine.
UITableViewForUnity is a component which can be used for implementing various list UI views with the Unity engine.

For example
| Chat | Nested Scrolling | Appendable List
Expand All @@ -14,9 +14,24 @@ For example
![](sample_changeable_grid.gif) | ![](sample_grid_drag.gif) | ![](sample_grid_del.gif) |


# Why I need this?
# Why do I need this?

UITableViewForUnity will help you to develop various of list views effectively without care for the number of items(gameobject), because them will be reused when disappeared from viewport of ScrollRect. Also, you can turn off the reuse feature for any cell which you do not want to reuse.
UITableViewForUnity will help you to develop various list views effectively without worrying about the number of items (GameObjects), because they will be reused when they disappear from the viewport of the ScrollRect. Also, you can turn off the reuse feature for any cell which you do not want to reuse.

## Key Features

- **Cell Lifecycle Management**: Three types of cell lifecycle options:
- `RecycleWhenDisappeared`: Cells are recycled when they scroll out of view (default, best for performance)
- `RecycleWhenReloaded`: Cells remain until `ReloadData()` is called (useful for heavy cells)
- `DestroyWhenDisappeared`: Cells are destroyed when they scroll out of view

- **Multiple Cell Types**: Support different cell types in a single table view (e.g., messages, images, locations in a chat app)

- **Dynamic Cell Sizes**: Each cell can have a different height/width

- **Append/Prepend Data**: Add cells to the beginning or end of the list dynamically

- **Scroll to Index**: Programmatically scroll to any cell by index

# Installation

Expand All @@ -28,11 +43,113 @@ UITableViewForUnity will help you to develop various of list views effectively w
## .unitypackage
Download the unitypackage from the [Releases](https://github.com/zhaozilong1988/UITableViewForUnity/releases), then import it to your project.

# How to use?
# Quick Start Guide

## Step 1: Create a Cell Class

Create a class that extends `UITableViewCell`:

```csharp
using UnityEngine.UI;

namespace UIKit.Samples
{
public class SimpleCell : UITableViewCell
{
public Text text;
public Image icon;
public Image background;
}
}
```

## Step 2: Implement Data Source and Delegate

Create a MonoBehaviour that implements `IUITableViewDataSource` and `IUITableViewDelegate`:

```csharp
using UnityEngine;

namespace UIKit.Samples
{
public class SimpleTableScene : MonoBehaviour, IUITableViewDataSource, IUITableViewDelegate
{
[SerializeField] UITableView _tableView;
[SerializeField] SimpleCell _cellPrefab;

void Start()
{
// Set the data source and delegate
_tableView.dataSource = this;
_tableView.@delegate = this;

// Reload the table view to refresh the UI
_tableView.ReloadData();
}

#region IUITableViewDataSource
// Return the cell for the given index
public UITableViewCell CellAtIndexInTableView(UITableView tableView, int index)
{
return _tableView.ReuseOrCreateCell(_cellPrefab);
}

// Return the total number of cells
public int NumberOfCellsInTableView(UITableView tableView)
{
return 200;
}

// Return the height (or width for horizontal) of each cell
public float LengthForCellInTableView(UITableView tableView, int index)
{
return index % 2 == 0 ? 150 : 200; // Variable heights
}
#endregion

#region IUITableViewDelegate
// Called when a cell is about to appear
public void CellAtIndexInTableViewWillAppear(UITableView tableView, int index)
{
var cell = tableView.GetLoadedCell<SimpleCell>(index);
cell.text.text = $"Cell Index: {index}";
}

// Called when a cell has disappeared
public void CellAtIndexInTableViewDidDisappear(UITableView tableView, int index)
{
var cell = tableView.GetLoadedCell<SimpleCell>(index);
cell.text.text = string.Empty;
}
#endregion
}
}
```

## Step 3: Set Up the Scene

1. Create a Canvas with a ScrollRect
2. Add a UITableView component to the ScrollRect
3. Create a cell prefab with your SimpleCell script
4. Assign the prefab and UITableView to your scene script

# More Examples

Check the samples in the [Assets/UIKit/Samples](https://github.com/zhaozilong1988/UITableViewForUnity/tree/master/Assets/UIKit/Samples) folder or in the Unity Package Manager's Samples tab:

Check the samples in the [Assets/UIKit/Samples](https://github.com/zhaozilong1988/UITableViewForUnity/tree/master/Assets/UIKit/Samples) folder or in the Unity Package Manager’s Samples tab
![](samples_tab.png)

# The concept of design
| Sample | Description |
| --- | --- |
| 0_SimpleTable | Basic table view with variable cell heights |
| 1_Chat | Chat-style list with multiple cell types |
| 2_Sns | Social media feed with append/prepend support |
| 3_SimpleGrid | Basic grid layout |
| 4_NetflixLike | Nested scrolling lists |
| 5_AdvancedGrid | Advanced grid with drag & delete |
| 6_AdvancedTable | Expandable/collapsible cells |
| 7_SnappingTable | Snap-to-cell scrolling |

# The Concept of Design

The design of UITableViewForUnity referred to the [UITableView](https://developer.apple.com/documentation/uikit/uitableview) of [UIKit](https://developer.apple.com/documentation/uikit) framework on iOS.
The design of UITableViewForUnity is based on the [UITableView](https://developer.apple.com/documentation/uikit/uitableview) of the [UIKit](https://developer.apple.com/documentation/uikit) framework on iOS.
104 changes: 103 additions & 1 deletion README_jp.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,113 @@ Cellの高さを自由(0不可)に調整できるので、ジャバラ式みた
## .unitypackage
[Releases](https://github.com/zhaozilong1988/UITableViewForUnity/releases)からunitypackageファイルをダウンロードして、プロジェクトにインポートします。

# 使い方
# クイックスタートガイド

## ステップ1:Cellクラスの作成

`UITableViewCell`を継承したクラスを作成します:

```csharp
using UnityEngine.UI;

namespace UIKit.Samples
{
public class SimpleCell : UITableViewCell
{
public Text text;
public Image icon;
public Image background;
}
}
```

## ステップ2:DataSourceとDelegateの実装

`IUITableViewDataSource`と`IUITableViewDelegate`を実装するMonoBehaviourを作成します:

```csharp
using UnityEngine;

namespace UIKit.Samples
{
public class SimpleTableScene : MonoBehaviour, IUITableViewDataSource, IUITableViewDelegate
{
[SerializeField] UITableView _tableView;
[SerializeField] SimpleCell _cellPrefab;

void Start()
{
// DataSourceとDelegateを設定
_tableView.dataSource = this;
_tableView.@delegate = this;

// TableViewをリロードしてUIを更新
_tableView.ReloadData();
}

#region IUITableViewDataSource
// 指定されたインデックスのCellを返す
public UITableViewCell CellAtIndexInTableView(UITableView tableView, int index)
{
return _tableView.ReuseOrCreateCell(_cellPrefab);
}

// Cellの総数を返す
public int NumberOfCellsInTableView(UITableView tableView)
{
return 200;
}

// 各Cellの高さ(横向きの場合は幅)を返す
public float LengthForCellInTableView(UITableView tableView, int index)
{
return index % 2 == 0 ? 150 : 200; // 可変高さ
}
#endregion

#region IUITableViewDelegate
// Cellが表示される直前に呼ばれる
public void CellAtIndexInTableViewWillAppear(UITableView tableView, int index)
{
var cell = tableView.GetLoadedCell<SimpleCell>(index);
cell.text.text = $"Cell Index: {index}";
}

// Cellが非表示になった時に呼ばれる
public void CellAtIndexInTableViewDidDisappear(UITableView tableView, int index)
{
var cell = tableView.GetLoadedCell<SimpleCell>(index);
cell.text.text = string.Empty;
}
#endregion
}
}
```

## ステップ3:シーンの設定

1. ScrollRectを含むCanvasを作成
2. ScrollRectにUITableViewコンポーネントを追加
3. SimpleCellスクリプトを持つCellプレハブを作成
4. プレハブとUITableViewをシーンスクリプトに割り当て

# サンプル一覧

[Assets/UIKit/Samples](https://github.com/zhaozilong1988/UITableViewForUnity/tree/master/Assets/UIKit/Samples)フォルダー内のサンプル、または Unity Package Manager の「Samples」タブをご確認ください。

![](samples_tab.png)

| サンプル | 説明 |
| --- | --- |
| 0_SimpleTable | 可変高さのセルを持つ基本的なテーブルビュー |
| 1_Chat | 複数のセルタイプを持つチャット形式のリスト |
| 2_Sns | 追加/先頭追加をサポートするSNS形式のフィード |
| 3_SimpleGrid | 基本的なグリッドレイアウト |
| 4_NetflixLike | ネストされたスクロールリスト |
| 5_AdvancedGrid | ドラッグ&削除機能付きの高度なグリッド |
| 6_AdvancedTable | 展開/折りたたみ可能なセル |
| 7_SnappingTable | セルにスナップするスクロール |

# 設計について

UITableViewForUnityは、基本iOSの[UIKit](https://developer.apple.com/documentation/uikit)フレームワークの[UITableView](https://developer.apple.com/documentation/uikit/uitableview)の設計を参考して実装していますが、いくつか違うところもあります。
Expand Down