UIBuff - jimdroberts/FishMMO GitHub Wiki
A UI control for displaying and managing buffs in the FishMMO client. Handles the display of active buffs, updates buff durations, and responds to buff-related events from the character and buff controller. Integrates with the UI to show, add, remove, and clear buffs dynamically.
-
public RectTransform BuffParent
The parent RectTransform for buff UI elements.
-
public UIBuffGroup BuffButtonPrefab
The prefab used to instantiate buff buttons/groups.
-
public Dictionary<int, UIBuffGroup> Buffs
Dictionary mapping buff template IDs to their UI group representations.
-
public override void OnStarting()
Subscribes to buff-related events.
-
public override void OnDestroying()
Unsubscribes from buff events and clears buffs.
-
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 buffs when quitting to login.
-
private void BuffController_OnSubtractTime(Buff buff)
Event handler for subtracting time from a buff. Updates the duration slider in the UI.
-
private void BuffController_OnAddBuff(Buff buff)
Event handler for adding a buff. Instantiates and initializes the buff UI group.
-
private void BuffController_OnRemoveBuff(Buff buff)
Event handler for removing a buff. Destroys the buff UI group.
-
public void ClearAllBuffs()
Clears all buffs from the UI and destroys their GameObjects.
-
public void Buff_OnLeftClick(int index, object[] optionalParams)
Event handler for left-clicking a buff. Used for debugging or removing buffs.
- Attach
UIBuff
to a buff UI GameObject in the Unity Editor. - Assign the
BuffParent
andBuffButtonPrefab
fields in the Inspector. - Integrate with the character and buff controller systems for event-driven updates.
// Example usage in a MonoBehaviour
public UIBuff buffUI;
void Start() {
buffUI.OnStarting();
}
// To clear all buffs
buffUI.ClearAllBuffs();
- 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
ClearAllBuffs()
and updating buff lists as needed. - Integrate with the buff controller for dynamic updates.