Skip to content

Game.UI.Tooltip.RaycastNameTooltipSystem

Assembly: Game
Namespace: Game.UI.Tooltip

Type: class

Base: TooltipSystemBase

Summary:
Monitors the tool raycast while the default tool is active and displays a name tooltip for raycasted game objects. When the default tool is active and a raycast hits an entity that represents a building, transport stop, outside connection, route, creature, vehicle, aggregate, or net object, this system fetches the instance prefab, adjusts the target for wrapper entities (Residents, Controllers, Pets), resolves an icon via ImageSystem, and shows a NameTooltip bound to the NameSystem.


Fields

  • private ToolSystem m_ToolSystem
    Reference to the ToolSystem used to determine the currently active tool.

  • private DefaultToolSystem m_DefaultTool
    Cached reference to the DefaultToolSystem used to compare against the active tool.

  • private NameSystem m_NameSystem
    Used as the nameBinder for the NameTooltip to resolve/display entity names.

  • private ImageSystem m_ImageSystem
    Used to obtain an icon for the tooltip via GetInstanceIcon(instance, prefab).

  • private ToolRaycastSystem m_ToolRaycastSystem
    Used to obtain current raycast results (GetRaycastResult).

  • private NameTooltip m_Tooltip
    Instance of NameTooltip configured with path "raycastName" and nameBinder set to m_NameSystem; reused when showing tooltips.

Properties

  • None (this system does not declare public properties).

Constructors

  • public RaycastNameTooltipSystem()
    Default parameterless constructor. Marked with [Preserve] in the compiled code; no custom initialization is performed here (initialization happens in OnCreate).

Methods

  • protected override void OnCreate() : System.Void
    Initializes and caches dependent systems from the ECS world: ToolSystem, DefaultToolSystem, NameSystem, ImageSystem, and ToolRaycastSystem. Creates and configures the NameTooltip (sets path to "raycastName" and nameBinder to the NameSystem).

  • protected override void OnUpdate() : System.Void
    Main runtime logic executed each frame/update:

  • Checks that the active tool is the default tool.
  • Queries ToolRaycastSystem for a hit (GetRaycastResult).
  • Verifies the hit entity has one of the supported components (Building, TransportStop, OutsideConnection, Route, Creature, Vehicle, Aggregate, NetObject).
  • Obtains the entity's PrefabRef and then calls AdjustTargets(ref instance, ref prefab) to resolve underlying instances for Residents, Controllers, or Pets.
  • Resolves the instance icon using ImageSystem.GetInstanceIcon(instance, prefab).
  • Assigns icon and entity to m_Tooltip and calls AddMouseTooltip(m_Tooltip) (inherited from TooltipSystemBase) to display the tooltip.

  • private void AdjustTargets(ref Entity instance, ref Entity prefab) : System.Void
    Adjusts instance and prefab references when the raycast hit is a wrapper entity:

  • If the instance has a Game.Creatures.Resident component, it swaps instance/prefab to the referenced citizen and that citizen's prefab.
  • If the instance has a Controller component, it swaps to the referenced controller entity and prefab.
  • If the instance has a Game.Creatures.Pet component, it swaps to the household pet entity and prefab. This ensures the tooltip shows the correct name/icon for the actual underlying entity rather than wrapper components.

Usage Example

[Preserve]
protected override void OnCreate()
{
    base.OnCreate();
    m_ToolSystem = base.World.GetOrCreateSystemManaged<ToolSystem>();
    m_DefaultTool = base.World.GetOrCreateSystemManaged<DefaultToolSystem>();
    m_NameSystem = base.World.GetOrCreateSystemManaged<NameSystem>();
    m_ImageSystem = base.World.GetOrCreateSystemManaged<ImageSystem>();
    m_ToolRaycastSystem = base.World.GetOrCreateSystemManaged<ToolRaycastSystem>();
    m_Tooltip = new NameTooltip
    {
        path = "raycastName",
        nameBinder = m_NameSystem
    };
}

{{ Additional notes: - The system depends on TooltipSystemBase for AddMouseTooltip and on EntityManager for component queries (HasComponent/TryGetComponent). - It only shows tooltips when the DefaultToolSystem is the active tool. - Supported hit entity component types include: Building, Game.Routes.TransportStop, Game.Objects.OutsideConnection, Route, Creature, Vehicle, Aggregate, Game.Objects.NetObject. - AdjustTargets handles common wrapper component types (Resident, Controller, Pet) so the name/icon shown correspond to the underlying in-game prefab/entity. }}