Role.onRoleNameChanged

From Intrigues Wiki
Revision as of 10:45, 5 January 2024 by Tayfunwiki (talk | contribs) (Created page with "=== Role Class - <code>onRoleNameChanged</code> Event === ==== Overview ==== The <code>onRoleNameChanged</code> event in the Role class is triggered whenever there is a change in the name of a role. ==== Syntax ==== <syntaxhighlight lang="c#"> public event Action<string> onRoleNameChanged; </syntaxhighlight> ==== Description ==== This event is useful for updating UI elements, game mechanics, or other components that rely on the role's name. The event passes the previo...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Role Class - onRoleNameChanged Event

Overview

The onRoleNameChanged event in the Role class is triggered whenever there is a change in the name of a role.

Syntax

public event Action<string> onRoleNameChanged;

Description

This event is useful for updating UI elements, game mechanics, or other components that rely on the role's name. The event passes the previous name of the role as a string parameter.

Usage

Subscribe to this event to perform actions whenever a role's name is updated, such as refreshing a list of roles in a management interface or logging changes for audit purposes.

Example of Usage

public class RoleNameChangeListener : MonoBehaviour {
    void Start() {
        // Retrieve a specific role, e.g., "Leader"
        var role = IM.GetRole("Leader");

        // Subscribe to the onRoleNameChanged event
        role.onRoleNameChanged += OnRoleNameChanged;
    }

    private void OnRoleNameChanged(string oldRoleName) {
        Debug.Log($"Role name changed from {oldRoleName} to {role.RoleName}");
    }
}

Remarks

  • The onRoleNameChanged event provides a mechanism to ensure that all aspects of the game that depend on role names remain up-to-date and consistent.
  • This event is particularly important in dynamic game environments where roles may evolve or be redefined during gameplay.