Skip to content

InteractableAction

Namespace: FireSoftworks.Interaction
Type: Abstract class · MonoBehaviour
Assembly: FireSofworks.InteractionSystem
Implements: IInteractableAction
Requires: [RequireComponent(typeof(InteractableTarget))]

Abstract MonoBehaviour base for component-based actions. Provides [SerializeField] fields for Id, Label, Icon, and OnExecuted, so subclasses only need to override IsAvailable() and Execute().

[RequireComponent(typeof(InteractableTarget))]
public class InteractableAction : MonoBehaviour, IInteractableAction

Subclassing

public class OpenDoorAction : InteractableAction
{
[SerializeField] private Animator _doorAnimator;
private bool _isOpen;
public override bool IsAvailable(InteractionContext context) => !_isOpen;
public override void Execute(InteractionContext context)
{
_isOpen = true;
_doorAnimator.SetTrigger("Open");
OnExecuted?.Invoke(context); // fires Inspector-wired callbacks
}
}

Inspector fields

FieldTypeDescription
idstringTechnical identifier for sorting and programmatic lookup.
displayNamestringHuman-readable label shown in the HUD.
iconSpriteOptional HUD icon.
onExecutedUnityEvent<InteractionContext>Callbacks fired after Execute().

Properties

Id

public string Id { get; }

Returns the serialized id field.

Label

public string Label { get; }

Returns the serialized displayName field.

Icon

public Sprite Icon { get; }

Returns the serialized icon field. null if unassigned.

ShowWhenUnavailable

public virtual bool ShowWhenUnavailable { get; }

Returns true by default. Override to hide this action from the HUD when unavailable.

OnExecuted

public UnityEvent<InteractionContext> OnExecuted { get; }

The serialized UnityEvent. Invoke it at the end of your Execute() override.


Virtual methods

IsAvailable(InteractionContext)

public virtual bool IsAvailable(InteractionContext context)

Default: returns this.enabled. Override to add custom availability conditions.

Execute(InteractionContext)

public virtual void Execute(InteractionContext context)

Default: invokes OnExecuted. Override with your specific action logic and call OnExecuted?.Invoke(context) at the end.