OnFamilyEmblemChanged

From Intrigues Wiki
Revision as of 22:40, 4 January 2024 by Tayfunwiki (talk | contribs) (Created page with "== <code>onFamilyEmblemChanged</code> Event in Family Class == === Overview === The <code>onFamilyEmblemChanged</code> event in the Family class is triggered when there's a change in the family's emblem. This event is crucial in games where visual symbols like emblems play an important role in representing family identity and heritage. === Event Definition === <syntaxhighlight lang="c#"> public event Action<Sprite> onFamilyEmblemChanged; </syntaxhighlight> === Descrip...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

onFamilyEmblemChanged Event in Family Class

Overview

The onFamilyEmblemChanged event in the Family class is triggered when there's a change in the family's emblem. This event is crucial in games where visual symbols like emblems play an important role in representing family identity and heritage.

Event Definition

public event Action<Sprite> onFamilyEmblemChanged;

Description

  • Event Type: Action<Sprite>
  • Functionality: Notifies when the family's emblem is changed, providing the new emblem as a Sprite object.

Usage

The event can be used to update UI elements, reflect changes in family alliances, or trigger specific game mechanics linked to the family's visual representation. It is particularly relevant in games that emphasize heraldry, family prestige, or visual storytelling.

Example of Usage

public class FamilyEmblemListener : MonoBehaviour {
    void Start() {
        Family playerFamily = IM.Player.Family;
        if (playerFamily != null) {
            playerFamily.onFamilyEmblemChanged += HandleFamilyEmblemChange;
        }
    }

    private void HandleFamilyEmblemChange(Sprite oldEmblem) {
        // Assume 'familyEmblemImage' is a UI Image component
        Image familyEmblemImage = GetComponent<Image>();
        familyEmblemImage.sprite = IM.Player.Family.Emblem;
        Debug.Log("Player's family emblem has been updated.");
    }

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

Description

  • This example demonstrates subscribing to the onFamilyEmblemChanged event and handling it appropriately.
  • When the family's emblem changes, HandleFamilyEmblemChange is called to update the UI with the new emblem.

Remarks

  • Unsubscribing from the event in the OnDestroy method is important to prevent memory leaks.
  • The onFamilyEmblemChanged event is a key feature for maintaining visual consistency and storytelling, adapting to changes in family identity and status.