UIGuild - jimdroberts/FishMMO GitHub Wiki
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.
-
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.
-
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
orGuildDeclineInviteBroadcast
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.
- Attach
UIGuild
to a UI GameObject under a Canvas. - Assign
GuildLabel
to the text field showing the guild name. - Assign
GuildMemberParent
to a RectTransform container (use layout groups for automatic layout). - Assign
GuildMemberPrefab
to aUIGuildMember
prefab exposing Name, Rank and Location. - Ensure
IPlayerCharacter
and itsIGuildController
are available so the control can subscribe to guild events.
var uiGuild = GetComponent<UIGuild>();
uiGuild.GuildMemberPrefab = guildMemberPrefab;
uiGuild.GuildMemberParent = guildMemberListParent;
// UIGuild will respond to guild controller events and update UI accordingly.
- 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.