OnFamilyEmblemChanged
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
Spriteobject.
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
onFamilyEmblemChangedevent and handling it appropriately. - When the family's emblem changes,
HandleFamilyEmblemChangeis called to update the UI with the new emblem.
Remarks
- Unsubscribing from the event in the
OnDestroymethod is important to prevent memory leaks. - The
onFamilyEmblemChangedevent is a key feature for maintaining visual consistency and storytelling, adapting to changes in family identity and status.