hi,
i have 4 different gui text for the gui. (time, lifes, bonus, second bonus ). every gui text have one drawcall. Together i have +4 drawcalls. Is it possible to improve it to one drawcall ?
hi,
i have 4 different gui text for the gui. (time, lifes, bonus, second bonus ). every gui text have one drawcall. Together i have +4 drawcalls. Is it possible to improve it to one drawcall ?
SpriteManager should do this for you, and people have made some GUI oriented versions of it… however, it requires jumping into the deep end or the pool.
Bumba: I’ve not looked into SpriteManager (but I will once I get over LongTopic-o-Phobia)…
But in the short term, you can cut down on your draw calls by putting all your GUI Text into one or two scrits/objects.
I have these two scripts:
// GUICategoryL.js
// This script assigns the label portion of the HUD to the screen on the Left Side only.
@script ExecuteInEditMode()
private var textLevel = "Level: ";
private var textFuel = "Fuel: ";
private var textHealth = "Health: ";
function Update () {
guiText.text = textLevel + "\n\n" + textFuel + "\n" + textHealth;
}
// GUIDataL.js
// This script assigns the data portion of the HUD to the screen on the Left Side only.
@script ExecuteInEditMode()
private var playerStatus : PlayerStatus;
function Start () {
playerStatus = FindObjectOfType(PlayerStatus);
if (!playerStatus)
Debug.Log("GUIDataR: No link to Player Status");
}
function Update () {
var currentFuel : float = (Mathf.Round(playerStatus.currentFuel));
var currentHealth : float = (Mathf.Round(playerStatus.currentHealth));
if (currentFuel < 0) {
currentFuel = 0;
}
if (currentHealth < 0) {
currentHealth = 0;
}
guiText.text = (Application.loadedLevel) + "\n\n" + currentFuel + "\n" + currentHealth;
}
That display this:
I’ve set this up in a way that I get the text to align left for the label, and right for the data. the biggest note to these scripts is the “\n” for a new line.
This is now 2 drawcalls, not 6.
BUT–
Can someone chime in with info on how drawcalls effect performance. I know you want to keep them low, but if a drawcall is simple, I gather that the impact on the game is low. ie: The it’s NOT a 1:1 rato of drawcall to performance degradation.
Is this not correct?
Well, if you want different font styles I think you would have to create 1 font that has all those styles in it and then convert each character of your strings to the actual value that shows that character in the right font… and then format it all into one single string… might be a bit of a hassle…
The closest thing I’ve done was to create a simple little font for the icons on the bottom of Age of Curling - they show the previous round results, what round you’re in and how many stones are already in play… (in this case you’re throwing the first stone of the second round and you won the first round with 2 points…)
and that’s the font:
The example above still needs 3 drawcalls as I couldn’t find a way to change the color of the font in mid-text and thus had to place 3 strings on top of each other to cover white, team-color 1 and team-color 2…
PS: Could you nice unity-people please make custom font textures (font from image instead of ttf) work with unityGUI - it took me forever to figure out that it’s simply broken and only works with GUITexts at the moment…