Hey,
so yesterday everything worked and today…
So here is my Problem:
class1 is there to detect if an itemslot is clicked
public class ItemSlotBehaviour : MonoBehaviour, IPointerClickHandler
{
public event Action<Item> OnShiftLeftClickEvent;
public void OnPointerClick(PointerEventData eventData)
{
if(eventData != null && eventData.button == PointerEventData.InputButton.Left)// && Input.GetKey(KeyCode.LeftControl))
{
Debug.Log(OnShiftLeftClickEvent);
if (Item !=null && OnShiftLeftClickEvent != null)
{
Debug.Log("ItemSLot.PointerClick");
OnShiftLeftClickEvent(Item);
}
}
}
the second class just know about the slots and is an intermediate for the action:
public class StashBehaviour : MonoBehaviour
{
//[SerializeField] List<Item> items = new List<Item>();
public List<Item> items = new List<Item>();
[SerializeField] Transform itemSlotsParent;
[SerializeField] ItemSlotBehaviour[] itemSlots;
public event Action<Item> OnItemInStashShiftClickedEvent;
private void Awake()
{
foreach(ItemSlotBehaviour isb in itemSlots)
{
//Debug.Log(isb.name);
isb.OnShiftLeftClickEvent += OnItemInStashShiftClickedEvent;
isb.OnShiftLeftClickEvent += TestAction;
}
}
public void TestAction(Item item)
{
Debug.Log(this.name + item);
}
So far everything works, TestAction(item) is executed just fine, tells me the item etc and Debug.Log(OnShiftLeftClickEvent); from the first class tells me there is indeed an action
The third class now should do something
public class InventoryBehaviour : MonoBehaviour
{
[SerializeField] EquipmentBehaviour equipment;
[SerializeField] StashBehaviour stash;
private void Awake()
{
stash.OnItemInStashShiftClickedEvent += EquipFromStash;
equipment.OnEquipmentShiftClickedEvent += UnequipFromEquipment;
stash.OnItemInStashShiftClickedEvent += TestAction;
stash.TestAction(stash.items[0]);
}
public void TestAction(Item item)
{
Debug.Log(this.name + item);
}
And here for some reason i cannot add a function to the second class’s action, i.e. stash.OnItemInStashShiftClickedEvent += TestAction; does not add the function. If i remove TestAction from the second class (stashbehave) the first debuglog correctly tells me that the action is null. However i can execute stash.TestAction(stash.items[0]); just fine, which tells me that stash is correctly set and, thus, the action should be correctly applied.
Also stash.OnItemInStashShiftClickedEvent += TestAction; does not show any error and it is all the same as for StashBehaviour… I can not see where things do not work.
thanks in advance