using UnityEngine; using System.Collections; using System.Collections.Generic; namespace Invector.vItemManager { public class vEquipAreaControl : MonoBehaviour { [HideInInspector] public List equipAreas; void Start() { equipAreas = GetComponentsInChildren().vToList(); foreach (vEquipArea area in equipAreas) area.onPickUpItemCallBack = OnPickUpItemCallBack; vInventory inventory = GetComponentInParent(); if (inventory) inventory.onOpenCloseInventory.AddListener(OnOpen); } /// /// Event called when inventory open or close /// /// is open public virtual void OnOpen(bool value) { } /// /// Event called when an area pick up an item /// /// target area /// target slot public virtual void OnPickUpItemCallBack(vEquipArea area, vItemSlot slot) { for (int i = 0; i < equipAreas.Count; i++) { var sameSlots = equipAreas[i].equipSlots.FindAll(slotInArea =>slotInArea!=slot && slotInArea.item != null && slotInArea.item == slot.item); for (int a = 0; a < sameSlots.Count; a++) { equipAreas[i].UnequipItem(sameSlots[a]); } } CheckTwoHandItem(area, slot); } void CheckTwoHandItem(vEquipArea area, vItemSlot slot) { if (slot.item == null) return; var opposite = equipAreas.Find(_area => _area != null && area.equipPointName.Equals("LeftArm") && _area.currentEquippedItem != null); //var RightEquipmentController = changeEquipmentControllers.Find(equipCtrl => equipCtrl.equipArea != null && equipCtrl.equipArea.equipPointName.Equals("RightArm")); if (area.equipPointName.Equals("LeftArm")) opposite = equipAreas.Find(_area => _area != null && area.equipPointName.Equals("RightArm") && _area.currentEquippedItem != null); else if (!area.equipPointName.Equals("RightArm")) { return; } if (opposite != null && (slot.item.twoHandWeapon || opposite.currentEquippedItem.twoHandWeapon)) { opposite.onUnequipItem.Invoke(opposite, slot.item); opposite.UnequipItem(slot as vEquipSlot); } } } }