UIEquipment - jimdroberts/FishMMO GitHub Wiki

Description

A UI control for managing and displaying player equipment and attributes in the FishMMO client. Handles equipment slot buttons, attribute labels, and integrates with the character, equipment, and attribute controllers. Supports dynamic updates, category grouping, and 3D equipment view camera toggling.


API Access

Fields

  • private Camera equipmentViewCamera

    Camera used for equipment view (e.g., 3D preview).

  • public RectTransform content

    The parent RectTransform for equipment UI elements.

  • public TMP_Text UILabel

    The label prefab for attribute categories and attributes.

  • public UIAttribute AttributeLabelPrefab

    Prefab used to instantiate attribute labels.

  • public List buttons

    List of equipment slot buttons.

  • public List<TMP_Text> attributeCategoryLabels

    List of category labels for attributes (e.g., Resource, Damage).

  • public Dictionary<long, UIAttribute> attributeLabels

    Dictionary of attribute labels by attribute template ID.

Methods

  • public override void OnStarting()

    Initializes equipment buttons and their slot references.

  • public override void OnDestroying()

    Cleans up camera and attribute labels.

  • public override void ToggleVisibility()

    Toggles the visibility of the equipment UI and associated camera.

  • public override void Show()

    Shows the equipment UI and associated camera.

  • public override void Hide()

    Hides the equipment UI and associated camera.

  • private void DestroyAttributes()

    Destroys all attribute labels and category labels in the UI.

  • public override void OnPreSetCharacter()

    Unsubscribes from equipment slot updates before setting the character reference.

  • public override void OnPostSetCharacter()

    Initializes equipment buttons and attribute labels after setting the character reference.

  • private void AddCharacterAttributeLabel(CharacterAttribute attribute)

    Adds a UI label for a character attribute and subscribes to updates.

  • private void SetButtonSlot(IEquipmentController container, UIEquipmentButton button)

    Sets the equipment button slot display based on the item in the container.

  • public void OnEquipmentSlotUpdated(IItemContainer container, Item item, int equipmentSlot)

    Callback for when an equipment slot is updated. Refreshes the corresponding button display.

  • public void OnAttributeUpdated(CharacterAttribute attribute)

    Callback for when an attribute is updated. Refreshes the corresponding attribute label.

  • public void SetEquipmentViewCamera(Camera camera)

    Sets the camera used for equipment view (e.g., 3D preview).


Basic Usage

Setup

  1. Attach UIEquipment to an equipment UI GameObject in the Unity Editor.
  2. Assign all required UI fields in the Inspector: content, UILabel, AttributeLabelPrefab, and equipment buttons.
  3. Integrate with the character, equipment, and attribute controllers for dynamic updates.
  4. Optionally, set a camera for 3D equipment preview.

Example

// Example usage in a MonoBehaviour
public UIEquipment equipmentUI;

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

// To update an equipment slot
equipmentUI.OnEquipmentSlotUpdated(container, item, slotIndex);

// To update an attribute
equipmentUI.OnAttributeUpdated(attribute);

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.
  • Group attributes by category for better readability.
  • Integrate with the character and equipment controllers for real-time updates.
  • Use the camera toggle methods for 3D equipment previews if needed.
⚠️ **GitHub.com Fallback** ⚠️