Family.OnMemberJoin

From Intrigues Wiki
Revision as of 21:43, 4 January 2024 by Tayfunwiki (talk | contribs) (Created page with "== <code>onMemberJoin</code> Event in Family Class == === Overview === The <code>onMemberJoin</code> event in the Family class is triggered when a new member joins the family. This event is particularly relevant in games where family dynamics, lineage, and relationships play a significant role in the gameplay and narrative. === Event Definition === <syntaxhighlight lang="c#"> public Action<Actor> onMemberJoin; </syntaxhighlight> === Description === * Event Type: <cod...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

onMemberJoin Event in Family Class

Overview

The onMemberJoin event in the Family class is triggered when a new member joins the family. This event is particularly relevant in games where family dynamics, lineage, and relationships play a significant role in the gameplay and narrative.

Event Definition

public Action<Actor> onMemberJoin;

Description

  • Event Type: Action<Actor>
  • Functionality: Notifies when a new member joins the family, providing the Actor object representing the new member.

Usage

The event can be used for updating family trees, modifying family-based quests, or triggering specific storylines or dialogues in response to the addition of a new family member.

Example of Usage

public class FamilyMemberAdditionListener : MonoBehaviour {
    void Start() {
        Family playerFamily = IM.Player.Family;
        if (playerFamily != null) {
            playerFamily.onMemberJoin += HandleNewFamilyMember;
        }
    }

    private void HandleNewFamilyMember(Actor newMember) {
        Debug.Log($"A new member, {newMember.Name}, has joined the player's family.");
        // Additional logic for handling the new family member
    }

    void OnDestroy() {
        if (IM.Player.Family != null) {
            IM.Player.Family.onMemberJoin -= HandleNewFamilyMember;
        }
    }
}

Description

  • This example demonstrates how to subscribe to the onMemberJoin event and handle it.
  • When a new member joins the player's family, HandleNewFamilyMember is called, logging the name of the new member and possibly triggering additional actions or updates.

Remarks

  • It's important to unsubscribe from the event in the OnDestroy method to prevent memory leaks or unintended behavior.
  • The onMemberJoin event helps in maintaining an up-to-date and dynamic representation of the player's family, adapting to changes in family composition.