UIFriend - jimdroberts/FishMMO GitHub Wiki
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.
-
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.
-
public void OnButtonRemoveFriend()
Invoked by the UI when the remove friend button is clicked. Calls
OnRemoveFriend
withFriendID
if any handlers are registered.
- Add the
UIFriend
component to a friend list row prefab. - Assign the
Name
andStatus
TMP_Text references in the inspector. - Assign the
Button
reference and wire its OnClick toOnButtonRemoveFriend
. - When instantiating, set
FriendID
and populateName.text
andStatus.text
. - Subscribe to
OnRemoveFriend
to handle removal logic (e.g., show confirmation and call server API).
// 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);
};
- 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.