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, IInteractableActionSubclassing
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
| Field | Type | Description |
|---|---|---|
id | string | Technical identifier for sorting and programmatic lookup. |
displayName | string | Human-readable label shown in the HUD. |
icon | Sprite | Optional HUD icon. |
onExecuted | UnityEvent<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.