Add a button to toolbar/selection grid?

I am trying to make a “tab” view similar to the one in the internet browsers where you have a tab line and a “+” button to make a new button (and well, “-” to remove it), so I am trying to make a GUI.toolbar and add buttons… But I am just confused how to do it…

toolbar and selection grids require Arrays, but it is hard to add elements to array, no? (at least I couldn’t find how to do it in C#), and when I found it they said “use lists!” but toolbar/selection grid doesn’t support lists… So, how can I do it??

Also if you know a simpler way to do a tabbed menu (or an example of it) than this, it would be helpful

You can simply use lists and call their ToArray() method upon passing it to GUI.Toolbar.

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class TabbedGUI : MonoBehaviour {
	private int currentTab = 0;
	private List<string> tabs = new List<string>();
	
	public void AddTab(string title) {
		tabs.Add(title);
	}
	
	public void RemoveTab(string title) {
		tabs.Remove(title);
	}
	
	void OnGUI() {
		// Notice the List<string>.ToArray() call.
		currentTab = GUI.Toolbar(new Rect(0, 0, 50, Screen.width), currentTab, tabs.ToArray());
	}
}

Keep in mind that this code doesn’t check for duplicate tab titles. In that case the RemoveTab method may remove the wrong tab from the list!