//Method for determining the correct x,y,width, and height values for each bar private void RenderBars() { int width = Screen.width - 20; //-20 for padding int height = Screen.height - 20; // -20 for padding int barWidth = (width - (numOfBars * barOffset)) / numOfBars; for (int i = 0; i < numOfBars; i++) { //Must convert division to float for floating point arithmetic float barHeight = -(int)(height / 2 * ((float)values[i] / maxHeight)); int xOffset = (i * (barWidth + barOffset)) + 20; int yOffset = (height / 2) + 30; barRects[i] = new Rect(xOffset, yOffset, barWidth, barHeight); //Only set the colour to white if it is the first isntance created of the bar if (barTextures[i] == null) { barTextures[i] = new ColouredText2D(Color.white); } } }
//Draws a single bar to the screen (called once for every bar) public void GUIDrawRect(Rect position, ColouredText2D texture, int value) { if (_staticRectStyle == null) //Ensures that a new GUIStyle is not created for each bar { _staticRectStyle = new GUIStyle(); } _staticRectStyle.normal.background = texture.getTexture(); _staticRectStyle.alignment = TextAnchor.LowerCenter; _staticRectStyle.fontSize = 40 - numOfBars; //Do not display the numbers if there are 25 or more bars to display if (numOfBars < 25) { GUI.Box(position, value.ToString(), _staticRectStyle); } else { GUI.Box(position, GUIContent.none, _staticRectStyle); } }