UIFriend - jimdroberts/FishMMO GitHub Wiki

Description

A UI entry component that represents a single friend in the player's friend list. Displays the friend's name and online status, stores the friend's character ID, and exposes an action for removing the friend.


API Access

Fields

  • public long FriendID

    The character ID of the friend. Marked NonSerialized and used to identify the friend for actions.

  • public TMP_Text Name

    Text component used to display the friend's name.

  • public TMP_Text Status

    Text component used to display the friend's status (e.g., Online/Offline).

  • public Button Button

    Button component used to trigger friend-related actions (e.g., open profile, send message, remove).

  • public Action OnRemoveFriend

    Event invoked when the remove-friend action is triggered, passing the friend's ID.

Methods

  • public void OnButtonRemoveFriend()

    Invoked by the UI when the remove friend button is clicked. Calls OnRemoveFriend with FriendID if any handlers are registered.


Basic Usage

Setup

  1. Add the UIFriend component to a friend list row prefab.
  2. Assign the Name and Status TMP_Text references in the inspector.
  3. Assign the Button reference and wire its OnClick to OnButtonRemoveFriend.
  4. When instantiating, set FriendID and populate Name.text and Status.text.
  5. Subscribe to OnRemoveFriend to handle removal logic (e.g., show confirmation and call server API).

Example

// Creating and wiring a friend entry
var entry = Instantiate(friendEntryPrefab, parentTransform).GetComponent<UIFriend>();
entry.FriendID = friendId;
entry.Name.text = friendName;
entry.Status.text = isOnline ? "Online" : "Offline";
entry.OnRemoveFriend += id => {
    // Confirm and request removal
    FriendService.RemoveFriend(id);
};

Best Practices

  • Use a pooled system for friend list entries to avoid frequent allocations when the list changes.
  • Keep UI update logic minimal; update only values that changed to improve performance for large friend lists.
  • Validate FriendID before invoking server-side removal APIs.
  • Localize status text strings if your game supports multiple languages.
⚠️ **GitHub.com Fallback** ⚠️