Quest Update
This commit is contained in:
@@ -81,8 +81,9 @@ public class InventoryManager : MonoBehaviour
|
||||
return count;
|
||||
}
|
||||
|
||||
public void RemoveItem(string type)
|
||||
public void RemoveItem(string type, int amount = 1)
|
||||
{
|
||||
int leftToRemove = amount;
|
||||
for (int i = 0; i < inventorySlots.Length; i++)
|
||||
{
|
||||
ItemInventory itemInSlot = inventorySlots[i].GetComponentInChildren<ItemInventory>();
|
||||
@@ -91,7 +92,10 @@ public class InventoryManager : MonoBehaviour
|
||||
if (itemInSlot.item.type == type)
|
||||
{
|
||||
Destroy(itemInSlot.gameObject);
|
||||
return;
|
||||
leftToRemove--;
|
||||
if(leftToRemove <= 0){
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,78 +1,78 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Unity.VisualScripting;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class ItemInventory : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler, IPointerClickHandler
|
||||
{
|
||||
public item item;
|
||||
[HideInInspector]
|
||||
public Transform parentAfterDrag;
|
||||
|
||||
public Image image;
|
||||
|
||||
InventoryManager inventoryManager = new InventoryManager();
|
||||
|
||||
public void Set(item newItem, InventoryManager man)
|
||||
{
|
||||
inventoryManager = man;
|
||||
Debug.Log("Setting new item to this slot " + newItem.type, gameObject);
|
||||
item = newItem;
|
||||
image.sprite = newItem.image;
|
||||
}
|
||||
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
|
||||
// UnityEditor.EditorApplication.delayCall += () =>
|
||||
// {
|
||||
// DestroyImmediate(gameObject);
|
||||
// };
|
||||
}
|
||||
|
||||
public void Drop()
|
||||
{
|
||||
inventoryManager.
|
||||
DropItem(item);
|
||||
Destroy(gameObject);
|
||||
}
|
||||
|
||||
public void OnBeginDrag(PointerEventData eventData)
|
||||
{
|
||||
image.raycastTarget = false;
|
||||
parentAfterDrag = transform.parent;
|
||||
transform.SetParent(transform.parent.parent.parent.parent);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void OnDrag(PointerEventData eventData)
|
||||
{
|
||||
transform.position = eventData.position;
|
||||
}
|
||||
|
||||
public void OnEndDrag(PointerEventData eventData)
|
||||
{
|
||||
Debug.Log("Dropping into " + parentAfterDrag.name, parentAfterDrag.gameObject);
|
||||
if(parentAfterDrag == transform.parent)
|
||||
{
|
||||
Destroy(gameObject);
|
||||
}
|
||||
image.raycastTarget = true;
|
||||
transform.SetParent(parentAfterDrag);
|
||||
}
|
||||
|
||||
public void OnPointerClick(PointerEventData eventData)
|
||||
{
|
||||
|
||||
//inventoryManager.SelectItem(item);
|
||||
if (item.isUsable == false)return;
|
||||
if (inventoryManager.UseItem(item))
|
||||
{
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Unity.VisualScripting;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class ItemInventory : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler, IPointerClickHandler
|
||||
{
|
||||
public item item;
|
||||
[HideInInspector]
|
||||
public Transform parentAfterDrag;
|
||||
|
||||
public Image image;
|
||||
|
||||
InventoryManager inventoryManager = new InventoryManager();
|
||||
|
||||
public void Set(item newItem, InventoryManager man)
|
||||
{
|
||||
inventoryManager = man;
|
||||
Debug.Log("Setting new item to this slot " + newItem.type, gameObject);
|
||||
item = newItem;
|
||||
image.sprite = newItem.image;
|
||||
}
|
||||
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
|
||||
// UnityEditor.EditorApplication.delayCall += () =>
|
||||
// {
|
||||
// DestroyImmediate(gameObject);
|
||||
// };
|
||||
}
|
||||
|
||||
public void Drop()
|
||||
{
|
||||
inventoryManager.
|
||||
DropItem(item);
|
||||
Destroy(gameObject);
|
||||
}
|
||||
|
||||
public void OnBeginDrag(PointerEventData eventData)
|
||||
{
|
||||
image.raycastTarget = false;
|
||||
parentAfterDrag = transform.parent;
|
||||
transform.SetParent(transform.parent.parent.parent.parent);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void OnDrag(PointerEventData eventData)
|
||||
{
|
||||
transform.position = eventData.position;
|
||||
}
|
||||
|
||||
public void OnEndDrag(PointerEventData eventData)
|
||||
{
|
||||
Debug.Log("Dropping into " + parentAfterDrag.name, parentAfterDrag.gameObject);
|
||||
if(parentAfterDrag == transform.parent)
|
||||
{
|
||||
Destroy(gameObject);
|
||||
}
|
||||
image.raycastTarget = true;
|
||||
transform.SetParent(parentAfterDrag);
|
||||
}
|
||||
|
||||
public void OnPointerClick(PointerEventData eventData)
|
||||
{
|
||||
|
||||
//inventoryManager.SelectItem(item);
|
||||
if (item.isUsable == false)return;
|
||||
if (inventoryManager.UseItem(item))
|
||||
{
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,32 +1,32 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Assets.HeroEditor4D.InventorySystem.Scripts.Enums;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
[CreateAssetMenu(fileName = "InventoryItem", menuName = "ScriptableObjects/InventoryItem", order = 2)]
|
||||
public class item : ScriptableObject
|
||||
{
|
||||
public string type;
|
||||
public bool isUsable;
|
||||
public Sprite image;
|
||||
public GameObject prefab;
|
||||
public int count;
|
||||
public int spawnProbability = 50;
|
||||
public int healthIncrease = 10;
|
||||
|
||||
|
||||
|
||||
|
||||
// public InventoryItemType type;
|
||||
// public InventoryItemAction action;
|
||||
|
||||
// public enum InventoryItemType{
|
||||
|
||||
// }
|
||||
|
||||
// public enum InventoryItemAction{
|
||||
|
||||
// }
|
||||
|
||||
}
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Assets.HeroEditor4D.InventorySystem.Scripts.Enums;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
[CreateAssetMenu(fileName = "InventoryItem", menuName = "ScriptableObjects/InventoryItem", order = 2)]
|
||||
public class item : ScriptableObject
|
||||
{
|
||||
public string type;
|
||||
public bool isUsable;
|
||||
public Sprite image;
|
||||
public GameObject prefab;
|
||||
public int count;
|
||||
public int spawnProbability = 50;
|
||||
public int healthIncrease = 10;
|
||||
|
||||
|
||||
|
||||
|
||||
// public InventoryItemType type;
|
||||
// public InventoryItemAction action;
|
||||
|
||||
// public enum InventoryItemType{
|
||||
|
||||
// }
|
||||
|
||||
// public enum InventoryItemAction{
|
||||
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user