Implementing a Guild System in Atavism with Unity: Part III
In this part of the series, we’ll focus on developing a core script in Unity to manage Guild data on the client side. This script will be responsible for storing player’s guild information and handling interactions with the server, such as sending messages or receiving updates about guild activities.
Prerequisites:
- Completion of Part II of this tutorial series.
- Ability to edit C# scripts in your Unity project.
Step 1: Creating the AtavismGuild C# Script
- Create a New C# Script in Unity: Ideally, place this in the
AtavismObjects/Scripts
folder. - Initial Setup:
- Include necessary namespaces, e.g.,
using System.Collections.Generic;
. - Remove the
Update()
function to enhance performance. - Define the following class variables:
string guildName;
int factionID;
List<AtavismGuildRank> ranks;
List<AtavismGuildMember> members;
string motd;
string omotd;
- Implement Property Getters for each variable to ensure controlled access.
- Include necessary namespaces, e.g.,
Step 2: Creating Member and Rank Classes
Within the AtavismGuild
script, define two additional classes:
- AtavismGuildMember Class:
- Contains member details such as OID, name, rank, level, zone, note, and status.
- AtavismGuildRank Class:
- Holds information on guild rank level, name, and permissions.
These classes correspond to their AGIS counterparts, with the omission of the ID attribute as it’s not required client-side.
Step 3: Establishing a Static Instance Variable
To ensure a single, accessible instance of AtavismGuild
, implement a static instance variable:
- Declare the Static Variable:
static AtavismGuild instance;
- Initialize in Start() Function:
instance = this;
- Property Getter for Instance Access:
public static AtavismGuild Instance {
get {
return instance;
}
}
This enables other scripts, such as Guild UI scripts, to easily access the running instance of
AtavismGuild
.
Step 4: Integrating the Script with the Scripts Prefab
Add the AtavismGuild
script as a component to the Scripts prefab located in the AtavismObjects
folder. This integration ensures that the script is loaded along with other components in the Scripts prefab when the Login scene starts.
By completing these steps, you’ve successfully set up the basic structure of the AtavismGuild
class in your Unity project. This script forms the foundation for managing guild-related data and interactions on the client side. The subsequent parts of this tutorial will expand on this foundation, introducing more complex functionalities and interactions.