UIAbilities - jimdroberts/FishMMO GitHub Wiki

Description

A UI control for displaying and managing ability buttons in the FishMMO client. Handles the display of all abilities, known abilities, and known ability events, and allows switching between different ability tabs. Integrates with the character and ability controller to update the UI in response to game events.


API Access

Fields

  • public RectTransform AbilityParent

    The parent RectTransform for ability button UI elements.

  • public UIAbilityButton AbilityButtonPrefab

    The prefab used to instantiate ability buttons.

  • public Button AbilitiesButton

    The button to show all abilities.

  • public Button KnownAbilitiesButton

    The button to show known abilities.

  • public Button KnownAbilityEventsButton

    The button to show known ability events.

Methods

  • public override void OnStarting()

    Subscribes to character and local client events.

  • public override void OnDestroying()

    Unsubscribes from events and clears all ability slots.

  • public override void OnPostSetCharacter()

    Subscribes to ability controller events after the character is set.

  • public override void OnPreUnsetCharacter()

    Unsubscribes from ability controller events and clears all ability slots before the character is unset.

  • public override void OnQuitToLogin()

    Clears all ability slots when quitting to login.

  • public void AddAbility(Ability ability)

    Adds an ability button for the given ability.

  • public void AddKnownAbility(BaseAbilityTemplate template)

    Adds a known ability button for the given ability template.

  • public void AddKnownAbilityEvent(AbilityEvent abilityEvent)

    Adds a known ability event button for the given ability event.

  • public void ClearAllSlots()

    Clears all ability slots from the UI.

  • public void Tab_OnClick(int type)

    Event handler for when an ability tab is clicked. Updates the visible ability entries.


Basic Usage

Setup

  1. Attach UIAbilities to an ability UI GameObject in the Unity Editor.
  2. Assign all required UI fields in the Inspector: AbilityParent, AbilityButtonPrefab, AbilitiesButton, KnownAbilitiesButton, and KnownAbilityEventsButton.
  3. Ensure the character and ability controller systems are available and properly set up.

Example

// Example usage in a MonoBehaviour
public UIAbilities uiAbilities;

void Start() {
    uiAbilities.OnStarting();
}

// To switch tabs
uiAbilities.Tab_OnClick((int)AbilityTabType.KnownAbility);

Best Practices

  • Always assign all UI references in the Inspector to avoid null reference errors.
  • Use event subscriptions in OnStarting/OnDestroying to avoid memory leaks.
  • Keep the UI updated by calling ClearAllSlots() and updating ability lists as needed.
  • Integrate with the character and ability controller for dynamic updates.
⚠️ **GitHub.com Fallback** ⚠️