UIAchievements - jimdroberts/FishMMO GitHub Wiki

Description

A UI control for displaying and managing achievements in the FishMMO client. Handles the display of achievement categories and descriptions, updates progress, and allows switching between categories. Integrates with the character and achievement controller to update the UI in response to game events.


API Access

Fields

  • public AchievementCategory CurrentCategory

    The currently selected achievement category.

  • public RectTransform AchievementCategoryParent

    The parent RectTransform for achievement category buttons.

  • public UIAchievementCategory AchievementCategoryButtonPrefab

    The prefab used to instantiate achievement category buttons.

  • public RectTransform AchievementDescriptionParent

    The parent RectTransform for achievement description UI elements.

  • public UIAchievementDescription AchievementDescriptionPrefab

    The prefab used to instantiate achievement description UI elements.

Methods

  • public override void OnStarting()

    Subscribes to character and local client events.

  • public override void OnDestroying()

    Unsubscribes from events and clears all achievement UI.

  • public override void OnPostSetCharacter()

    Subscribes to achievement update events after the character is set.

  • public override void OnPreUnsetCharacter()

    Unsubscribes from achievement update events before the character is unset.

  • public override void OnQuitToLogin()

    Clears all achievement UI when quitting to login.

  • public void AchievementController_OnUpdateAchievement(ICharacter character, Achievement achievement)

    Instantiates or updates achievement UI elements when an achievement is updated.

  • public void ClearAll()

    Clears all achievement UI elements and listeners.

  • public void Category_OnClick(AchievementCategory type)

    Event handler for when an achievement category is clicked. Updates the visible achievements.


Basic Usage

Setup

  1. Attach UIAchievements to an achievements UI GameObject in the Unity Editor.
  2. Assign all required UI fields in the Inspector: AchievementCategoryParent, AchievementCategoryButtonPrefab, AchievementDescriptionParent, and AchievementDescriptionPrefab.
  3. Ensure the character and achievement controller systems are available and properly set up.

Example

// Example usage in a MonoBehaviour
public UIAchievements uiAchievements;

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

// To update achievements
uiAchievements.AchievementController_OnUpdateAchievement(character, achievement);

// To switch categories
uiAchievements.Category_OnClick(AchievementCategory.Combat);

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 ClearAll() and updating achievement lists as needed.
  • Integrate with the character and achievement controller for dynamic updates.
⚠️ **GitHub.com Fallback** ⚠️