OnFamilyCultureChanged

From Intrigues Wiki
Revision as of 22:42, 4 January 2024 by Tayfunwiki (talk | contribs) (Created page with "== <code>onFamilyCultureChanged</code> Event in Family Class == === Overview === The <code>onFamilyCultureChanged</code> event in the Family class triggers when there is a change in the family's associated culture. This event is significant in games where cultural aspects play a key role in shaping family identity, traditions, and interactions within the game world. === Event Definition === <syntaxhighlight lang="c#"> public event Action<Culture> onFamilyCultureChanged...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

onFamilyCultureChanged Event in Family Class

Overview

The onFamilyCultureChanged event in the Family class triggers when there is a change in the family's associated culture. This event is significant in games where cultural aspects play a key role in shaping family identity, traditions, and interactions within the game world.

Event Definition

public event Action<Culture> onFamilyCultureChanged;

Description

  • Event Type: Action<Culture>
  • Functionality: Notifies subscribers when the family's culture is altered, providing the new Culture object.

Usage

This event can be utilized to adapt game elements, such as dialogue, missions, or character interactions, in response to the cultural shift within a family. It's particularly relevant in narrative-driven games where cultural background influences character development and story arcs.

Example of Usage

public class FamilyCultureListener : MonoBehaviour {
    void Start() {
        Family playerFamily = IM.Player.Family;
        if (playerFamily != null) {
            playerFamily.onFamilyCultureChanged += HandleFamilyCultureChange;
        }
    }

    private void HandleFamilyCultureChange(Culture oldCulture) {
        Debug.Log($"The player's family culture has been changed to: {IM.Player.Family.Culture.CultureName}, Old name: {oldCulture.CultureName}");
        // Additional logic to handle the culture change
    }

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

Description

  • In the example, the onFamilyCultureChanged event is used to handle changes in the player's family culture.
  • When the family's culture changes, HandleFamilyCultureChange is called, logging the new culture name and potentially triggering related game mechanics.

Remarks

  • It is crucial to unsubscribe from the event when the object is destroyed to avoid memory leaks or unexpected behavior.
  • The onFamilyCultureChanged event helps ensure that the game accurately reflects changes in cultural dynamics, enhancing realism and player engagement.