class : MonoBehaviour
CCText is a component that uses a mesh to display a box of text.
CCTextModifier
objects and only when the
a modifier is called by the CCText
object during an update.
None of them are serialized, except mesh
, but the mesh object itself is not saved.
Vector3
Minimum bounds coordinates used for bounding the mesh, in local space units. Modifiers might want change this if they update vertices.
Vector3
Maximum bounds coordinates used for bounding the mesh, in local space units. Modifiers might want change this if they update vertices.
Mesh
Mesh used to display the text. Modifiers might want to access it.
Vector3[]
Vertices used to position character sprites. Modifiers might want to access these. Will be pushed to the mesh after the modifier has been called.
Color[]
Colors used to color character sprites. Modifiers might want to access these. Will not be pushed to the mesh by default, that's up to the modifier.
Vector2[]
UV coordinates used to texture the character sprites. Modifiers might want to access these. Will be pushed to the mesh after the modifier has been called.
int[]
Triangles used to define character sprites. Modifiers might want to access these, but probably not. Will not be pushed to the mesh by default.
char [int]
Get a character from the currently displayed text at some position.
Uses StringBuilder
if assigned, otherwise Text
.
CCText.AlignmentMode
Get or set the text alignment. Setting a different value triggers an update.
CCText.BoundingMode
Get or set the bounding mode. Setting a different value triggers an update.
CCText.HorizontalAnchorMode
Get or set the horizontal anchor mode. Setting a different value triggers an update.
CCText.VerticalAnchorMode
Get or set the vertical anchor mode. Setting a different value triggers an update.
Vector3
Get the minimum bounds of the caret based on minBounds
and font borders, in local space units.
Will be incorrect if a modifier changed minBounds
.
Vector3
Get the maximum bounds of the caret based on maxBounds
and font borders, in local space units.
Will be incorrect if a modifier changed maxBounds
.
int
Get or set the chunk sized used to increase SpriteCount
, with a minimum of 1
.
Color
Get or set the color of the text. Setting a different value triggers a color reset and an update.
CCFont
Get or set the font used to place text.
No text is displayed if set to null
or an invalid font.
Setting a different value triggers an update.
int
Get the length of the text currently being displayed.
Uses StringBuilder
if assigned, otherwise Text
.
int
Get the number of text lines currently being displayed.
float
Get or set the line height, in local space units, with a minimum of 0f
.
A height of 1f
corresponds to the font's default line height.
Setting a different value triggers an update.
float
Get the line width to which the caret is constrained.
Might be the same as Width
, depending on Width
, Bounding
, and Font
.
CCTextModifier
Get or set the modifier used to alter the text sprites. Can be null
. Setting a different value triggers an update.
Vector3
Get or set the text offset relative to the anchor. Setting a different value triggers an update.
int
Get how many sprites are currently allocated.
int
Get how many sprites are currently used to display characters.
StringBuilder
Get or set the StringBuilder
used to display text. Setting a different value triggers an update.
Modifying the StringBuilder
itself does not trigger an update.
If not null
, will be used instead of Text
.
string
Get or set the string
used to display text. Setting always triggers an update. Setting to null
will result in the empty string.
Will be ignored if StringBuilder
is not null
.
float
Get or set the tab size, in local space units, with a minimum of 0.001f
.
Setting a different value triggers an update.
float
Get or set the width of the box containing the text, with a minimum of 0f
.
Setting a different value triggers an update.
int
Return the index of the character hit by a raycast, or -1 if no character was hit.
This is a convenient alternative for the TriangleToCharacterIndex
method.
RaycastHit
A successful raycast hit.
using UnityEngine; public class HitTest : MonoBehaviour { public CCText text; void Update () { if(!Input.GetMouseButtonDown(0)){ return; } RaycastHit hit; if(Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit)){ Debug.Log(text.HitCharacterIndex(hit)); } } }
void
Reset the colors of all character sprites. By default colors aren't updated.
You typically don't call this method explictly.
void
Update the text mesh. Is called automatically when setting most properties.
Typically, you only call this yourself after modifying the contents of a StringBuilder
.
int
Return the index of a character based on a triangle index. Return -1 if no matching character was found.
int
Index of a triangle.
enum
How to align text.
enum
How to bound text.
enum
How to anchor text horizontally.
enum
How to anchor text vertically.
using System.Text; using UnityEngine; public class CCTextExample : MonoBehaviour { public CCText textBox; public string[] names = {"Alfred", "Bob", "Charlie"}; public int[] scores = {9999999, 700042, 9001}; private StringBuilder sb; void Start () { sb = new StringBuilder(); textBox.StringBuilder = sb; UpdateHighScores(); } public void UpdateHighScores () { sb.Length = 0; for(int i = 0; i < names.Length; i++){ sb.Append(names[i]); sb.Append('\t'); CCStringBuilderUtility.AppendIntGrouped(sb, scores[i], 9); sb.AppendLine(); } textBox.UpdateText(); } }The above code defines a component that contains high score information which it uses to update a
CCText
component.
You can add this component to any game object, including the CCText
component, as long as you
properly set its textBox property. It calls UpdateHighScores
on start, but you can call
it through scripting at any later time, for instance after high score data has changed.
The high score list will look reasonable if you use a monospace font, left align the text, and set a large enough tab size. If you want to make it very elaborate, it might be easiest to place two seperate text boxes next to each other instead of trying to combine it all into one box.