Drop item onto storage container

This commit is contained in:
tonyomendoza 2023-01-26 18:16:31 -08:00
parent 8a6fdd6156
commit 6e13c5dd08
10 changed files with 44037 additions and 260 deletions

View File

@ -351,7 +351,7 @@ MonoBehaviour:
image: {fileID: 0} image: {fileID: 0}
useImageAsSlotHolder: 0 useImageAsSlotHolder: 0
EquipSlot: 1 EquipSlot: 1
FitItemImageInSlotImage: 0 FitItemImageInSlotImage: 1
IgnoreItemSize: 1 IgnoreItemSize: 1
AllowedItemTags: 08000000 AllowedItemTags: 08000000
DisallowedItemTags: DisallowedItemTags:
@ -2766,7 +2766,7 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0} m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 1} m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: -0.00048828125, y: 0} m_AnchoredPosition: {x: 0.000091552734, y: 0}
m_SizeDelta: {x: 0, y: 2250} m_SizeDelta: {x: 0, y: 2250}
m_Pivot: {x: 0, y: 1} m_Pivot: {x: 0, y: 1}
--- !u!114 &2770326604978625766 --- !u!114 &2770326604978625766
@ -4300,7 +4300,7 @@ MonoBehaviour:
image: {fileID: 0} image: {fileID: 0}
useImageAsSlotHolder: 0 useImageAsSlotHolder: 0
EquipSlot: 1 EquipSlot: 1
FitItemImageInSlotImage: 0 FitItemImageInSlotImage: 1
IgnoreItemSize: 1 IgnoreItemSize: 1
AllowedItemTags: 06000000 AllowedItemTags: 06000000
DisallowedItemTags: DisallowedItemTags:
@ -4927,7 +4927,7 @@ MonoBehaviour:
image: {fileID: 0} image: {fileID: 0}
useImageAsSlotHolder: 0 useImageAsSlotHolder: 0
EquipSlot: 0 EquipSlot: 0
FitItemImageInSlotImage: 0 FitItemImageInSlotImage: 1
IgnoreItemSize: 1 IgnoreItemSize: 1
AllowedItemTags: 05000000 AllowedItemTags: 05000000
DisallowedItemTags: DisallowedItemTags:
@ -7578,7 +7578,7 @@ MonoBehaviour:
m_TargetGraphic: {fileID: 2770326605425540239} m_TargetGraphic: {fileID: 2770326605425540239}
m_HandleRect: {fileID: 2770326605425540238} m_HandleRect: {fileID: 2770326605425540238}
m_Direction: 2 m_Direction: 2
m_Value: 1.0000005 m_Value: 1
m_Size: 0.5264038 m_Size: 0.5264038
m_NumberOfSteps: 0 m_NumberOfSteps: 0
m_OnValueChanged: m_OnValueChanged:
@ -8622,8 +8622,8 @@ MonoBehaviour:
m_TargetGraphic: {fileID: 2770326605532365202} m_TargetGraphic: {fileID: 2770326605532365202}
m_HandleRect: {fileID: 2770326605532365201} m_HandleRect: {fileID: 2770326605532365201}
m_Direction: 0 m_Direction: 0
m_Value: 1 m_Value: 0
m_Size: 0.99999994 m_Size: 1
m_NumberOfSteps: 0 m_NumberOfSteps: 0
m_OnValueChanged: m_OnValueChanged:
m_PersistentCalls: m_PersistentCalls:
@ -9752,6 +9752,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: cd9ef096fe611e246a2140b3c29f6ba1, type: 3} m_Script: {fileID: 11500000, guid: cd9ef096fe611e246a2140b3c29f6ba1, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
pauseMenu: {fileID: 0}
--- !u!1 &2770326605798828941 --- !u!1 &2770326605798828941
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -9867,7 +9868,7 @@ MonoBehaviour:
image: {fileID: 0} image: {fileID: 0}
useImageAsSlotHolder: 0 useImageAsSlotHolder: 0
EquipSlot: 1 EquipSlot: 1
FitItemImageInSlotImage: 0 FitItemImageInSlotImage: 1
IgnoreItemSize: 1 IgnoreItemSize: 1
AllowedItemTags: 07000000 AllowedItemTags: 07000000
DisallowedItemTags: DisallowedItemTags:
@ -12583,7 +12584,7 @@ MonoBehaviour:
image: {fileID: 2770326605760504765} image: {fileID: 2770326605760504765}
useImageAsSlotHolder: 1 useImageAsSlotHolder: 1
EquipSlot: 1 EquipSlot: 1
FitItemImageInSlotImage: 0 FitItemImageInSlotImage: 1
IgnoreItemSize: 1 IgnoreItemSize: 1
AllowedItemTags: 02000000 AllowedItemTags: 02000000
DisallowedItemTags: DisallowedItemTags:
@ -12787,7 +12788,7 @@ MonoBehaviour:
image: {fileID: 0} image: {fileID: 0}
useImageAsSlotHolder: 0 useImageAsSlotHolder: 0
EquipSlot: 0 EquipSlot: 0
FitItemImageInSlotImage: 0 FitItemImageInSlotImage: 1
IgnoreItemSize: 1 IgnoreItemSize: 1
AllowedItemTags: 05000000 AllowedItemTags: 05000000
DisallowedItemTags: DisallowedItemTags:
@ -12960,7 +12961,7 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 1} m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 1, y: 1} m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: -0.00024414062, y: -0.0002941991} m_AnchoredPosition: {x: -0.00012207031, y: 0}
m_SizeDelta: {x: 0, y: 1500} m_SizeDelta: {x: 0, y: 1500}
m_Pivot: {x: 0, y: 1} m_Pivot: {x: 0, y: 1}
--- !u!114 &2770326606141421693 --- !u!114 &2770326606141421693
@ -13504,7 +13505,7 @@ MonoBehaviour:
image: {fileID: 2770326606446118955} image: {fileID: 2770326606446118955}
useImageAsSlotHolder: 1 useImageAsSlotHolder: 1
EquipSlot: 1 EquipSlot: 1
FitItemImageInSlotImage: 0 FitItemImageInSlotImage: 1
IgnoreItemSize: 1 IgnoreItemSize: 1
AllowedItemTags: 0900000012000000 AllowedItemTags: 0900000012000000
DisallowedItemTags: DisallowedItemTags:
@ -13673,7 +13674,7 @@ MonoBehaviour:
image: {fileID: 2770326604820499960} image: {fileID: 2770326604820499960}
useImageAsSlotHolder: 1 useImageAsSlotHolder: 1
EquipSlot: 1 EquipSlot: 1
FitItemImageInSlotImage: 0 FitItemImageInSlotImage: 1
IgnoreItemSize: 1 IgnoreItemSize: 1
AllowedItemTags: 06000000 AllowedItemTags: 06000000
DisallowedItemTags: DisallowedItemTags:
@ -14612,7 +14613,7 @@ MonoBehaviour:
image: {fileID: 0} image: {fileID: 0}
useImageAsSlotHolder: 1 useImageAsSlotHolder: 1
EquipSlot: 1 EquipSlot: 1
FitItemImageInSlotImage: 0 FitItemImageInSlotImage: 1
IgnoreItemSize: 1 IgnoreItemSize: 1
AllowedItemTags: 11000000 AllowedItemTags: 11000000
DisallowedItemTags: DisallowedItemTags:
@ -15070,6 +15071,8 @@ GameObject:
m_Component: m_Component:
- component: {fileID: 2770326606332454989} - component: {fileID: 2770326606332454989}
- component: {fileID: 2770326606332454990} - component: {fileID: 2770326606332454990}
- component: {fileID: 2109804768}
- component: {fileID: 2109804769}
m_Layer: 5 m_Layer: 5
m_Name: Tactical Rig Group Slot Manager m_Name: Tactical Rig Group Slot Manager
m_TagString: Untagged m_TagString: Untagged
@ -15125,6 +15128,40 @@ MonoBehaviour:
incompatibleSlots: [] incompatibleSlots: []
hideGameObjects: [] hideGameObjects: []
AllowedItemTags: 09000000 AllowedItemTags: 09000000
--- !u!114 &2109804768
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2770326606332454988}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: a6349c95e0055a64db6010b6bfaa9971, type: 3}
m_Name:
m_EditorClassIdentifier:
StackSlotLimit: 12
limitStackSlots:
- {fileID: 2770326605039798047}
- {fileID: 2770326605069652577}
- {fileID: 2770326605604029970}
- {fileID: 2770326606725301637}
combinedLimit: 1
slot: {fileID: 0}
--- !u!114 &2109804769
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2770326606332454988}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: ec4b16f08baaf5648a7e5ebe9e562069, type: 3}
m_Name:
m_EditorClassIdentifier:
textMeshProUGUI: {fileID: 2770326604711117547}
value:
--- !u!1 &2770326606343437209 --- !u!1 &2770326606343437209
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -17491,7 +17528,7 @@ MonoBehaviour:
image: {fileID: 2770326605749996529} image: {fileID: 2770326605749996529}
useImageAsSlotHolder: 1 useImageAsSlotHolder: 1
EquipSlot: 1 EquipSlot: 1
FitItemImageInSlotImage: 0 FitItemImageInSlotImage: 1
IgnoreItemSize: 1 IgnoreItemSize: 1
AllowedItemTags: 01000000 AllowedItemTags: 01000000
DisallowedItemTags: DisallowedItemTags:

View File

@ -92,9 +92,10 @@ MonoBehaviour:
CellPrefab: {fileID: 0} CellPrefab: {fileID: 0}
generateCells: 0 generateCells: 0
slots: [] slots: []
associatedItemUI: {fileID: 0}
gridSize: gridSize:
Width: 4 Width: 4
Height: 3 Height: 4
testItem: {fileID: 0} testItem: {fileID: 0}
testItems: [] testItems: []
--- !u!1001 &260965358647896355 --- !u!1001 &260965358647896355

View File

@ -111,9 +111,10 @@ MonoBehaviour:
CellPrefab: {fileID: 4961555904879958529} CellPrefab: {fileID: 4961555904879958529}
generateCells: 0 generateCells: 0
slots: [] slots: []
associatedItemUI: {fileID: 0}
gridSize: gridSize:
Width: 5 Width: 5
Height: 6 Height: 7
testItem: {fileID: 0} testItem: {fileID: 0}
testItems: [] testItems: []
--- !u!1001 &438648606362640708 --- !u!1001 &438648606362640708

View File

@ -426,6 +426,7 @@ namespace SimpleInventorySystem
public SlotUI slot; public SlotUI slot;
public bool ownsSlot; public bool ownsSlot;
public bool inUse; public bool inUse;
public ItemUI item;
public Cell(int x, int y, SlotUI slot, bool ownsSlot) public Cell(int x, int y, SlotUI slot, bool ownsSlot)
{ {

View File

@ -19,7 +19,7 @@ namespace SimpleInventorySystem
public int StackLimit = 1; public int StackLimit = 1;
public int width; public int width;
public int height; public int height;
public float weight; public float weight;
public float monetaryValue; public float monetaryValue;
[Header("Container Prefab")] [Header("Container Prefab")]
public GameObject containerUIPrefab; public GameObject containerUIPrefab;
@ -103,9 +103,9 @@ namespace SimpleInventorySystem
if (image == null) if (image == null)
{ {
Image[] images = transform.GetComponentsInChildren<Image>(); Image[] images = transform.GetComponentsInChildren<Image>();
for(int i = 0; i < images.Length; i++) for (int i = 0; i < images.Length; i++)
{ {
if(images[i] == GetComponent<Image>()) if (images[i] == GetComponent<Image>())
{ {
continue; continue;
} }
@ -114,7 +114,7 @@ namespace SimpleInventorySystem
} }
} }
if(image == null) if (image == null)
{ {
Debug.LogError("ItemUI: Item needs a child with an Image component."); Debug.LogError("ItemUI: Item needs a child with an Image component.");
} }
@ -161,7 +161,7 @@ namespace SimpleInventorySystem
public int ContainerCapacity() public int ContainerCapacity()
{ {
GridUI gridUI = null; GridUI gridUI = null;
if(container != null && container.TryGetComponent<GridUI>(out gridUI)) if (container != null && container.TryGetComponent<GridUI>(out gridUI))
{ {
return gridUI.gridSize.Width * gridUI.gridSize.Height; return gridUI.gridSize.Width * gridUI.gridSize.Height;
} }
@ -229,7 +229,7 @@ namespace SimpleInventorySystem
{ {
foreach (TagSlotGridPairing tsgp in InventorySystem.instance.TagSlotGridPairings) foreach (TagSlotGridPairing tsgp in InventorySystem.instance.TagSlotGridPairings)
{ {
if (tsgp.CanStore (this)) if (tsgp.CanStore(this))
{ {
UnsetSlot(); UnsetSlot();
bool value = tsgp.DropOntoGrid(this); bool value = tsgp.DropOntoGrid(this);
@ -239,6 +239,7 @@ namespace SimpleInventorySystem
} }
else else
{ {
container.SetActive(false);
return true; return true;
} }
} }
@ -247,6 +248,19 @@ namespace SimpleInventorySystem
return false; return false;
} }
public bool DropItemInStorageContainer(ItemUI droppedItem)
{
Debug.Log("Checking");
if (IsStorageContainer())
{
Debug.Log("Storage container found");
return container.GetComponent<GridUI>().DropItemOnGrid(droppedItem.gameObject);
}
return false;
}
public void DropItemOntoSlot(bool fitImageInSlot = false) public void DropItemOntoSlot(bool fitImageInSlot = false)
{ {
//Debug.Log("OnEndDrag"); //Debug.Log("OnEndDrag");
@ -359,6 +373,7 @@ namespace SimpleInventorySystem
if (c != null) if (c != null)
{ {
c.inUse = false; c.inUse = false;
c.item = null;
//c.overlapped = false; //c.overlapped = false;
//s.ShowImage(); //s.ShowImage();
if (c.GetSlot() != null && c.GetSlot() != this.slot) if (c.GetSlot() != null && c.GetSlot() != this.slot)
@ -382,32 +397,6 @@ namespace SimpleInventorySystem
item.ParentContainer = null; item.ParentContainer = null;
} }
public void OnPointerDown(PointerEventData eventData)
{
if (eventData.button == PointerEventData.InputButton.Left)
{
GrabAndDragItem();
}
}
public void OnPointerClick(PointerEventData eventData)
{
if(eventData.button == PointerEventData.InputButton.Left)
{
GrabAndDragItem();
}
else if (eventData.button == PointerEventData.InputButton.Right)
{
InventorySystem.instance.OpenContextMenu(this);
}
/*else if (eventData.button == PointerEventData.InputButton.Right)
{
InventorySystem.instance.OpenContextMenu(this);
}*/
}
public void FitImageInSlot(Vector2 size) public void FitImageInSlot(Vector2 size)
{ {
Debug.Log("FitImageInSlot: " + image.transform.name); Debug.Log("FitImageInSlot: " + image.transform.name);
@ -480,6 +469,8 @@ namespace SimpleInventorySystem
backdropImage.color = new Color(r.color.r, r.color.g, r.color.b, InventorySystem.instance.ItemBackdropTransparency); backdropImage.color = new Color(r.color.r, r.color.g, r.color.b, InventorySystem.instance.ItemBackdropTransparency);
} }
CreateStorageContainer();
//backdropImage.sprite.rect. //backdropImage.sprite.rect.
/*overrideSortingCanvas = gameObject.AddComponent<Canvas>(); /*overrideSortingCanvas = gameObject.AddComponent<Canvas>();
@ -582,6 +573,7 @@ namespace SimpleInventorySystem
{ {
cells[i] = cellList[i]; cells[i] = cellList[i];
cells[i].inUse = true; cells[i].inUse = true;
cells[i].item = this;
} }
} }
} }
@ -610,11 +602,7 @@ namespace SimpleInventorySystem
} }
return false; return false;
} }
public void UnsetSlots()
{
cells = null;
}
void FixedUpdate() void FixedUpdate()
{ {
@ -704,42 +692,42 @@ namespace SimpleInventorySystem
{ {
if (PointerIsHoveredOver && Input.GetMouseButtonDown(2)) if (PointerIsHoveredOver && Input.GetMouseButtonDown(2))
{ {
CreateStorageWindow(); ShowStorageWindow();
} }
} }
} }
public void CreateStorageWindow() public void ShowStorageWindow()
{ {
if(StorageWindow == null || !StorageWindow.gameObject.activeSelf) if(IsStorageContainer() && (StorageWindow == null || !StorageWindow.gameObject.activeSelf))
{ {
Debug.Log("Opening Window"); Debug.Log("Opening Window");
StorageWindow = InventorySystem.instance.OpenWindow().GetComponent<StorageWindowUI>(); StorageWindow = InventorySystem.instance.OpenWindow().GetComponent<StorageWindowUI>();
if(StorageWindow != null && containerUIPrefab != null && !Equipped) if(StorageWindow != null && containerUIPrefab != null && !Equipped)
{ {
Debug.Log("Opening Window"); Debug.Log("Opening Window");
if (container == null)
{
Debug.Log("Creating new");
container = Instantiate(containerUIPrefab, StorageWindow.StorageContainer.transform, false);
//itemUI.container.name = itemUI.container.name + " " + inCount;
container.SetActive(true);
StorageWindow.gameObject.SetActive(true);
StorageWindow.itemUI = this;
container.GetComponentInChildren<GridUI>().SetAssociatedItemUI(this);
}
else
{
if(container.transform.parent != StorageWindow.StorageContainer.transform) if(container.transform.parent != StorageWindow.StorageContainer.transform)
container.transform.SetParent(StorageWindow.StorageContainer.transform, false); container.transform.SetParent(StorageWindow.StorageContainer.transform, false);
container.SetActive(true); container.SetActive(true);
StorageWindow.itemUI = this; StorageWindow.itemUI = this;
StorageWindow.gameObject.SetActive(true); StorageWindow.gameObject.SetActive(true);
}
} }
} }
} }
public void CreateStorageContainer()
{
if (container == null && IsStorageContainer())
{
Debug.Log("Item:CreateStorageContainer:" + gameObject.name);
container = Instantiate(containerUIPrefab, this.transform, false);// StorageWindow.StorageContainer.transform, false);
//itemUI.container.name = itemUI.container.name + " " + inCount;
container.GetComponentInChildren<GridUI>().SetAssociatedItemUI(this);
container.SetActive(true);
}
}
public void DropItemAway() public void DropItemAway()
{ {
if (pickUp == null) if (pickUp == null)
@ -779,5 +767,10 @@ namespace SimpleInventorySystem
{ {
//PointerIsHoveredOver = true; //PointerIsHoveredOver = true;
} }
public bool IsStorageContainer()
{
return containerUIPrefab != null && containerUIPrefab.GetComponent<GridUI>() != null;
}
} }
} }

View File

@ -563,18 +563,28 @@ namespace SimpleInventorySystem
if (Input.GetMouseButtonDown(0)) if (Input.GetMouseButtonDown(0))
{ {
DroppedOnFrame = true; DroppedOnFrame = true;
bool callback = DropOntoSlot(droppedItem.gameObject, true); ItemUI potentialContainerItem = cell.item;
if (callback && droppedItem.Stackable) if (potentialContainerItem != null && potentialContainerItem.DropItemInStorageContainer(droppedItem))
{ {
if (droppedItem.Count <= 0) // todo: do something, or not, idk
Debug.Log("This should have dropped into a storage container");
}
else
{
bool callback = DropOntoSlot(droppedItem.gameObject, true);
if (callback && droppedItem.Stackable)
{ {
Destroy(droppedItem.gameObject); if (droppedItem.Count <= 0)
} {
else if (itemUI.Count < droppedItem.Count && !droppedStackOntoEmptySlot) Destroy(droppedItem.gameObject);
{ }
InventorySystem.instance.DraggedItem = droppedItem; else if (itemUI.Count < droppedItem.Count && !droppedStackOntoEmptySlot)
droppedStackOntoEmptySlot = false; {
InventorySystem.instance.DraggedItem = droppedItem;
droppedStackOntoEmptySlot = false;
}
} }
} }
} }
@ -629,23 +639,6 @@ namespace SimpleInventorySystem
} }
} }
public void OnPointerClick(PointerEventData eventData)
{
}
public void OnPointerDown(PointerEventData eventData)
{
if(InventorySystem.instance.PressedDropItemKey(false) || InventorySystem.instance.PressedEquipItemKey(false))
{
return;
}
ItemUI droppedItem = InventorySystem.instance.DraggedItem;
if (droppedItem != null && !droppedItem.PickedUpOnFrame)
{
DropOntoSlot(droppedItem.gameObject);
}
}
public void OnPointerExit(PointerEventData eventData) public void OnPointerExit(PointerEventData eventData)
{ {
//PointerIsHoveredOver = false; //PointerIsHoveredOver = false;

View File

@ -153,7 +153,7 @@ PrefabInstance:
- target: {fileID: 41448509920528303, guid: d8382154c724fca4a8ddc89666da0975, - target: {fileID: 41448509920528303, guid: d8382154c724fca4a8ddc89666da0975,
type: 3} type: 3}
propertyPath: m_LocalPosition.z propertyPath: m_LocalPosition.z
value: 0 value: 1.357
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 41448509920528303, guid: d8382154c724fca4a8ddc89666da0975, - target: {fileID: 41448509920528303, guid: d8382154c724fca4a8ddc89666da0975,
type: 3} type: 3}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: d89d974d3d9627f4a998d330e3ebba28
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant: