Skip to Content

IconButton

GnosisUIElementIconButton is a control element (elementId = "IconButton") for interactive icon-based actions.

It inherits GnosisUIElementControl, so it also uses control identity fields (viewId, controlIdMode, controlId) configured on the component.

Runtime parameters

In addition to built-in element parameters, GnosisUIElementIconButton supports:

  • spriteId (string) - sprite id resolved from UnityAssetRegistry and assigned on the target Image.
  • onClickInvokes (list) - list of service invokes to execute on click.
    • each item shape: { service, function, parameters? }

Example - create an icon button under a view

GameUI.CreateIconButton.Example.cs
private GnosisFunctionResult CreateInventoryIconButton() { if (Context?.Store == null || Context.CallService == null) return GnosisFunctionResult.Fail("No context"); var payload = GnosisNode.CreateObject(Context.Store); payload.Set("elementId", "IconButton"); payload.Set("parentId", "ui.InventoryView"); var parameters = GnosisNode.CreateObject(Context.Store); parameters.Set("name", "InventoryIconButton"); parameters.Set("spriteId", "icons.inventory"); var invokes = GnosisNode.CreateList(Context.Store); var pushView = GnosisNode.CreateObject(Context.Store); pushView.Set("service", "GameUI"); pushView.Set("function", "PushView"); var pushArgs = GnosisNode.CreateObject(Context.Store); pushArgs.Set("viewId", "game.panel.inventory"); pushArgs.Set("inTransitionId", "scalefade"); pushView.Set("parameters", pushArgs); invokes.Add(pushView); parameters.Set("onClickInvokes", invokes); payload.Set("parameters", parameters); return CallService("GameUI", "CreateElement", payload); }

Example - JSON payload shape

{ "service": "GameUI", "function": "CreateElement", "parameters": { "elementId": "IconButton", "parentId": "ui.InventoryView", "parameters": { "name": "InventoryIconButton", "spriteId": "icons.inventory", "onClickInvokes": [ { "service": "GameUI", "function": "PushView", "parameters": { "viewId": "game.panel.inventory", "inTransitionId": "scalefade" } } ] } } }

Example - inspect schema via DescribeUIElement

GameUI.DescribeIconButton.Example.cs
private GnosisFunctionResult DescribeIconButtonElement() { if (Context?.Store == null || Context.CallService == null) return GnosisFunctionResult.Fail("No context"); var payload = GnosisNode.CreateObject(Context.Store); payload.Set("elementId", "IconButton"); return CallService("GameUI", "DescribeUIElement", payload); }
Last updated on