CharacterDetailsButton - jimdroberts/FishMMO GitHub Wiki

Description

The CharacterDetailsButton is a UI component in the FishMMO client that represents a selectable button for a player character in the character selection screen. It displays the character's name and scene, manages selection events, and allows for dynamic label color changes to indicate selection or focus.


API Access

Fields

  • public Button CharacterButton

    The button component for selecting the character.

  • public TMP_Text CharacterNameLabel

    The label displaying the character's name.

  • public TMP_Text CharacterSceneLabel

    The label displaying the character's scene name.

  • public CharacterDetails Details

    The details of the character represented by this button.

  • private Color labelColor

    The color used for the character name label (for reset purposes).

Events

  • public event CharacterSelectEvent OnCharacterSelected

    Event triggered when this character button is selected. The delegate provides the selected button instance.

Methods

  • public void Initialize(CharacterDetails details)

    Initializes the button with character details and sets up labels.

  • public void OnClick_CharacterButton()

    Called when the character button is clicked. Triggers the selection event.

  • public void ResetLabelColor()

    Resets the character name label color to its original value.

  • public void SetLabelColors(Color color)

    Sets the character name label color to the specified color and stores the previous color for reset.


Basic Usage

Setup

  1. Attach CharacterDetailsButton to a UI button GameObject in your character selection panel.
  2. Assign the CharacterButton, CharacterNameLabel, and CharacterSceneLabel references in the inspector.
  3. Call Initialize(details) to set up the button for a specific character.
  4. Subscribe to OnCharacterSelected to handle selection events.
  5. Use SetLabelColors and ResetLabelColor to visually indicate selection or focus.

Example

// Initialize the button
characterButton.Initialize(characterDetails);

// Subscribe to selection event
characterButton.OnCharacterSelected += OnCharacterSelected;

// Change label color on selection
characterButton.SetLabelColors(Color.yellow);

// Reset label color when deselected
characterButton.ResetLabelColor();

Best Practices

  • Always initialize the button with valid character details before displaying it.
  • Use the selection event to update the UI or load character data as needed.
  • Use color changes to provide clear visual feedback for selection or focus.
  • Reset label colors when the selection state changes to maintain UI consistency.
  • Ensure all UI references are assigned in the inspector to avoid null reference errors.
⚠️ **GitHub.com Fallback** ⚠️