public void EquipOnSlot(BodyPart bodyPart, ScriptableEquipment equipment) { switch (bodyPart) { case BodyPart.Hair: hair = null; hair = new Slot(equipment); break; case BodyPart.Head: head = null; head = new Slot(equipment); break; case BodyPart.Torso: torso = null; torso = new Slot(equipment); break; case BodyPart.ArmUpperRight: rightUpperArm = null; rightUpperArm = new Slot(equipment); break; case BodyPart.ArmLowerRight: rightLowerArm = null; rightLowerArm = new Slot(equipment); break; case BodyPart.RightHand: rightHand = null; rightHand = new Slot(equipment); break; case BodyPart.ArmUpperLeft: leftUpperArm = null; leftUpperArm = new Slot(equipment); break; case BodyPart.ArmLowerLeft: leftLowerArm = null; leftLowerArm = new Slot(equipment); break; case BodyPart.LeftHand: leftHand = null; leftHand = new Slot(equipment); break; case BodyPart.Hips: hips = null; hips = new Slot(equipment); break; case BodyPart.RightLeg: rightLeg = null; rightLeg = new Slot(equipment); break; case BodyPart.LeftLeg: leftLeg = null; leftLeg = new Slot(equipment); break; case BodyPart.RightHandWeapon: rightWeapon = null; rightWeapon = new Slot(equipment); break; default: break; } }
private void LoadSlots(SaveableSlot[] savedSlots) { hair = null; head = null; torso = null; leftUpperArm = null; leftLowerArm = null; leftHand = null; rightUpperArm = null; rightLowerArm = null; rightHand = null; hips = null; leftLeg = null; rightLeg = null; leftWeapon = null; rightWeapon = null; // We need to access the character's inventory so we can access each instance of each equipped item CharacterInventory characterInventory = this.gameObject.GetComponent <CharacterInventory>(); if (characterInventory == null) { Debug.LogError("No character inventory found. Were you trying to load slots on the wrong character?"); } // Hair string hairEquipment = savedSlots.Where(x => x.slotKey == "hair").First().currentEquipment; if (!string.IsNullOrEmpty(hairEquipment)) { ScriptableEquipment hairEquipmentInstance = characterInventory.FindByItemName(hairEquipment) as ScriptableEquipment; if (hairEquipment != null) { hair = new Slot(hairEquipmentInstance); hair.equipment.Equip(this.gameObject); } } // Head string headEquipment = savedSlots.Where(x => x.slotKey == "head").First().currentEquipment; if (!string.IsNullOrEmpty(headEquipment)) { ScriptableEquipment headEquipmentInstance = characterInventory.FindByItemName(headEquipment) as ScriptableEquipment; if (headEquipment != null) { head = new Slot(headEquipmentInstance); head.equipment.Equip(this.gameObject); } } // Torso string torsoEquipment = savedSlots.Where(x => x.slotKey == "torso").First().currentEquipment; if (!string.IsNullOrEmpty(torsoEquipment)) { ScriptableEquipment torsoEquipmentInstance = characterInventory.FindByItemName(torsoEquipment) as ScriptableEquipment; if (torsoEquipment != null) { torso = new Slot(torsoEquipmentInstance); torso.equipment.Equip(this.gameObject); } } // Left Upper Arm string leftUpperArmEquipment = savedSlots.Where(x => x.slotKey == "leftUpperArm").First().currentEquipment; if (!string.IsNullOrEmpty(leftUpperArmEquipment)) { ScriptableEquipment leftUpperArmEquipmentInstance = characterInventory.FindByItemName(leftUpperArmEquipment) as ScriptableEquipment; if (leftUpperArmEquipmentInstance != null) { leftUpperArm = new Slot(leftUpperArmEquipmentInstance); leftUpperArm.equipment.Equip(this.gameObject); } } // Left Lower Arm string leftLowerArmEquipment = savedSlots.Where(x => x.slotKey == "leftLowerArm").First().currentEquipment; if (!string.IsNullOrEmpty(leftLowerArmEquipment)) { ScriptableEquipment leftLowerArmEquipmentInstance = characterInventory.FindByItemName(leftLowerArmEquipment) as ScriptableEquipment; if (leftLowerArmEquipmentInstance != null) { leftLowerArm = new Slot(leftLowerArmEquipmentInstance); leftLowerArm.equipment.Equip(this.gameObject); } } // Left Hand string leftHandEquipment = savedSlots.Where(x => x.slotKey == "leftHand").First().currentEquipment; if (!string.IsNullOrEmpty(leftHandEquipment)) { ScriptableEquipment leftHandEquipmentInstance = characterInventory.FindByItemName(leftHandEquipment) as ScriptableEquipment; if (leftHandEquipmentInstance != null) { leftHand = new Slot(leftHandEquipmentInstance); leftHand.equipment.Equip(this.gameObject); } } // Right Upper Arm string rightUpperArmEquipment = savedSlots.Where(x => x.slotKey == "rightUpperArm").First().currentEquipment; if (!string.IsNullOrEmpty(rightUpperArmEquipment)) { ScriptableEquipment rightUpperArmEquipmentInstance = characterInventory.FindByItemName(rightUpperArmEquipment) as ScriptableEquipment; if (rightUpperArmEquipmentInstance != null) { rightUpperArm = new Slot(rightUpperArmEquipmentInstance); rightUpperArm.equipment.Equip(this.gameObject); } } // Right Lower Arm string rightLowerArmEquipment = savedSlots.Where(x => x.slotKey == "rightLowerArm").First().currentEquipment; if (!string.IsNullOrEmpty(rightLowerArmEquipment)) { ScriptableEquipment rightLowerArmEquipmentInstance = characterInventory.FindByItemName(rightLowerArmEquipment) as ScriptableEquipment; if (rightLowerArmEquipmentInstance != null) { rightLowerArm = new Slot(rightLowerArmEquipmentInstance); rightLowerArm.equipment.Equip(this.gameObject); } } // Right Hand string rightHandEquipment = savedSlots.Where(x => x.slotKey == "rightHand").First().currentEquipment; if (!string.IsNullOrEmpty(rightHandEquipment)) { ScriptableEquipment rightHandEquipmentInstance = characterInventory.FindByItemName(rightHandEquipment) as ScriptableEquipment; if (rightHandEquipmentInstance != null) { rightHand = new Slot(rightHandEquipmentInstance); rightHand.equipment.Equip(this.gameObject); } } // Hips string hipsEquipment = savedSlots.Where(x => x.slotKey == "hips").First().currentEquipment; if (!string.IsNullOrEmpty(hipsEquipment)) { ScriptableEquipment hipsEquipmentInstance = characterInventory.FindByItemName(hipsEquipment) as ScriptableEquipment; if (hipsEquipmentInstance != null) { hips = new Slot(hipsEquipmentInstance); hips.equipment.Equip(this.gameObject); } } // Left Leg string leftLegEquipment = savedSlots.Where(x => x.slotKey == "leftLeg").First().currentEquipment; if (!string.IsNullOrEmpty(leftLegEquipment)) { ScriptableEquipment leftLegEquipmentInstance = characterInventory.FindByItemName(leftLegEquipment) as ScriptableEquipment; if (leftLegEquipmentInstance != null) { leftLeg = new Slot(leftLegEquipmentInstance); leftLeg.equipment.Equip(this.gameObject); } } // Right Leg string rightLegEquipment = savedSlots.Where(x => x.slotKey == "rightLeg").First().currentEquipment; if (!string.IsNullOrEmpty(rightLegEquipment)) { ScriptableEquipment rightLegEquipmentInstance = characterInventory.FindByItemName(rightLegEquipment) as ScriptableEquipment; if (rightLegEquipmentInstance != null) { rightLeg = new Slot(rightLegEquipmentInstance); rightLeg.equipment.Equip(this.gameObject); } } // Left Weapon string leftWeaponEquipment = savedSlots.Where(x => x.slotKey == "leftWeapon").First().currentEquipment; if (!string.IsNullOrEmpty(leftWeaponEquipment)) { ScriptableEquipment leftWeaponEquipmentInstance = characterInventory.FindByItemName(leftWeaponEquipment) as ScriptableEquipment; if (leftWeaponEquipmentInstance != null) { leftWeapon = new Slot(leftWeaponEquipmentInstance); leftWeapon.equipment.Equip(this.gameObject); } } // Right Weapon string rightWeaponEquipment = savedSlots.Where(x => x.slotKey == "rightWeapon").First().currentEquipment; if (!string.IsNullOrEmpty(rightWeaponEquipment)) { ScriptableEquipment rightWeaponEquipmentInstance = characterInventory.FindByItemName(rightWeaponEquipment) as ScriptableEquipment; if (rightWeaponEquipmentInstance != null) { rightWeapon = new Slot(rightWeaponEquipmentInstance); rightWeapon.equipment.Equip(this.gameObject); } } }