C# Class SpriteText, marblemadness

Inheritance: MonoBehaviour
Exibir arquivo Open project: MtvnGames/marblemadness Class Usage Examples

Public Properties

Property Type Description
alignment Alignment_Type
anchor Anchor_Pos
characterSize float
characterSpacing float
color Color
dynamicLength bool
font UnityEngine.TextAsset
hideAtStart bool
ignoreClipping bool
lineSpacing float
maskingCharacter string
maxWidth float
multiline bool
offsetZ float
parseColorTags bool
password bool
persistent bool
pixelPerfect bool
removeUnsupportedCharacters bool
renderCamera Camera
tabSize int
text string

Protected Properties

Property Type Description
UVs Vector2[]
capacity int
clipped bool
clippingRect Rect3D
colDel string[]
colors Color[]
commaDelimiter char[]
displayString string
faces int[]
lineSpaceSize float
localClipRect Rect
m_awake bool
m_hidden bool
m_started bool
mesh Mesh
meshColors Color[]
meshFilter UnityEngine.MeshFilter
meshRenderer UnityEngine.MeshRenderer
meshString string
mirror SpriteTextMirror,
newLineDelimiter char[]
newLineInserts List
oldMesh Mesh
plainText string
screenPlacer EZScreenPlacement,
screenSize Vector2
spriteFont SpriteFont,
stringContentChanged bool
tabSpaces string
texture Texture
topLeft Vector3
totalWidth float
unclippedTL Vector3
updateClipping bool
updateColors bool
vertices Vector3[]
worldUnitsPerScreenPixel float
worldUnitsPerTexel float
worldUnitsPerUV Vector2

Public Methods

Method Description
CalcSize ( ) : void
Copy ( SpriteText, s ) : void

Duplicates the settings of another SpriteText object.

Delete ( ) : void

Call Delete() before destroying this component or the GameObject to which it is attached. Memory leaks can ensue otherwise.

DisplayIndexToPlainIndex ( int dispCharIndex ) : int

Converts a character index in the display text string to a corresponding index in the plain text string.

DoMirror ( ) : void
GetCenterPoint ( ) : Vector3

Gets the center point of the text's extents in local space.

GetDisplayLineCount ( ) : int

Returns the number of lines actually being displayed, as opposed to the number of lines in the string assigned to the object. In other words, if word-wrapping is being used, the number of actual lines displayed may be more than the number of lines in the actual string.

GetDisplayLineCount ( int charIndex, int &charLine, int &lineStart, int &lineEnd ) : int

Returns the number of lines actually being displayed, as opposed to the number of lines in the string assigned to the object. In other words, if word-wrapping is being used, the number of actual lines displayed may be more than the number of lines in the actual string. It also stores the line number of the character at the specified index in the string.

GetInsertionPointPos ( int charIndex ) : Vector3

Returns the position, in world space, of the insertion point relative to a specified character (specified by index). The position returned is at the left edge of, and the baseline of, the specified character.

GetNearestInsertionPoint ( Vector3 point ) : int

Returns both the world-space position of the insertion point most nearly matching the specified point, as well as the index of the character to the left of which the insertion point corresponds.

GetNearestInsertionPointPos ( Vector3 point, int &insertionPt ) : Vector3

Returns both the world-space position of the insertion point most nearly matching the specified point, as well as the index of the character to the left of which the insertion point corresponds.

GetScreenWidth ( string s ) : float

Returns the width, in screen pixels, of the specified string were it to be rendered using the current font and settings. NOTE: Assumes the string is a single line.

GetVertices ( ) : Vector3[]

Returns a reference to the text's vertices.

GetWidth ( string s ) : float

Returns the width, in world units, of the specified string were it to be rendered using the current font and settings. NOTE: Assumes the string is a single line.

Hide ( bool tf ) : void

Hides or displays the text by disabling/enabling the mesh renderer component.

IsHidden ( ) : bool

Returns whether the text is currently set to be hidden (whether its mesh renderer component is enabled).

OnDestroy ( ) : void
OnDrawGizmos ( ) : void
OnDrawGizmosSelected ( ) : void
OnEnable ( ) : void
PixelCoordToUVCoord ( Vector2 xy ) : Vector2

Converts pixel coordinates to UV coordinates according to the currently assigned material. NOTE: This is for converting coordinates and will reverse the Y component accordingly. For converting widths and heights, use PixelSpaceToUVSpace()!

PixelCoordToUVCoord ( int x, int y ) : Vector2

Converts pixel coordinates to UV coordinates according to the currently assigned material. NOTE: This is for converting coordinates and will reverse the Y component accordingly. For converting widths and heights, use PixelSpaceToUVSpace()!

PixelSpaceToUVSpace ( Vector2 xy ) : Vector2

Converts pixel-space values to UV-space scalar values according to the currently assigned material. NOTE: This is for converting widths and heights-not coordinates (which have reversed Y-coordinates). For coordinates, use PixelCoordToUVCoord()!

PixelSpaceToUVSpace ( int x, int y ) : Vector2

Converts pixel-space values to UV-space scalar values according to the currently assigned material. NOTE: This is for converting widths and heights-not coordinates (which have reversed Y-coordinates). For coordinates, use PixelCoordToUVCoord()!

PlainIndexToDisplayIndex ( int plainCharIndex ) : int

Converts a character index in the plain text string to a corresponding index in the display string.

SetAlignment ( Alignment_Type a ) : void

Sets the alignment of the text (left, right, center).

SetAnchor ( Anchor_Pos a ) : void

Sets the anchor type to use. See Anchor_Pos

SetCamera ( ) : void

A no-argument version of SetCamera() that simply re-assigns the same camera to the object, forcing it to recalculate all camera-dependent calculations.

SetCamera ( Camera c ) : void

Sets the camera to use when calculating a pixel-perfect character size.

SetCharacterSize ( float size ) : void

Sets the size (height) of the text such that a capital character that extends from the baseline to the absolute top of the line will be the specified height in world units. All other characters will be sized proportionately. If called while set to pixel perfect, pixel-perfect will be automatically disabled.

SetColor ( Color c ) : void

Sets the text's color to the specified color. NOTE: Will not override color tags in the text itself.

SetFont ( SpriteFont, newFont, Material fontMaterial ) : void

Changes the font to be used for this text object.

SetFont ( TextAsset newFont, Material fontMaterial ) : void

Changes the font to be used for this text object.

SetLineSpacing ( float spacing ) : void

Sets the spacing between lines as a percentage of the character size. i.e. a value of 1.1 means 10% of the height of a full-height character will be placed between lines.

SetPixelToUV ( Texture tex ) : void
SetPixelToUV ( int texWidth, int texHeight ) : void
Start ( ) : void
Unclip ( ) : void

Removes any clipping that is being applied to the text object.

Update ( ) : void
UpdateCamera ( ) : void

Updates any camera-dependent settings, such as the calculated pixel-perfect size. Use this with BroadcastMessage() to do bulk re-calculation of object sizes whenever your screensize/resolution changes at runtime.

UpdateMesh ( ) : void

Protected Methods

Method Description
Awake ( ) : void
BuildCharacter ( int vertNum, int charNum, Vector3 upperLeft, SpriteChar &ch ) : void
ClearMesh ( ) : void
CreateMesh ( ) : void
DoSingleLineTruncation ( ) : void
EnlargeMesh ( ) : void
GetLineBaseline ( int numLines, int lineNum ) : float
GetStartPos_SingleLine ( float baseHeight, float width ) : Vector3
Init ( ) : void
LayoutText ( ) : void
Layout_Line ( Vector3 startPos, string txt, int charIdx ) : void
Layout_Multiline ( string lines ) : void
Layout_Single_Line ( ) : void
OnDisable ( ) : void
ParseColor ( string str ) : Color
ParseHexColor ( string str ) : Color
ProcessString ( string str ) : void
ZeroQuad ( int i ) : void

Method Details

Awake() protected method

protected Awake ( ) : void
return void

BuildCharacter() protected method

protected BuildCharacter ( int vertNum, int charNum, Vector3 upperLeft, SpriteChar &ch ) : void
vertNum int
charNum int
upperLeft Vector3
ch SpriteChar
return void

CalcSize() public method

public CalcSize ( ) : void
return void

ClearMesh() protected method

protected ClearMesh ( ) : void
return void

Copy() public method

Duplicates the settings of another SpriteText object.
public Copy ( SpriteText, s ) : void
s SpriteText, The SpriteText object to be copied.
return void

CreateMesh() protected method

protected CreateMesh ( ) : void
return void

Delete() public method

Call Delete() before destroying this component or the GameObject to which it is attached. Memory leaks can ensue otherwise.
public Delete ( ) : void
return void

DisplayIndexToPlainIndex() public method

Converts a character index in the display text string to a corresponding index in the plain text string.
public DisplayIndexToPlainIndex ( int dispCharIndex ) : int
dispCharIndex int
return int

DoMirror() public method

public DoMirror ( ) : void
return void

DoSingleLineTruncation() protected method

protected DoSingleLineTruncation ( ) : void
return void

EnlargeMesh() protected method

protected EnlargeMesh ( ) : void
return void

GetCenterPoint() public method

Gets the center point of the text's extents in local space.
public GetCenterPoint ( ) : Vector3
return Vector3

GetDisplayLineCount() public method

Returns the number of lines actually being displayed, as opposed to the number of lines in the string assigned to the object. In other words, if word-wrapping is being used, the number of actual lines displayed may be more than the number of lines in the actual string.
public GetDisplayLineCount ( ) : int
return int

GetDisplayLineCount() public method

Returns the number of lines actually being displayed, as opposed to the number of lines in the string assigned to the object. In other words, if word-wrapping is being used, the number of actual lines displayed may be more than the number of lines in the actual string. It also stores the line number of the character at the specified index in the string.
public GetDisplayLineCount ( int charIndex, int &charLine, int &lineStart, int &lineEnd ) : int
charIndex int The index of the character sought.
charLine int OUT: The 1-based line number on which the character /// at charIndex sits.
lineStart int OUT: The index of the first character on the same line as the character at the specified index.
lineEnd int OUT: The index of the last character on the same line as the character at the specified index (excludes ending newline character).
return int

GetInsertionPointPos() public method

Returns the position, in world space, of the insertion point relative to a specified character (specified by index). The position returned is at the left edge of, and the baseline of, the specified character.
public GetInsertionPointPos ( int charIndex ) : Vector3
charIndex int The 0-based index of the character to the right of /// where you want an insertion point. 0 indicates the very beginning, /// and an index equal to the string's length indicates an insertion point /// at the very end of the string.
return Vector3

GetLineBaseline() protected method

protected GetLineBaseline ( int numLines, int lineNum ) : float
numLines int
lineNum int
return float

GetNearestInsertionPoint() public method

Returns both the world-space position of the insertion point most nearly matching the specified point, as well as the index of the character to the left of which the insertion point corresponds.
public GetNearestInsertionPoint ( Vector3 point ) : int
point Vector3 A point, in world space, from which you want to find /// the nearest insertion point.
return int

GetNearestInsertionPointPos() public method

Returns both the world-space position of the insertion point most nearly matching the specified point, as well as the index of the character to the left of which the insertion point corresponds.
public GetNearestInsertionPointPos ( Vector3 point, int &insertionPt ) : Vector3
point Vector3 A point, in world space, from which you want to find /// the nearest insertion point.
insertionPt int OUT: Will hold the index of the character to /// the left of which the insertion point will be. If the insertion point is /// at the end of the string, this value will be one greater than the index /// of the last character.
return Vector3

GetScreenWidth() public method

Returns the width, in screen pixels, of the specified string were it to be rendered using the current font and settings. NOTE: Assumes the string is a single line.
public GetScreenWidth ( string s ) : float
s string The string to measure.
return float

GetStartPos_SingleLine() protected method

protected GetStartPos_SingleLine ( float baseHeight, float width ) : Vector3
baseHeight float
width float
return Vector3

GetVertices() public method

Returns a reference to the text's vertices.
public GetVertices ( ) : Vector3[]
return Vector3[]

GetWidth() public method

Returns the width, in world units, of the specified string were it to be rendered using the current font and settings. NOTE: Assumes the string is a single line.
public GetWidth ( string s ) : float
s string The string to measure.
return float

Hide() public method

Hides or displays the text by disabling/enabling the mesh renderer component.
public Hide ( bool tf ) : void
tf bool When true, the text is hidden, when false, the text will be displayed.
return void

Init() protected method

protected Init ( ) : void
return void

IsHidden() public method

Returns whether the text is currently set to be hidden (whether its mesh renderer component is enabled).
public IsHidden ( ) : bool
return bool

LayoutText() protected method

protected LayoutText ( ) : void
return void

Layout_Line() protected method

protected Layout_Line ( Vector3 startPos, string txt, int charIdx ) : void
startPos Vector3
txt string
charIdx int
return void

Layout_Multiline() protected method

protected Layout_Multiline ( string lines ) : void
lines string
return void

Layout_Single_Line() protected method

protected Layout_Single_Line ( ) : void
return void

OnDestroy() public method

public OnDestroy ( ) : void
return void

OnDisable() protected method

protected OnDisable ( ) : void
return void

OnDrawGizmos() public method

public OnDrawGizmos ( ) : void
return void

OnDrawGizmosSelected() public method

public OnDrawGizmosSelected ( ) : void
return void

OnEnable() public method

public OnEnable ( ) : void
return void

ParseColor() protected method

protected ParseColor ( string str ) : Color
str string
return Color

ParseHexColor() protected method

protected ParseHexColor ( string str ) : Color
str string
return Color

PixelCoordToUVCoord() public method

Converts pixel coordinates to UV coordinates according to the currently assigned material. NOTE: This is for converting coordinates and will reverse the Y component accordingly. For converting widths and heights, use PixelSpaceToUVSpace()!
public PixelCoordToUVCoord ( Vector2 xy ) : Vector2
xy Vector2 The coordinates to convert.
return Vector2

PixelCoordToUVCoord() public method

Converts pixel coordinates to UV coordinates according to the currently assigned material. NOTE: This is for converting coordinates and will reverse the Y component accordingly. For converting widths and heights, use PixelSpaceToUVSpace()!
public PixelCoordToUVCoord ( int x, int y ) : Vector2
x int The x-coordinate to convert.
y int The y-coordinate to convert.
return Vector2

PixelSpaceToUVSpace() public method

Converts pixel-space values to UV-space scalar values according to the currently assigned material. NOTE: This is for converting widths and heights-not coordinates (which have reversed Y-coordinates). For coordinates, use PixelCoordToUVCoord()!
public PixelSpaceToUVSpace ( Vector2 xy ) : Vector2
xy Vector2 The values to convert.
return Vector2

PixelSpaceToUVSpace() public method

Converts pixel-space values to UV-space scalar values according to the currently assigned material. NOTE: This is for converting widths and heights-not coordinates (which have reversed Y-coordinates). For coordinates, use PixelCoordToUVCoord()!
public PixelSpaceToUVSpace ( int x, int y ) : Vector2
x int The X-value to convert.
y int The Y-value to convert.
return Vector2

PlainIndexToDisplayIndex() public method

Converts a character index in the plain text string to a corresponding index in the display string.
public PlainIndexToDisplayIndex ( int plainCharIndex ) : int
plainCharIndex int The index in the plain string to be converted.
return int

ProcessString() protected method

protected ProcessString ( string str ) : void
str string
return void

SetAlignment() public method

Sets the alignment of the text (left, right, center).
public SetAlignment ( Alignment_Type a ) : void
a Alignment_Type The alignment to use.
return void

SetAnchor() public method

Sets the anchor type to use. See Anchor_Pos
public SetAnchor ( Anchor_Pos a ) : void
a Anchor_Pos The anchor method to use.
return void

SetCamera() public method

A no-argument version of SetCamera() that simply re-assigns the same camera to the object, forcing it to recalculate all camera-dependent calculations.
public SetCamera ( ) : void
return void

SetCamera() public method

Sets the camera to use when calculating a pixel-perfect character size.
public SetCamera ( Camera c ) : void
c Camera
return void

SetCharacterSize() public method

Sets the size (height) of the text such that a capital character that extends from the baseline to the absolute top of the line will be the specified height in world units. All other characters will be sized proportionately. If called while set to pixel perfect, pixel-perfect will be automatically disabled.
public SetCharacterSize ( float size ) : void
size float The size of a full-height character, in world units.
return void

SetColor() public method

Sets the text's color to the specified color. NOTE: Will not override color tags in the text itself.
public SetColor ( Color c ) : void
c Color Color to shade the text.
return void

SetFont() public method

Changes the font to be used for this text object.
public SetFont ( SpriteFont, newFont, Material fontMaterial ) : void
newFont SpriteFont, Reference to the SpriteFont to be used for this text object.
fontMaterial Material The material to use for the new font.
return void

SetFont() public method

Changes the font to be used for this text object.
public SetFont ( TextAsset newFont, Material fontMaterial ) : void
newFont UnityEngine.TextAsset The TextAsset that defines the font to be used.
fontMaterial Material The material to use for the new font.
return void

SetLineSpacing() public method

Sets the spacing between lines as a percentage of the character size. i.e. a value of 1.1 means 10% of the height of a full-height character will be placed between lines.
public SetLineSpacing ( float spacing ) : void
spacing float Percentage of the line height to place between lines.
return void

SetPixelToUV() public method

public SetPixelToUV ( Texture tex ) : void
tex Texture
return void

SetPixelToUV() public method

public SetPixelToUV ( int texWidth, int texHeight ) : void
texWidth int
texHeight int
return void

Start() public method

public Start ( ) : void
return void

Unclip() public method

Removes any clipping that is being applied to the text object.
public Unclip ( ) : void
return void

Update() public method

public Update ( ) : void
return void

UpdateCamera() public method

Updates any camera-dependent settings, such as the calculated pixel-perfect size. Use this with BroadcastMessage() to do bulk re-calculation of object sizes whenever your screensize/resolution changes at runtime.
public UpdateCamera ( ) : void
return void

UpdateMesh() public method

public UpdateMesh ( ) : void
return void

ZeroQuad() protected method

protected ZeroQuad ( int i ) : void
i int
return void

Property Details

UVs protected_oe property

protected Vector2[] UVs
return Vector2[]

alignment public_oe property

How the text is to be aligned.
public Alignment_Type alignment
return Alignment_Type

anchor public_oe property

The position of the center of the GameObject relative to the text.
public Anchor_Pos anchor
return Anchor_Pos

capacity protected_oe property

protected int capacity
return int

characterSize public_oe property

The size, in world units, of a full-height character. All other characters will be sized proportionately.
public float characterSize
return float

characterSpacing public_oe property

An adjustable factor by which you can increase/decrease the spacing between characters. A value of 1.0 will space characters exactly as described by the font. Decreasing this value will place the characters closer together, while increasing it will place them farther apart.
public float characterSpacing
return float

clipped protected_oe property

protected bool clipped
return bool

clippingRect protected_oe property

protected Rect3D clippingRect
return Rect3D

colDel protected_oe static_oe property

protected static string[] colDel
return string[]

color public_oe property

The color to be used by all of the text's vertices. This can be used to color, highlight, or fade the text. Be sure to use a vertex-colored shader for this to have an effect.
public Color color
return Color

colors protected_oe property

protected Color[] colors
return Color[]

commaDelimiter protected_oe static_oe property

protected static char[] commaDelimiter
return char[]

displayString protected_oe property

protected string displayString
return string

dynamicLength public_oe property

When true, this setting tells the script that it should optimize its behavior on the assumption that its contents will change size frequently. When false, it will be optimized on the assumption that its length will remain the same for most, if not all, of the time.
public bool dynamicLength
return bool

faces protected_oe property

protected int[] faces
return int[]

font public_oe property

Text asset that defines the font to be used.
public TextAsset,UnityEngine font
return UnityEngine.TextAsset

hideAtStart public_oe property

Whether the text will be hidden when it starts.
public bool hideAtStart
return bool

ignoreClipping public_oe property

When true, the text will not be clipped.
public bool ignoreClipping
return bool

lineSpaceSize protected_oe property

protected float lineSpaceSize
return float

lineSpacing public_oe property

The distance from one line to the next as a percentage of characterSize. Defaults to a distance that is 1.1 times the height of a character. This has the effect of creating a gap between lines that is 10% the height of a line.
public float lineSpacing
return float

localClipRect protected_oe property

protected Rect localClipRect
return Rect

m_awake protected_oe property

protected bool m_awake
return bool

m_hidden protected_oe property

protected bool m_hidden
return bool

m_started protected_oe property

protected bool m_started
return bool

maskingCharacter public_oe property

Holds the character to be used to mask password text. Defaults to asterisk (*).
public string maskingCharacter
return string

maxWidth public_oe property

When set to a value over 0, if the multiline setting is true, then the content of the SpriteText object will be word-wrapped when a line reaches the specified maximum width (specified in local units), otherwise the text displayed will be truncated and "..." will be appended. NOTE: The actual text contents are preserved and only the display string is truncated.
public float maxWidth
return float

mesh protected_oe property

protected Mesh mesh
return Mesh

meshColors protected_oe property

protected Color[] meshColors
return Color[]

meshFilter protected_oe property

protected MeshFilter,UnityEngine meshFilter
return UnityEngine.MeshFilter

meshRenderer protected_oe property

protected MeshRenderer,UnityEngine meshRenderer
return UnityEngine.MeshRenderer

meshString protected_oe property

protected string meshString
return string

mirror protected_oe property

protected SpriteTextMirror, mirror
return SpriteTextMirror,

multiline public_oe property

When set to true, the text object will allow multi-line content. This also enables word-wrapping when the maxWidth setting is set to a non-zero value. If multiline is false, then a non-zero maxWidth setting will cause text that exceeds the maxWidth to be truncated and have "..." appended. NOTE: The actual text contents are preserved and only the display string is truncated.
public bool multiline
return bool

newLineDelimiter protected_oe static_oe property

protected static char[] newLineDelimiter
return char[]

newLineInserts protected_oe property

protected List newLineInserts
return List

offsetZ public_oe property

The distance the text is to be offset along the local Z-axis from the GameObject's center.
public float offsetZ
return float

oldMesh protected_oe property

protected Mesh oldMesh
return Mesh

parseColorTags public_oe property

If set to false, color tags will not be parsed out of the text.
public bool parseColorTags
return bool

password public_oe property

When set to true, all text in this control will be masked using the specified maskingCharacter.
public bool password
return bool

persistent public_oe property

This must be set to true at design time for the object to survive loading a new level.
public bool persistent
return bool

pixelPerfect public_oe property

Automatically sizes the text so that it will display pixel-perfect on-screen. NOTE: If you change the orthographic size of the camera or the distance between the text and a perspective camera, call SetCamera() to make the text pixel-perfect again.
public bool pixelPerfect
return bool

plainText protected_oe property

protected string plainText
return string

removeUnsupportedCharacters public_oe property

When true, any unsupported characters in the string assigned to this object at runtime will be removed from the string. NOTE: Using this on large amounts of text may have an adverse impact on performance.
public bool removeUnsupportedCharacters
return bool

renderCamera public_oe property

public Camera renderCamera
return Camera

screenPlacer protected_oe property

protected EZScreenPlacement, screenPlacer
return EZScreenPlacement,

screenSize protected_oe property

protected Vector2 screenSize
return Vector2

spriteFont protected_oe property

protected SpriteFont, spriteFont
return SpriteFont,

stringContentChanged protected_oe property

protected bool stringContentChanged
return bool

tabSize public_oe property

The number of space characters which are produced by a tab character.
public int tabSize
return int

tabSpaces protected_oe property

protected string tabSpaces
return string

text public_oe property

The (decorated) text the object is to contain. NOTE: This is only for use in the inspector at edit time. The ".Text" or ".PlainText" properties should be used in script at runtime.
public string text
return string

texture protected_oe property

protected Texture texture
return Texture

topLeft protected_oe property

protected Vector3 topLeft
return Vector3

totalWidth protected_oe property

protected float totalWidth
return float

unclippedTL protected_oe property

protected Vector3 unclippedTL
return Vector3

updateClipping protected_oe property

protected bool updateClipping
return bool

updateColors protected_oe property

protected bool updateColors
return bool

vertices protected_oe property

protected Vector3[] vertices
return Vector3[]

worldUnitsPerScreenPixel protected_oe property

protected float worldUnitsPerScreenPixel
return float

worldUnitsPerTexel protected_oe property

protected float worldUnitsPerTexel
return float

worldUnitsPerUV protected_oe property

protected Vector2 worldUnitsPerUV
return Vector2