Skip to content

Instantly share code, notes, and snippets.

@tklee1975
Created April 2, 2019 07:58
Show Gist options
  • Select an option

  • Save tklee1975/99212617ce332d58423afe75e56ec5bf to your computer and use it in GitHub Desktop.

Select an option

Save tklee1975/99212617ce332d58423afe75e56ec5bf to your computer and use it in GitHub Desktop.
Sample Code for TSTable (Simple Scenario)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using Tacticsoft;
public class TestTableViewCell : TableViewCell
{
[SerializeField] public Text m_rowText;
public void SetRowText(string text) {
m_rowText.text = text;
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Tacticsoft;
public class TestTableViewController : MonoBehaviour, ITableViewDataSource
{
[SerializeField] int m_numRows = 10;
[SerializeField] TableView m_tableView;
[SerializeField] TestTableViewCell m_cellPrefab = null;
private int m_numInstancesCreated = 0;
// Start is called before the first frame update
void Start() {
m_tableView.dataSource = this;
}
// Update is called once per frame
void Update()
{
}
#region ITableViewDataSource
//Will be called by the TableView to know how many rows are in this table
public int GetNumberOfRowsForTableView(TableView tableView) {
return m_numRows;
}
//Will be called by the TableView to know what is the height of each row
public float GetHeightForRowInTableView(TableView tableView, int row) {
return (m_cellPrefab.transform as RectTransform).rect.height;
//return 30.0f; // (m_cellPrefab.transform as RectTransform).rect.height;
}
//Will be called by the TableView when a cell needs to be created for display
public TableViewCell GetCellForRowInTableView(TableView tableView, int row) {
TestTableViewCell cell = tableView.GetReusableCell(m_cellPrefab.reuseIdentifier) as TestTableViewCell;
if(cell == null) {
cell = (TestTableViewCell) GameObject.Instantiate(m_cellPrefab);
cell.name = "VisibleCounterCellInstance_" + (++m_numInstancesCreated).ToString();
}
cell.SetRowText("Row " + row);
// VisibleCounterCell cell = tableView.GetReusableCell(m_cellPrefab.reuseIdentifier) as VisibleCounterCell;
// if (cell == null) {
// cell = (VisibleCounterCell)GameObject.Instantiate(m_cellPrefab);
// cell.name = "VisibleCounterCellInstance_" + (++m_numInstancesCreated).ToString();
// }
// cell.SetRowNumber(row);
// return cell;
return cell;
}
#endregion
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment