CharacterDetailsButton - jimdroberts/FishMMO GitHub Wiki
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.
-
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).
-
public event CharacterSelectEvent OnCharacterSelected
Event triggered when this character button is selected. The delegate provides the selected button instance.
-
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.
- Attach
CharacterDetailsButton
to a UI button GameObject in your character selection panel. - Assign the
CharacterButton
,CharacterNameLabel
, andCharacterSceneLabel
references in the inspector. - Call
Initialize(details)
to set up the button for a specific character. - Subscribe to
OnCharacterSelected
to handle selection events. - Use
SetLabelColors
andResetLabelColor
to visually indicate selection or focus.
// 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();
- 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.