GUI Table View In Unity

I want to ask if unity supports table view control something like this* which has been made in JavaFX.

http://s12.postimg.org/reimjc8gr/table_View.png

http://s18.postimg.org/b2g47ql8p/table_edit.png

You would need to look at creating this yourself using the existing GUI labels. It shouldn’t be too hard depending on how many features you need.

1.) Consider the method to store the data. If you need something quite dynamic I’d suggest a list of a class that contains all the variables you need. Like this:

public class variablecontainer : Object {
	public string firstname, lastname;
	public byte age;
}

List<variablecontainer> containerList = new List<variablecontainer>();

2.) To display this data just use a for loop with a bunch of labels containing the data you need to display.

	private void drawsingleline (int pos, variablecontainer toShow) {
		GUI.Label(new Rect(0,pos*32, 128,32), toShow.firstname);
		GUI.Label(new Rect(128,pos*32, 128,32), toShow.lastname);
		GUI.Label(new Rect(256,pos*32, 128,32), toShow.age.ToString());
	}
	
	private void drawTable () {
		int i = 0;
		foreach (variablecontainer thecont in containerList) {
			drawsingleline(i, thecont);
			i++;
		}
	}

Obviously you will need to go a lot further to make this nice and functional. But it should give you a head start :slight_smile:

Shameless Plug: TablePro is available for Unity 5+ and does this plus a lot more now out of the box:

Hope this help!!!

I developed this plugin for this usage. You just have to give it a collection and select the properties for the columns and it will draw the table automatically.

I hope it helps!

I ended up developing my own class that draws the table based on GUI.Label. When you can specify fixed widths for the columns it’s trivial, but when you cannot know in advance what would be the column width, then it’s a challenge. In my class what I do is collecting strings and calculating their width in the Layout phase. Then, in the Repaint these widths are used to draw the properly aligned and scaled table.

Here is the code. Usage:

  GUILayoutStringTable _guiTable = new GUILayoutStringTable(4, keepMaxSize: true);

  void OnGUI() {
    for (var i = 0; i < 10; i++) {
      _guiTable.StartNewRow();
      using (new GUILayout.HorizontalScope()) {
        _guiResourcesTable.AddTextColumn("column1", GUI.skin.button);
        _guiResourcesTable.AddTextColumn("column2", GUI.skin.button);
        _guiResourcesTable.AddTextColumn("column3", GUI.skin.button);
        _guiResourcesTable.AddTextColumn("column4", GUI.skin.button);
      }
    }
  }