Jump to content

ScreenMessage Colors


Recommended Posts

In 0.22, Squad has the science parts posting variously-colored ScreenMessages via ScreenMessages.PostScreenMessage. However, I can't find a clean example of how to color them or alter the fonts. Does anyone here know how to do so?

TIA

Link to comment
Share on other sites

  • 1 month later...

Adding this here in case it helps somebody searching for this in the future: dumping the actual message object contents to the log shows that messages apparently recognize some HTML tags, so for instance this works to produce orange italic text:


ScreenMessages.PostScreenMessage(
"<color=#ff9900ff>["+part.partInfo.title+"] <i>"+subject.title+":</i> Container Full.</color>",
10f, ScreenMessageStyle.UPPER_LEFT
);

P.S. Interestingly, these dumped messages also appear colored etc in the in-game debug log viewer window, so this may be some obscure feature of unity GUI controls in general.

Edited by a.g.
Link to comment
Share on other sites

To follow up on this as well, the ScreenMessages system appears to be intended for use with a persistent message whose contents are updated; this is how the "bump" toggle is useful, for instance.

Put another way, rather than building a new ScreenMessage object with new content and style each time you need a new message, one would re-use a single ScreenMessage object for each purpose. For example, the KSP code uses a single persistent ScreenMessage per antenna for all transmission updates with each antenna.

Good to know about the HTML tags; I might have to make use of that. :)

Link to comment
Share on other sites

To follow up on this as well, the ScreenMessages system appears to be intended for use with a persistent message whose contents are updated; this is how the "bump" toggle is useful, for instance.

Put another way, rather than building a new ScreenMessage object with new content and style each time you need a new message, one would re-use a single ScreenMessage object for each purpose. For example, the KSP code uses a single persistent ScreenMessage per antenna for all transmission updates with each antenna.

Good to know about the HTML tags; I might have to make use of that. :)

Another way to do it is to set the screanMessageTime to Time.fixedDeltaTime, this way, it only lasts one frame and is correctly updated every frame.

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...