IEquippable - jimdroberts/FishMMO GitHub Wiki
Interface for objects that can be equipped and unequipped by an owner of type T. Implement this to allow items or entities to be equipped by a character or other owner.
-
void Equip(T owner)
Equips the object to the specified owner. owner (T): The entity or character equipping this object.
-
void Unequip()
Unequips the object from its current owner.
- Implement IEquippable on your item or entity class.
- Provide logic in the Equip and Unequip methods to handle equipping and unequipping.
- Use the interface to allow characters or other owners to equip or unequip the object.
// Example 1: Implementing IEquippable for a weapon
public class Sword : MonoBehaviour, IEquippable<Player> {
public void Equip(Player owner) {
// Equip logic here
}
public void Unequip() {
// Unequip logic here
}
}
// Example 2: Equipping and unequipping in gameplay
IEquippable<Player> weapon = sword.GetComponent<IEquippable<Player>>();
weapon.Equip(player);
weapon.Unequip();
- Always implement both Equip and Unequip to handle all relevant logic for your equippable object.
- Use the generic type T to restrict which types of owners can equip the object.
- Use IEquippable for all items or entities that should be equippable by players or other entities.