public void InitSlots() { //SET SIZE ON BACKPACK INIT for (int i = 0; i < Size; i++) { float angle = (Mathf.PI * 2 * i) / Size; Vector2 slotPos = new Vector2(Radius * Mathf.Cos(angle), Radius * Mathf.Sin(angle)); UiInventorySlot slot = Instantiate(UiSlotPrefab, SlotsParent); slot.gameObject.transform.localPosition = slotPos; UiSlotList.Add(slot); } }
private void OnTriggerEnter2D(Collider2D collision) { UiInventorySlot uiSlot = collision.gameObject.GetComponent <UiInventorySlot>(); if (!uiSlot.IsEmpty) { if (SelectedSlot) { SelectedSlot.UnSelectSlot(); } SelectedSlot = uiSlot; uiSlot.SelectSlot(); } }
private int _GetSlotIndex(PointerEventData eventData) { // return -2 if no GO is found GameObject slotGo = eventData.pointerCurrentRaycast.gameObject; if (slotGo == null) { Debug.Log("no go found"); return(-2); } // return -1 if invalid GO is selected UiInventorySlot slot = slotGo.GetComponent <UiInventorySlot>(); if (slot == null) { Debug.Log("no slot found"); return(-1); } return(System.Array.IndexOf(gameObject.GetComponent <Inventory>().slots, slot)); }