UIDebuff - jimdroberts/FishMMO GitHub Wiki

Description

A UI control for displaying and managing debuffs in the FishMMO client. Handles the display of active debuffs, updates debuff durations, and responds to debuff-related events from the character and buff controller. Integrates with the UI to show, add, remove, and clear debuffs dynamically.


API Access

Fields

  • public RectTransform DebuffParent

    The parent RectTransform for debuff UI elements.

  • public UIBuffGroup DebuffButtonPrefab

    The prefab used to instantiate debuff buttons/groups.

  • public Dictionary<int, UIBuffGroup> Debuffs

    Dictionary mapping debuff template IDs to their UI group representations.

Methods

  • public override void OnStarting()

    Subscribes to debuff-related events.

  • public override void OnDestroying()

    Unsubscribes from debuff events and clears debuffs.

  • public override void OnPostSetCharacter()

    Invokes base implementation after the character is set.

  • public override void OnPreUnsetCharacter()

    No implementation (reserved for future use).

  • public override void OnQuitToLogin()

    Clears all debuffs when quitting to login.

  • private void BuffController_OnSubtractTime(Buff buff)

    Event handler for subtracting time from a debuff. Updates the duration slider in the UI.

  • private void BuffController_OnAddDebuff(Buff buff)

    Event handler for adding a debuff. Instantiates and initializes the debuff UI group.

  • private void BuffController_OnRemoveDebuff(Buff buff)

    Event handler for removing a debuff. Destroys the debuff UI group.

  • public void ClearAllDebuffs()

    Clears all debuffs from the UI and destroys their GameObjects.


Basic Usage

Setup

  1. Attach UIDebuff to a debuff UI GameObject in the Unity Editor.
  2. Assign the DebuffParent and DebuffButtonPrefab fields in the Inspector.
  3. Integrate with the character and buff controller systems for event-driven updates.

Example

// Example usage in a MonoBehaviour
public UIDebuff debuffUI;

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

// To clear all debuffs
debuffUI.ClearAllDebuffs();

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