UIGuild - jimdroberts/FishMMO GitHub Wiki

Description

UI control for managing guild UI: displays the guild name, instantiates and updates guild member entries, handles invites, creation, leaving, and receives guild-related results and invites.


API Access

Fields

  • public TMP_Text GuildLabel

    Text label that displays the current guild name.

  • public RectTransform GuildMemberParent

    Parent transform used to instantiate guild member UI entries.

  • public UIGuildMember GuildMemberPrefab

    Prefab used to create UIGuildMember instances.

  • public Dictionary<long, UIGuildMember> Members

    Mapping of member character ID -> instantiated UIGuildMember entry maintained by this control.

Methods

  • public override void OnDestroying()

    Handles cleanup when the UI is destroyed by invoking guild leave handling to clear members and label.

  • public override void OnPostSetCharacter()

    Subscribes to IGuildController events for receiving invites, adding/removing members, validating members, leaving guild, and receiving guild results.

  • public override void OnPreUnsetCharacter()

    Unsubscribes from IGuildController events when the character is being unset.

  • public void GuildController_OnReceiveGuildInvite(long inviterCharacterID)

    Shows a dialog asking the player to accept or decline a guild invite. Sends GuildAcceptInviteBroadcast or GuildDeclineInviteBroadcast based on choice.

  • public void GuildController_OnAddGuildMember(long characterID, long guildID, GuildRank rank, string location)

    Adds a guild member UI element and updates the guild label using the guild name resolved asynchronously.

  • public void GuildController_OnValidateGuildMembers(HashSet newMembers)

    Validates current members and removes any entries not included in the provided set.

  • public void GuildController_OnLeaveGuild()

    Clears guild label and destroys all member UI entries.

  • public void GuildController_OnAddMember(long characterID, GuildRank rank, string location)

    Creates or updates an individual guild member UI entry, resolves the member name asynchronously, and sets rank and location fields.

  • public void GuildController_OnRemoveMember(long characterID)

    Removes and destroys the UI entry for the specified member if present.

  • public void GuildController_OnReceiveGuildResult(GuildResultType result)

    Displays result messages in UIChat for various guild operation outcomes (invalid name, name exists, already in guild).

  • public void OnButtonCreateGuild()

    Opens an input dialog to create a guild and broadcasts a GuildCreateBroadcast if the name is valid.

  • public void OnButtonLeaveGuild()

    Opens a confirmation dialog to leave the guild and broadcasts GuildLeaveBroadcast when confirmed.

  • public void OnButtonInviteToGuild()

    Invites a target or prompts for a name and sends a GuildInviteBroadcast for the target character ID.


Basic Usage

Setup

  1. Attach UIGuild to a UI GameObject under a Canvas.
  2. Assign GuildLabel to the text field showing the guild name.
  3. Assign GuildMemberParent to a RectTransform container (use layout groups for automatic layout).
  4. Assign GuildMemberPrefab to a UIGuildMember prefab exposing Name, Rank and Location.
  5. Ensure IPlayerCharacter and its IGuildController are available so the control can subscribe to guild events.

Example

var uiGuild = GetComponent<UIGuild>();
uiGuild.GuildMemberPrefab = guildMemberPrefab;
uiGuild.GuildMemberParent = guildMemberListParent;
// UIGuild will respond to guild controller events and update UI accordingly.

Best Practices

  • Use layout components on GuildMemberParent to keep member entries arranged and sized consistently.
  • Pool UIGuildMember instances if guild rosters change frequently to minimize allocations.
  • Keep callbacks for name resolution lightweight and avoid heavy processing in those closures.
  • Validate guild names and show clear feedback in UIChat when operations fail.
  • Unsubscribe from controller events on pre-unset to avoid memory leaks and unexpected callbacks.
⚠️ **GitHub.com Fallback** ⚠️