GUILayout.SelectionGrid with GUIStyle ignores textColor

Ok, I have a GUILayout.SelectionGrid going that seems to work fine except for one thing. It only ever uses the Normal state for textColor, regardless of whatever I’m doing to the buttons in the selectionGrid. I don’t know if I’m doing something wrong, or if GUIStyle doesn’t play nice with selection grids or what. I’ve set up the style using the Unity editor, and assigned it in the following code (where raceSelected is an int, races is a string array, and menuStyle is my GUIStyle obj):

GUILayout.BeginArea(new Rect(65, 5, 150, 550));
raceSelected = GUILayout.SelectionGrid(raceSelected, races, 1, menuStyle, null);
GUILayout.EndArea();

2 Answers

2

Try setting the Background texture- I’ve noticed that Text Color is ignored unless there’s a background texture for the state

THAT'S IT!!! I just spent the last 20 minutes beating my head against this same thing! Thanks for pointing out what now seems fairly obvious... Unity uses the presence of the background image to know whether to apply or ignore the text color as well!

–

custom grid:

Problem with that, is it uses 1 draw call per button, very slow, for like 10x10 buttons is 100 draw calls. here is a button using whatever texture you want, it returns number of button clicked on your texture:

  function OnGUI(){
			var gridpixels = 20;//pixels per grid square
			var gidxsquares = 12;//num squares in x direction
			if (GUI.Button(Rect(320,10,240,60),fctbutton,GUIStyle.none))
	{
			var xpos = Input.mousePosition.x - 320 ;
			var ypos = Screen.height - Input.mousePosition.y -10;
			
			var result =  Mathf.Floor(xpos / gridpixels) + Mathf.Floor(ypos / gridpixels)*gidxsquares + 1;//plus 1 at end for not zero first square
			//
			print (result);
	}	

}