Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Kurochi · Oct 25, 2013 at 05:55 PM · networkingissueissues

[C#]CalcHeight issues

alt text

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.
mc49u.png (92.3 kB)
Comment
Add comment · Show 4
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Dave-Carlile · Oct 25, 2013 at 05:56 PM 0
Share

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?

avatar image Kurochi · Oct 25, 2013 at 06:15 PM 0
Share

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.)

avatar image Dave-Carlile · Oct 25, 2013 at 06:32 PM 0
Share

Oh, I see. It's wrapping, but not tall enough to display the wrapped text.

avatar image Dave-Carlile · Oct 25, 2013 at 06:36 PM 0
Share

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?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

16 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges