UICastBar - jimdroberts/FishMMO GitHub Wiki

Description

A UI control for displaying a cast bar in the FishMMO client. Shows the progress of ability casting with a slider and label, and updates or hides itself in response to ability controller events.


API Access

Fields

  • public Slider slider

    The slider UI element representing the cast progress.

  • public TMP_Text castText

    The text UI element displaying the cast label.

Methods

  • public override void OnPostSetCharacter()

    Subscribes to ability controller events after the character is set.

  • public override void OnPreUnsetCharacter()

    Unsubscribes from ability controller events and hides the cast bar before the character is unset.

  • public void OnUpdate(string label, float remainingTime, float totalTime)

    Event handler for ability update. Updates the cast bar UI based on remaining and total time. Hides the cast bar if the cast is finished.

  • public void OnCancel()

    Event handler for ability cancel. Hides the cast bar.


Basic Usage

Setup

  1. Attach UICastBar to a cast bar UI GameObject in the Unity Editor.
  2. Assign the slider and castText fields in the Inspector.
  3. Integrate with the character and ability controller systems for event-driven updates.

Example

// Example usage in a MonoBehaviour
public UICastBar castBar;

void Start() {
    // Set up the cast bar as needed
}

// To update the cast bar
castBar.OnUpdate("Casting Fireball", 1.5f, 3.0f);

// To cancel the cast
castBar.OnCancel();

Best Practices

  • Always assign the slider and castText in the Inspector to avoid null reference errors.
  • Use event subscriptions in OnPostSetCharacter/OnPreUnsetCharacter to avoid memory leaks.
  • Hide the cast bar when casting is finished or canceled for a clean UI.
  • Update the slider value smoothly to reflect cast progress.
⚠️ **GitHub.com Fallback** ⚠️