Hello, I am working on Inventory system. Now I implemented Equipment window and added “right click to wear” method. Everything works fine BUT! Only if Equipment panel is visible. When panel is not visible (.SetActive(false)
) My method doesn’t work. Now question. It is possible to edit variables in not active UI components? Or I have to rewrite my system to .alpha = 0f/1f
instead?
Thanks!!
Code of method:
public void WearItem(ContainerSlot from, CharacterEquipmentSlot to)
{
if(from != null && to != null)
{
if(from.Container.containerItems[from.id].ItemType == to.equipmentPart ||
((from.Container.containerItems[from.id].ItemType == ItemType.ONEHAND_WEAPON || from.Container.containerItems[from.id].ItemType == ItemType.TWOHAND_WEAPON)) && to.equipmentPart == ItemType.WEAPON)
{
if(from.Container.containerItems[from.id].ItemType == ItemType.TWOHAND_WEAPON)
{
CharacterEquipmentSlot shield = Array.Find(FindObjectsOfType<CharacterEquipmentSlot>(), slot => (slot.equipmentPart == ItemType.SHIELD));
if(shield.Item.ItemType == ItemType.NULL)
{
from.Container.containerItems[from.id] = to.Item;
to.Item = draggingItem;
characterEquipment.RecalculateStats();
this.HideToolTip();
}
else
{
from.Container.containerItems[from.id] = to.Item;
to.Item = draggingItem;
from.Container.AddItemToContainer(shield.Item.ItemId,1);
shield.Item = new Item();
characterEquipment.RecalculateStats();
this.HideToolTip();
}
}
else if (from.Container.containerItems[from.id].ItemType == ItemType.SHIELD)
{
CharacterEquipmentSlot mainHand = Array.Find(FindObjectsOfType<CharacterEquipmentSlot>(), slot => (slot.equipmentPart == ItemType.WEAPON));
if(mainHand.Item.ItemType == ItemType.NULL || mainHand.Item.ItemType == ItemType.ONEHAND_WEAPON)
{
from.Container.containerItems[from.id] = to.Item;
to.Item = draggingItem;
characterEquipment.RecalculateStats();
this.HideToolTip();
}
else
{
from.Container.containerItems[from.id] = to.Item;
to.Item = draggingItem;
from.Container.AddItemToContainer(mainHand.Item.ItemId,1);
mainHand.Item = new Item();
characterEquipment.RecalculateStats();
this.HideToolTip();
}
}
else
{
from.Container.containerItems[from.id] = to.Item;
to.Item = draggingItem;
characterEquipment.RecalculateStats();
this.HideToolTip();
}
}
}
else if (from != null && to == null)
{
CharacterEquipmentSlot eqSlot;
if(from.Container.containerItems[from.id].ItemType == ItemType.ONEHAND_WEAPON || from.Container.containerItems[from.id].ItemType == ItemType.TWOHAND_WEAPON)
{
eqSlot = Array.Find(FindObjectsOfType<CharacterEquipmentSlot>(), slot => (slot.equipmentPart == ItemType.WEAPON));
}
else
{
eqSlot = Array.Find(FindObjectsOfType<CharacterEquipmentSlot>(), slot => (slot.equipmentPart == from.Container.containerItems[from.id].ItemType));
}
this.WearItem(from, eqSlot);
return;
}
}
As you can see I need to get refference to CharacterEquipmentSlot “on the fly” cus “right click” on item runs that method with second parametr == null.