Yes I have looked, I managed to get somewhere... I created an empty scene and managed to instantiate the slots inside a backpack (just like in the example, a slot has a background and an icon) - everything worked well, slots had colliders attached to them, they acted perfectly like buttons, I also attached a collider to the bag and managed to drag it around using UIDragObject (I had to increase the z of the bag collider to detect the buttons/slots clicks)
But the problem is, when I went over to my project and do EXACTLY the same thing, I got the slots drawn but they did NOT detect input
((( they had colliders attached to them, I tried changing the depth, the z I tried everything, buttons did NOT detect input at all
( any idea why?
I have the InventoryManager as a child to my panel.
Here are my scripts:
1- Here's how I add a new bag to the inventory (which is a child to the panel)
GameObject bagObject = NGUITools.AddChild(gameObject, bagPrefab);
bagObject.transform.parent = _transform;
2- Here's how I'm adding the slots to the bag:
private void PopulateSlots()
{
for (int i = 0; i < nRows; i++)
{
slots
.Add(new List
<Slot
>()); for (int j = 0; j < nCols; j++)
{
GameObject slotObj = NGUITools.AddChild(gameObject, slotTemplate);
Transform slotTrans = slotObj.transform;
float x = -bagWidth + SPACE_BETWEEN_SLOTS * (j + 1) + j * slotSize;
float y = -SPACE_BETWEEN_SLOTS * (i + 1) - i * slotSize - headerPadding;
slotTrans
.localPosition = new Vector3
(x, y, 0f
);
try
{
var slot = slotObj.GetComponent<Slot>();
slot
.Init(new Index2D
(i, j
), slotSize
); slots[i].Add(slot);
}
catch (Exception e)
{
Debug.Log(e.Message);
}
availableIndices.Add(i, j);
}
}
}
This is the Start of the Bag, where I call the previous method, and set the collider right for the bag:
private void Start()
{
bagHeight = nRows * (slotSize) + HEADER_SPACE + (nRows+1) * SPACE_BETWEEN_SLOTS;
bagWidth = nCols * (slotSize) + (nCols+1) * SPACE_BETWEEN_SLOTS;
_collider
.size = new Vector3
(bagWidth, bagHeight,
1); _collider
.center = new Vector3
(_transform
.localPosition.x - bagWidth
/ 2, _transform
.localPosition.y - bagHeight
/ 2, _collider
.center.z); background
.transform.localScale = new Vector3
(bagWidth, bagHeight,
0); PopulateSlots();
}
Here's how I'm setting the colliders for the slots:
void Awake()
{
_collider = GetComponent<BoxCollider>();
background
.transform.localScale = new Vector3
(size, size,
1); icon = null;
_collider
.size = new Vector3
(size, size,
1); _collider
.center = new Vector3
(size
/ 2,
-size
/ 2, _collider
.center.z);}
Any idea what's going on? what am I missing? I'm going nuts, I'd REALLY appreciate any help. Thanks.