mirror of
https://github.com/DerTyp7/harvestdale-unity.git
synced 2025-10-29 12:52:07 +01:00
Drag
This commit is contained in:
@@ -60,7 +60,7 @@ public class Inventory : MonoBehaviour
|
|||||||
{
|
{
|
||||||
InventoryItem invItem = items[i];
|
InventoryItem invItem = items[i];
|
||||||
Debug.Log(invItem);
|
Debug.Log(invItem);
|
||||||
if (invItem.item == null)
|
if (invItem?.item == null)
|
||||||
{
|
{
|
||||||
|
|
||||||
int toAdd = Mathf.Min(item.maxStackSize, remainingCount);
|
int toAdd = Mathf.Min(item.maxStackSize, remainingCount);
|
||||||
|
|||||||
@@ -1,16 +1,18 @@
|
|||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.EventSystems;
|
using UnityEngine.EventSystems;
|
||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public class DraggableSlotContentUI : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler
|
public class DraggableSlotContentUI : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler
|
||||||
{
|
{
|
||||||
public int slotIndex;
|
public int slotIndex; // slotIndex is set by SlotUI
|
||||||
[HideInInspector] public Transform parentAfterDrag;
|
[HideInInspector] public Transform parentAfterDrag;
|
||||||
public Image image;
|
public Image image;
|
||||||
public void OnBeginDrag(PointerEventData eventData)
|
public void OnBeginDrag(PointerEventData eventData)
|
||||||
{
|
{
|
||||||
Debug.Log("Start Drag");
|
|
||||||
|
|
||||||
parentAfterDrag = transform.parent;
|
parentAfterDrag = transform.parent;
|
||||||
|
slotIndex = parentAfterDrag.GetComponent<SlotUI>().slotIndex; // Set slotIndex again to be safe, but should be already set
|
||||||
transform.SetParent(transform.root);
|
transform.SetParent(transform.root);
|
||||||
transform.SetAsLastSibling();
|
transform.SetAsLastSibling();
|
||||||
image.raycastTarget = false;
|
image.raycastTarget = false;
|
||||||
@@ -25,7 +27,6 @@ public class DraggableSlotContentUI : MonoBehaviour, IBeginDragHandler, IDragHan
|
|||||||
|
|
||||||
public void OnEndDrag(PointerEventData eventData)
|
public void OnEndDrag(PointerEventData eventData)
|
||||||
{
|
{
|
||||||
Debug.Log("End drag");
|
|
||||||
transform.SetParent(parentAfterDrag);
|
transform.SetParent(parentAfterDrag);
|
||||||
image.raycastTarget = true;
|
image.raycastTarget = true;
|
||||||
// invoke
|
// invoke
|
||||||
|
|||||||
@@ -32,14 +32,10 @@ public class InventoryUI : MonoBehaviour
|
|||||||
}
|
}
|
||||||
private void UpdateSlots()
|
private void UpdateSlots()
|
||||||
{
|
{
|
||||||
Debug.Log("Update slots");
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
foreach (SlotUI slotUi in slotUIList)
|
foreach (SlotUI slotUi in slotUIList)
|
||||||
{
|
{
|
||||||
|
|
||||||
slotUi.SetInventoryItem(playerInventory.items[i]);
|
slotUi.SetInventoryItem(playerInventory.items[i]);
|
||||||
|
|
||||||
|
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ public class SlotUI : MonoBehaviour, IDropHandler
|
|||||||
private void Start()
|
private void Start()
|
||||||
{
|
{
|
||||||
UpdateSlot();
|
UpdateSlot();
|
||||||
contentObject.GetComponent<DraggableSlotContentUI>().slotIndex = slotIndex;
|
|
||||||
playerInventory = GameObject.FindGameObjectWithTag("Player").GetComponent<Inventory>();
|
playerInventory = GameObject.FindGameObjectWithTag("Player").GetComponent<Inventory>();
|
||||||
}
|
}
|
||||||
public void SetInventoryItem(InventoryItem newInventoryItem)
|
public void SetInventoryItem(InventoryItem newInventoryItem)
|
||||||
|
|||||||
Reference in New Issue
Block a user