running code on item equip based on an items category?

Mimi

New member
I want to use a case switch to run code based on which equipment slot something is placed in. the point of this is to use with a different asset that has a cosmetic armor system already, so I just want UIS to run that assets functions to visually equip things

I want to make my own script that inherits from the equipper and overrides equip, like the demo equipper script. I don't know the simple/proper way to get an attribute from something that was just equipped based on the slot

C#:
switch ("Item Catagory?")
{
    case "Chest Wear":
        EquipVest(SpriteId)
        break;
       
    case "Arm Wear":
        EquipVest(SpriteId)
        break;
       
    case "Leg Wear":
        EquipLeggings(SpriteId)
        break;

    default:
        break;
}
       
public void EquipVest(string SpriteId)
{
    if (SpriteId == null) UnEquip(EquipmentPart.Vest);
    else Equip(SpriteCollection.Armor.Single(i => i.Id == SpriteId), EquipmentPart.Vest);
}

public void EquipBracers(string SpriteId)
{
    if (SpriteId == null) UnEquip(EquipmentPart.Bracers);
    else Equip(SpriteCollection.Armor.Single(i => i.Id == SpriteId), EquipmentPart.Bracers);
}

public void EquipLeggings(string SpriteId)
{
    if (SpriteId == null) UnEquip(EquipmentPart.Leggings);
    else Equip(SpriteCollection.Armor.Single(i => i.Id == SpriteId), EquipmentPart.Leggings);
}
btw I wrote this code in the code editor here, it's not what I'm using, I did it as an example of what I plan to do hoping to get some help with the way this asset wants me to do what im trying to do!
 
I'm assuming you have read the "DemoCharacterEquipper" script as reference.

Both the Equip and Unequip function pass in an Index as parameter. That index is the slot index.

So Instead of using a switch, I'd recommend making a dictionary of (int, EquipmentPart) where the int is the slot index and the EquipmentPart is the category enum.

In psuedo code it would look like something like this:

Code:
public void EquipVisually(string spriteID, int index){
EquipmentPart equipmentPart = m_SlotEquipmentPartDictionary(index);
if (SpriteId == null) UnEquip(equipmentPart);
    else Equip(SpriteCollection.Armor.Single(i => i.Id == SpriteId), equipmentPart);
}

This way you only have a single function, instead of one for every single equipment part. Plus no switch statement.
This way you keep your code nice and scalable

i hope that helps
 
Top