IEquippable - jimdroberts/FishMMO GitHub Wiki

Description

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.


API Access

Methods

  • 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.


Basic Usage

Setup

  1. Implement IEquippable on your item or entity class.
  2. Provide logic in the Equip and Unequip methods to handle equipping and unequipping.
  3. Use the interface to allow characters or other owners to equip or unequip the object.

Example

// 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();

Best Practices

  • 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.
⚠️ **GitHub.com Fallback** ⚠️