OnTargetChanged

From Intrigues Wiki
Revision as of 18:39, 4 January 2024 by Tayfunwiki (talk | contribs) (Created page with "== <code>onTargetChanged</code> Event in Scheme Class == === Overview === The <code>onTargetChanged</code> event in the Scheme class is triggered when there is a change in the target actor of a scheme. This event allows the game to dynamically respond to alterations in the scheme's target. === Event Definition === <syntaxhighlight lang="c#"> public static event Action<Scheme, Actor> onTargetChanged; </syntaxhighlight> === Description === * Parameters: ** <code>Scheme...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

onTargetChanged Event in Scheme Class

Overview

The onTargetChanged event in the Scheme class is triggered when there is a change in the target actor of a scheme. This event allows the game to dynamically respond to alterations in the scheme's target.

Event Definition

public static event Action<Scheme, Actor> onTargetChanged;

Description

  • Parameters:
    • Scheme: The scheme for which the target has changed.
    • Actor: The new target actor of the scheme.
  • Type: Action<Scheme, Actor> - A delegate type that defines the method signature for event handlers.
  • Visibility: Public.

Functionality

  • This event provides a mechanism to notify other components of the game when the target of a scheme is updated. This is crucial in games where the progression of schemes significantly impacts gameplay or narrative.
  • It can be used to update UI elements, modify game logic, or trigger specific actions in response to changes in a scheme's target.

Usage

The onTargetChanged event is instrumental in systems that require tracking of scheme targets, such as updating the display of scheme information in the UI or adjusting game mechanics based on the new target.

Example of Usage

public class SchemeTargetListener : MonoBehaviour {
    void OnEnable() {
        Scheme.onTargetChanged += HandleTargetChange;
    }

    void OnDisable() {
        Scheme.onTargetChanged -= HandleTargetChange;
    }

    private void HandleTargetChange(Scheme scheme, Actor newTarget) {
        Debug.Log($"Target of scheme '{scheme.SchemeName}' changed to: {newTarget.Name}");
    }
}

Description

  • The example shows a class subscribing to the onTargetChanged event. When the target of any scheme changes, the HandleTargetChange method logs the new target of the scheme.
  • The subscription is set up in OnEnable and removed in OnDisable to manage the event lifecycle properly.

Remarks

  • Handling the onTargetChanged event is crucial for games with dynamic scheme systems, where targets can change due to various gameplay events or player decisions.
  • Proper management of event subscriptions is necessary to prevent memory leaks and ensure that changes in targets are accurately reflected throughout the game.
  • Developers should consider how frequently targets may change and the potential impact on game performance when implementing handlers for this event.