Class Nameplate
The overhead plate for one thing in the world: a stack of rows, a style, and a point to hang them over. Rendered by whatever UI layer is present rather than by a renderer of its own.
[DisallowMultipleComponent]
public sealed class Nameplate : MonoBehaviour
- Inheritance
-
ObjectComponentBehaviourMonoBehaviourNameplate
- Inherited Members
-
MonoBehaviour.IsInvoking()MonoBehaviour.CancelInvoke()MonoBehaviour.StopCoroutine(Coroutine)MonoBehaviour.StopAllCoroutines()MonoBehaviour.destroyCancellationTokenMonoBehaviour.useGUILayoutMonoBehaviour.didStartMonoBehaviour.didAwakeMonoBehaviour.runInEditModeBehaviour.enabledBehaviour.isActiveAndEnabledComponent.GetComponent<T>()Component.TryGetComponent<T>(out T)Component.GetComponentInChildren<T>()Component.GetComponentsInChildren<T>()Component.GetComponentInParent<T>()Component.GetComponentsInParent<T>()Component.GetComponents<T>()Component.GetComponentIndex()Component.CompareTag(TagHandle)Component.transformComponent.transformHandleComponent.gameObjectComponent.tagObject.GetEntityId()Object.GetInstanceID()Object.GetHashCode()Object.InstantiateAsync<T>(T)Object.InstantiateAsync<T>(T, Transform)Object.InstantiateAsync<T>(T, Vector3, Quaternion)Object.InstantiateAsync<T>(T, Transform, Vector3, Quaternion)Object.Instantiate(Object, Vector3, Quaternion)Object.Instantiate(Object, Vector3, Quaternion, Transform)Object.Instantiate(Object)Object.Instantiate(Object, Scene)Object.Instantiate<T>(T, InstantiateParameters)Object.Instantiate<T>(T, Vector3, Quaternion, InstantiateParameters)Object.Instantiate(Object, Transform)Object.Instantiate<T>(T)Object.Instantiate<T>(T, Vector3, Quaternion)Object.Instantiate<T>(T, Vector3, Quaternion, Transform)Object.Instantiate<T>(T, Transform)Object.Destroy(Object)Object.DestroyImmediate(Object)Object.DontDestroyOnLoad(Object)Object.DestroyObject(Object)Object.FindObjectsOfType<T>()Object.FindObjectsByType<T>(FindObjectsSortMode)Object.FindObjectsByType<T>(FindObjectsInactive, FindObjectsSortMode)Object.FindObjectOfType<T>()Object.FindFirstObjectByType<T>()Object.FindAnyObjectByType<T>()Object.FindFirstObjectByType<T>(FindObjectsInactive)Object.FindAnyObjectByType<T>(FindObjectsInactive)Object.FindObjectsByType<T>()Object.FindObjectsByType<T>(FindObjectsInactive)Object.ToString()Object.nameObject.hideFlags
Remarks
Why this exists instead of a group of WorldLabels. A nameplate used to be several labels parented to the same overhead anchor, each projected onto the screen independently and then pushed apart vertically by the renderer. Two labels a few centimetres apart in the world do not stay a fixed number of pixels apart on screen: as the camera pitches, that world-space gap projects to a different screen-space gap — and to none at all when the camera looks straight down the offset — so the correction that separated them at one camera angle overlapped them at another. Rotating the camera made names collide, and no amount of tuning the correction could fix it, because the premise (a fixed screen offset between two separately projected points) is what was wrong.
A plate is ONE anchor. It projects once, and its rows are laid out by the UI's own vertical layout inside a single element, in points, where a gap authored as two points is two points at every camera angle in the game. The stack cannot come apart because it is not assembled from independently positioned pieces.
What stays with WorldLabel. Damage numbers, healing numbers, region captions and anything else that is one free-floating piece of text with a lifetime of its own. Those never wanted to be grouped, and they keep the pooled label path with its effect timeline.
This is data, not a renderer. Like WorldLabel it has no visual of its own, is never instantiated by the server, and is inert in a headless build. It is also deliberately not client-only code: the rows are written from Shared — a name resolving, a guild changing, an interactable declaring what it is — and only the drawing is the client's business.
Fields
RuntimeObjectName
The name given to plates this class builds at runtime.
public const string RuntimeObjectName = "Nameplate"
Field Value
Properties
Active
Read-only view of the currently enabled plates, for a renderer to walk.
public static IReadOnlyList<Nameplate> Active { get; }
Property Value
AllianceTint
The faction-standing colour used by every part of the style tinted Alliance.
public Color AllianceTint { get; set; }
Property Value
- Color
Remarks
Written by the client, because standing is the viewer's question and not the plate's: the same orc is an enemy to one player and a neutral to another, and a plate that resolved its own colour would be answering for the wrong client.
LineCount
How many rows the plate carries.
public int LineCount { get; }
Property Value
Lines
The rows, in the order they stack from the top down.
public IReadOnlyList<NameplateLine> Lines { get; }
Property Value
Priority
Draw-order bias; higher paints in front and is dropped last by the budget.
public int Priority { get; set; }
Property Value
Revision
Bumped by every change to the rows.
public int Revision { get; }
Property Value
Style
The style this plate is drawn with: its own if it authors one, its asset's if it references one, otherwise the default plate.
public NameplateStyle Style { get; }
Property Value
StyleAsset
The shared style this plate references, if any.
public NameplateStyleAsset StyleAsset { get; }
Property Value
StyleRevision
Bumped by every change to the style or the tint, including the asset's own edits.
public int StyleRevision { get; }
Property Value
Remarks
Folds the referenced asset's revision in, so editing a shared style while the client is running restyles every plate using it without the plates having to subscribe to anything.
Visible
Whether the plate is drawn.
public bool Visible { get; set; }
Property Value
Remarks
A flag rather than the GameObject's active state, which is what the old label stack used. A plate carries the rows other systems write into it — a name resolved on spawn, a guild that arrived while the plate was hidden — and deactivating the object to hide it would deregister the plate and drop that state on the floor. Hiding is a rendering decision and this is where it belongs.
WorldOffset
World-space offset from this transform to the plate's anchor point.
public Vector3 WorldOffset { get; set; }
Property Value
- Vector3
WorldPosition
The world point the plate's bottom edge sits at.
public Vector3 WorldPosition { get; }
Property Value
- Vector3
Methods
ClearLine(NameplateSlot)
Removes a standard row.
public bool ClearLine(NameplateSlot slot)
Parameters
slotNameplateSlotWhich row.
Returns
- bool
True when a row was actually removed.
ClearLine(int)
Removes a row by key.
public bool ClearLine(int key)
Parameters
keyintThe row's identity.
Returns
- bool
True when a row was actually removed.
ClearLines()
Removes every row.
public void ClearLines()
Remarks
For a plate being handed to something else — a pooled interactable coming back out of the pool as a different object — where the previous occupant's rows would otherwise show through.
GetOrCreate(Transform, Vector3)
Finds the plate on a hierarchy, building one if it has none.
public static Nameplate GetOrCreate(Transform root, Vector3 localOffset)
Parameters
rootTransformThe object the plate belongs to.
localOffsetVector3Where the plate hangs, in the root's local space, when one is built.
Returns
- Nameplate
The plate, or null when
rootis null.
Remarks
For the things that are worth a plate but were never authored with one — a chest, a harvest node, a dropped item. An authored plate always wins, so adding one to a prefab later takes over from this without any code changing. The built plate starts hidden and carries no rows, exactly like an authored one.
SetLine(NameplateSlot, string)
Writes a standard row, coloured by the plate's style.
public void SetLine(NameplateSlot slot, string text)
Parameters
slotNameplateSlotWhich row.
textstringThe text; null or blank removes the row.
SetLine(NameplateSlot, string, Color)
Writes a standard row in a colour of its own.
public void SetLine(NameplateSlot slot, string text, Color color)
Parameters
slotNameplateSlotWhich row.
textstringThe text; null or blank removes the row.
colorColorThe colour to draw it in, overriding the style.
SetLine(int, int, string, float)
Writes a row of the caller's own, at the caller's own place in the stack.
public void SetLine(int key, int order, string text, float scale = 0.85)
Parameters
keyintThe row's identity. Use Custom or above.
orderintWhere it stacks; ascending from the top of the plate.
textstringThe text; null or blank removes the row.
scalefloatFont scale relative to the plate's name row.
SetLine(int, int, string, Color, float)
Writes a row of the caller's own, in a colour of its own.
public void SetLine(int key, int order, string text, Color color, float scale = 0.85)
Parameters
keyintThe row's identity. Use Custom or above.
orderintWhere it stacks; ascending from the top of the plate.
textstringThe text; null or blank removes the row.
colorColorThe colour to draw it in, overriding the style.
scalefloatFont scale relative to the plate's name row.
SetStyle(NameplateStyle)
Gives this plate a style of its own, overriding any referenced asset.
public void SetStyle(NameplateStyle value)
Parameters
valueNameplateStyleThe style to draw with.
SetStyle(NameplateStyleAsset)
Points this plate at a shared style, or at none.
public void SetStyle(NameplateStyleAsset value)
Parameters
valueNameplateStyleAssetThe style asset, or null for the default plate.
Remarks
Clears the inline style flag: a caller asking for a shared style at runtime — a boss entering its final phase, a quest giver becoming relevant — means it, and leaving an inline style in place to silently win would make the call do nothing.
TryGetLine(NameplateSlot, out NameplateLine)
Reads a standard row back.
public bool TryGetLine(NameplateSlot slot, out NameplateLine line)
Parameters
slotNameplateSlotWhich row.
lineNameplateLineThe row, when one is present.
Returns
- bool
True when the plate carries that row.
TryGetLine(int, out NameplateLine)
Reads a row back.
public bool TryGetLine(int key, out NameplateLine line)
Parameters
keyintThe row's identity.
lineNameplateLineThe row, when one is present.
Returns
- bool
True when the plate carries that row.
Events
OnNameplateDisabled
Raised when a plate is disabled or destroyed, so a renderer can release it.
public static event Action<Nameplate> OnNameplateDisabled
Event Type
OnNameplateEnabled
Raised when a plate is enabled, so a renderer can build backing UI for it.
public static event Action<Nameplate> OnNameplateEnabled