- Home /
[C#]CalcHeight issues
As you can see, the first message over there is clipped on the chatbox of the server. It can't be that the data was lost while being transmitted, because the messages don't appear on the client until the server approves them and hands them back. If data was lost, the client wouldn't have it as well.
I assumed it is an issue with CalcHeight, but it's weird: the word was clipped as if about to be sent to the line below.
Here is the code I'm using for displaying messages in the ChatBox:
switch (message.msgType){
case MsgType.PlayerMessage:
text = "<color=#FF0000>" + DataManager.playerDataTable.Get(message.player).Get("chatName") + "</color><b>:</b> " + message.text;
message.lastKnownPlayerName = DataManager.playerDataTable.Get(message.player).Get("chatName").ToString();
break;
case MsgType.ServerMessage:
text = "<color=#00FF00>" + DataManager.serverData.Get("chatName") + "</color><b>:</b> " + message.text;
break;
case MsgType.SimpleMessage:
text = "<b><color=#FFFF00>" + message.text + "</color></b>";
break;
}
height = (int)style.CalcHeight(new GUIContent(text), chatBoxRect.width - (messageSpacer * 2)); // The markup tags are handed in too. My logic is that bold parts will be calculated with their actual width like this?
GUI.Label (new Rect(messageSpacer, y, chatBoxRect.width - (messageSpacer * 2) - 10, height), text);
y += height; // This is to arrange the messages in the chatbox.
It seems that this would be an issue with the width, not the height? The width of your chat box is different on the server versus the client. How is the width set? Is the screen size different on the server?
The chatboxes are calculated on both server and client, separately. It is meant to work with every kind of resolution or aspect ratio.
This is how I set their size:
Rect textFieldRect = new Rect(messageSpacer, Screen.height - 20 - messageSpacer, Screen.width * chatWidthFraction + 20, 20);
Rect chatBoxRect = new Rect(textFieldRect.x, textFieldRect.y - messageSpacer - (Screen.height chatHeightFraction), textFieldRect.width, Screen.height chatHeightFraction);
These are the variables:
public int messageSpacer = 5;
public float chatWidthFraction = 0.5f;
public float chatHeightFraction = 0.3333333f;
The text will always stop (20 - messageSpacer) pixels before the left edge of the ChatBox. (For the scrollbar.)
Oh, I see. It's wrapping, but not tall enough to display the wrapped text.
Shouldn't the height calculation include the "-10"? Without that, it's leaving enough room for the "name" text in this case, so it's shorter. But when you actually draw the label you're not allowing the same amount of space. Does that make sense?
Answer by Kurochi · Oct 25, 2013 at 07:57 PM
I just wanted to say that I fixed this myself. It was because of a little bit of calculation mistakes in parts of code I didn't paste here.
Thank you for your help.
Your answer
Follow this Question
Related Questions
Unet error code : unity host id out of bound id -1 max id should be greater 0 and less than 2 1 Answer
Player Spawning Network issue 1 Answer
expecting :, found '=' in checkpoint script 1 Answer
Issue where if I click a button then press W,A,S,D the value of my sliders go down by 10 or up by 10 0 Answers
Unity networking tutorial? 6 Answers