Implementing a Guild System in Atavism with Unity: Part V
In this final part of the series, we focus on building the User Interface (UI) for the Guild system in Atavism and implementing the remaining guild commands.
Prerequisites:
- Completion of Part IV of the series.
- Ability to edit C# scripts in Unity.
- Basic Unity skills (creating GameObjects, modifying Inspector values, etc.).
Step 1: Designing the User Interface
Before coding or UI creation, you should have a clear design idea. The main Guild UI panel might include:
- Guild Name.
- Message of the Day (MOTD).
- A list of Guild Members (with details like name, rank, level).
- Buttons for various actions (invite members, edit ranks, etc.).
- A scrollbar for the member list.
Create a mockup drawing to visualize the UI layout.
Step 2: Building the Guild Window using Unity’s UI (UGUI)
- Creating the Panel: In Unity, create a new UI Panel under the Canvas object. Name it
GuildPanel
. Resize and anchor it to your preferred location, e.g., left side of the screen. - Setting Up the Title Bar: Add a
TitlePanel
prefab to display the guild name and a close button. - Message of the Day Section: Create a
MotdPanel
for displaying the guild’s MOTD. Include a Text object to dynamically display the message. - Member List Headers: Add a
HeaderPanel
above the member list for headers like ‘Name’, ‘Rank’, and ‘Level’. - Creating the Member List: Implement a scrollable member list using Unity’s Scroll Rect and Mask components. Include a grid layout inside the
MemberList
panel. - Scrollbar: Add a scrollbar to the side of the
MemberList
to allow scrolling through the member list. - Action Buttons Panel: Create a
ButtonsPanel
at the bottom with buttons for actions like adding members or accessing guild settings.
Step 3: Creating the GuildMemberEntry Prefab and Script
- GuildMemberEntry Prefab: Create a
GuildMemberEntry
prefab that will represent each member in the member list. It should include Text objects for the member’s name, rank, and level. - GuildMemberEntry Script: Write a script (
UGUIGuildMemberEntry.cs
) for this prefab. The script should include public Text variables for each member attribute and a method to set these details (SetGuildMemberDetails
).
Step 4: Creating the Guild Panel Script
- GuildPanel Script: Create a new C# script (
UGUIGuildPanel.cs
). This script will manage the Guild Panel’s overall functionality. - Implementing UIList: Make the
UGUIGuildPanel
script inherit fromUIList
and implement required methods likeNumberOfCells
andUpdateCell
. - Additional Functions: Include functions for updating guild details, handling UI events, showing/hiding the panel, and toggling visibility.
- Handling Key Presses: Add a public KeyCode variable to handle toggling the guild panel visibility with a keyboard shortcut.
- Adding to Unity: Attach this script to the
GuildPanel
GameObject and set up the necessary references (e.g., title bar, MOTD text field).
Step 5: Inviting Members to the Guild
- Invite Request Functionality: Implement a function in
UGUIGuildPanel
to handle the invite member action. It should send an invite request to the server with the targeted player’s OID or name. - Handling Server Invite: On the server side, update the
GuildCommandHook
to process invite commands. Create a method inGuild.java
(inviteNewMember
) to handle the invitation logic. - Client-side Invite Handling: In Unity, write a message handler (
HandleGuildInvite
) inAtavismGuild
to display a confirmation box when an invite is received. - Response Handling on the Server: Implement the
GuildInviteResponseHook
on the server to process the player’s response to the invitation.
By following these steps, you’ll have a functional guild system in Atavism with a comprehensive UI for guild management. This system allows players to create guilds, manage members, and handle invitations seamlessly.