Game.UI.Tooltip.NameTooltip
Assembly: Game (Assembly-CSharp)
Namespace: Game.UI.Tooltip
Type: Class
Base: Game.UI.Widgets.Widget
Summary:
A UI widget used to represent a tooltip that shows an entity's name and an optional icon. The NameTooltip holds a reference to an ECS Entity and an optional icon identifier, and it relies on a NameSystem to write/resolve the display name into a JSON writer used by the UI rendering system. When properties change the widget signals the UI system by calling SetPropertiesChanged() so the tooltip will be refreshed.
Fields
-
private System.String m_Icon
Optional icon identifier (nullable). Backing field for the public icon property; its value is serialized to the JSON writer as the "icon" property. Changing the exposed property triggers a UI refresh. -
public Unity.Entities.Entity m_Entity
Public field that contains the Entity this tooltip refers to. Use the public entity property instead of setting this field directly to ensure SetPropertiesChanged() is called and the UI updates.
Properties
-
public System.String icon { get; set; }
Nullable. Gets or sets the tooltip's icon identifier. Setting to a different value calls SetPropertiesChanged() so the UI is refreshed and the new icon is serialized. -
public Unity.Entities.Entity entity { get; set; }
Gets or sets the Entity whose name will be displayed. Setting a different Entity calls SetPropertiesChanged(). -
public NameSystem nameBinder { get; set; }
Reference to a NameSystem instance used to resolve and write the entity's display name into the IJsonWriter inside WriteProperties. Must be assigned (non-null) before the UI system invokes WriteProperties, otherwise a NullReferenceException will occur.
Constructors
public NameTooltip()
No explicit constructor is defined in the class; the default parameterless constructor (and any initialization from the base Widget) is used.
Methods
protected override void WriteProperties(IJsonWriter writer) : System.Void
Writes the widget's serializable properties to the supplied IJsonWriter. Implementation:- Calls base.WriteProperties(writer).
- Writes a property named "icon" and the current icon value.
- Writes a property named "name" and delegates to nameBinder.BindName(writer, entity) to write the resolved name for the entity. Note: nameBinder must be set before this method runs; otherwise a NullReferenceException will occur. The method is protected and is intended to be called by the UI framework when serializing widget state.
Usage Example
// Typical usage: create/configure the tooltip and let the UI system call WriteProperties when needed.
var tooltip = new NameTooltip();
// Set an icon identifier (nullable).
tooltip.icon = "Icons/BuildingSmall";
// Assign the entity to display (Unity.Entities.Entity obtained elsewhere).
tooltip.entity = someEntity;
// Acquire or reference the NameSystem used by your game's ECS to resolve display names.
// How you obtain it depends on your ECS setup; example:
tooltip.nameBinder = World.DefaultGameObjectInjectionWorld?.GetExistingSystem<NameSystem>();
// After setting these, the UI framework will call WriteProperties(writer) to serialize the icon and name.
// Do not call WriteProperties directly from outside the UI system (it's protected).