1 / 6

Message Text

Message Text. Chapter 12. GUI Skin. A collection of predefined GUIStyles that dictate the look and much of the behavior of each element Similar to cascading style sheets Unity GUI must be scripted Can use empty game object to attach script to Can use already present object.

margo
Download Presentation

Message Text

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Message Text Chapter 12

  2. GUI Skin • A collection of predefined GUIStyles that dictate the look and much of the behavior of each element • Similar to cascading style sheets • Unity GUI must be scripted • Can use empty game object to attach script to • Can use already present object

  3. Script – OnGUI function • GUI.Label (Rect (0,0,100,50), "This is the text string for a Label Control"); • Rect ( x_pos, y_pos, width, height). • Text size does not scale with window size

  4. Fonts in Unity • Fonts can only have one size unless it is set to Dynamic • Must make duplicate font for each size used • Generally full set of characters will be generated for each font/size combination used

  5. function OnGUI () { GUI.skin = customSkin; //GUI.Label (Rect (Screen.width/2 - 300, Screen.height - 47, 600, 32), "This is a really long and complicated bit of text, so we can test the text on screen size."); if (useText){ //global toggle if(showActionMsg) GUI.Label (Rect (Screen.width/2 - 300, Screen.height - 75, 600, 32),actionMsg); if (showText && !showActionMsg){ //local toggle if (useLongDesc) { if (showLongDesc && inRange) GUI.Label (Rect (Screen.width/2 - 250, Screen.height - 37, 500,35), longDesc); } if (showShortDesc) GUI.Label (Rect (Screen.width/2 - 250, Screen.height - 65, 500,35), shortDesc, customGUIStyle); } } // cursor control if (!navigating && !suppressPointer && !camMatch) { varpos : Vector2 = Input.mousePosition; //get the location of the cursor GUI.color = currentCursorColor; // set the cursor color to current GUI.DrawTexture (Rect(pos.x, Screen.height - pos.y,64,64), currentCursor);// draw the cursor there GUI.color = Color.white; // set the cursor color back to default } }

  6. Summary In this chapter, you were introduced to the Unity GUI as a means of adding 2D text on screen to display mouseover and message text. You discovered the GUISkin, which provides a way of creating GUI elements with a consistent look and feel, and, later, the GUIStyle, which is a means of overriding the skin in particular places. You experimented with the parameters for the GUI controls and found you could make label controls look like box controls while still acting like labels. After you learned that the GUI elements exist only through scripting, you found that Rect parameters define the position and region a control will occupy. You learned that dynamic fonts from the OS use less texture memory, but include the risk of dropping back to a default, if the font you specify doesn’t exist on the player’s system. When using the alternative to dynamic fonts, the ASCII default sets, you discovered that a duplicate font must be created for each font for each size you need, and that a texture containing the entire set of characters is created for each. Being able to draw text onscreen led to the next logical step—tapping the action object’s metadata for the correct messages for both mouseover and action message. It seemed best to break the distance to the object into two zones. The outer zone provided the mouseover short description and didn’t allow for picked objects. The inner zone provided long descriptions and allowed the action objects to be picked. Once the correct messages were working, you started hooking the animations and audio clips to the pick, using the Lookup information to determine which state the objects needed to go into and then using the object’s metadata to handle the appropriate actions. And, finally, you allowed the player control over the time the action message was shown on screen. In the next chapter, you will start to develop an inventory system and allow for different cursors, as the player collects various action objects for use through the game.

More Related