- Home /
GUI Table View In Unity
I want to ask if unity supports table view control something like this* which has been made in JavaFX.
Answer by MylesLambert · Apr 21, 2013 at 02:12 PM
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.
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 containerList = new List();
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 :)
You would have to put all that in a OnGUI method or you will not see any labels or buttons
Answer by bourriquet · Mar 18, 2019 at 10:35 PM
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!
https://assetstore.unity.com/packages/tools/gui/ui-table-137867
Answer by slumtrimpet · Nov 25, 2015 at 03:38 PM
Shameless Plug: TablePro is available for Unity 5+ and does this plus a lot more now out of the box: http://u3d.as/ipR
Answer by tungnguyendev · Jan 20, 2018 at 02:59 PM
https://www.youtube.com/watch?v=UtPYR4EoXKc Hope this help!!!
If you are the developer of this table view you should add a direct link to your git repository as link chains are generally a bad idea. If something happens to the YT video this answer would be useless.
You also should add a license otherwise people will not use your script as it's not clear what is allowed. You also should clean up your scripts. Removing empty Start and Update methods will increase the performance (especially in your UITableViewCell script). Each existing Start and Update methods need to be called by the engine. If you remove them Unity won't even try calling it.
Answer by IgorZ · Jun 19, 2021 at 10:40 PM
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);
}
}
}
Your answer
Follow this Question
Related Questions
how will i get every time values in table window? 0 Answers
Change Font Size of GUI Table 0 Answers
Passing values every time to table? 0 Answers
How to Load Dynamic Form Based on User Choice Selection 2 Answers
need help for Displaying Values? 0 Answers