2022-10-19 13:51:46 +00:00
|
|
|
using System;
|
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
using TMPro;
|
2022-10-29 19:56:00 +00:00
|
|
|
using UnityEngine.EventSystems;
|
2022-10-19 13:51:46 +00:00
|
|
|
|
|
|
|
// TODO: Expand for other measurement systems later
|
|
|
|
|
|
|
|
namespace SimpleInventorySystem
|
|
|
|
{
|
|
|
|
public enum Orientation { Portrait, Landscape };
|
|
|
|
|
|
|
|
[Serializable]
|
|
|
|
public struct Size
|
|
|
|
{
|
|
|
|
public int Width;
|
|
|
|
public int Height;
|
|
|
|
|
|
|
|
public Size(int width, int height)
|
|
|
|
{
|
|
|
|
this.Width = width;
|
|
|
|
this.Height = height;
|
|
|
|
}
|
|
|
|
public Size(float width, float height)
|
|
|
|
{
|
|
|
|
this.Width = (int)width;
|
|
|
|
this.Height = (int)height;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int span { get { return Width * Height; } }
|
|
|
|
}
|
|
|
|
|
|
|
|
public struct KeyInput
|
|
|
|
{
|
|
|
|
public bool pressedKey, holdingKey;
|
|
|
|
public KeyCode keyCode;
|
|
|
|
|
|
|
|
public KeyInput(KeyCode keyCode)
|
|
|
|
{
|
|
|
|
this.keyCode = keyCode;
|
|
|
|
pressedKey = false;
|
|
|
|
holdingKey = false;
|
|
|
|
}
|
|
|
|
public void Update()
|
|
|
|
{
|
|
|
|
if (Input.GetKeyDown(keyCode) && !pressedKey && !holdingKey)
|
|
|
|
{
|
|
|
|
//Debug.Log("R");
|
|
|
|
pressedKey = true;
|
|
|
|
}
|
|
|
|
else if (pressedKey && !holdingKey)
|
|
|
|
{
|
|
|
|
holdingKey = true;
|
|
|
|
}
|
|
|
|
else if (Input.GetKeyUp(keyCode))
|
|
|
|
{
|
|
|
|
//Debug.Log("R - up");
|
|
|
|
holdingKey = false;
|
|
|
|
pressedKey = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool PressedKey(bool singlePress)
|
|
|
|
{
|
|
|
|
return pressedKey && (!singlePress || !holdingKey);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-15 22:58:54 +00:00
|
|
|
[Serializable]
|
|
|
|
public class TagSlotPairing
|
|
|
|
{
|
|
|
|
public ItemTags itemTag;
|
|
|
|
public SlotUI slot;
|
|
|
|
|
|
|
|
public bool HasSlotOccupied()
|
|
|
|
{
|
|
|
|
return slot.GetItemUI() != null;
|
|
|
|
}
|
2023-01-15 11:39:47 +00:00
|
|
|
|
|
|
|
public bool DropOntoSlot(ItemUI item)
|
|
|
|
{
|
2023-01-25 07:14:16 +00:00
|
|
|
return CanEquip(item) && slot.DropOntoSlot(item.gameObject);
|
2023-01-15 11:39:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public bool CanEquip(ItemUI item)
|
|
|
|
{
|
2023-01-25 07:14:16 +00:00
|
|
|
return item.ItemTag == itemTag && slot != null && (!HasSlotOccupied() || slot.IsStacking()) && slot.CanDropOntoSlot();
|
2023-01-15 11:39:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[Serializable]
|
|
|
|
public class TagSlotGridPairing
|
|
|
|
{
|
|
|
|
public ItemTags itemTag;
|
|
|
|
public SlotUI slot;
|
|
|
|
[HideInInspector] public GridUI grid;
|
|
|
|
|
|
|
|
public bool IsSlotOccupied()
|
|
|
|
{
|
|
|
|
return slot.GetItemUI() != null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool DropOntoGrid(ItemUI item)
|
|
|
|
{
|
|
|
|
//List<GridUI.Cell> cells = new List<GridUI.Cell>();
|
|
|
|
//bool canMoveInCells = grid.CanMoveInCells(item, slot, cells);
|
|
|
|
bool dropped = CanStore(item) && grid.DropItemOnGrid(item.gameObject);
|
2023-01-31 02:12:08 +00:00
|
|
|
//Debug.Log("IS:" + dropped);
|
2023-01-15 11:39:47 +00:00
|
|
|
return dropped;
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool CanStore(ItemUI item)
|
|
|
|
{
|
|
|
|
bool preliminaryCheck = item != null && (item.ItemTag == itemTag || itemTag == ItemTags.Any) && slot != null && IsSlotOccupied() && slot.GetItemUI().container != null;
|
|
|
|
bool slotCheck = preliminaryCheck && slot != null && slot.GetItemUI() != null && slot.GetItemUI().container != null;
|
|
|
|
if (!slotCheck)
|
|
|
|
return slotCheck;
|
|
|
|
grid = slot.GetItemUI().container.GetComponent<GridUI>();
|
|
|
|
bool gridCheck = grid != null;
|
2023-01-31 02:12:08 +00:00
|
|
|
//Debug.Log("IS:" + gridCheck);
|
2023-01-15 11:39:47 +00:00
|
|
|
return slotCheck && gridCheck;
|
|
|
|
}
|
2022-11-15 22:58:54 +00:00
|
|
|
}
|
|
|
|
|
2022-10-29 19:56:00 +00:00
|
|
|
public class InventorySystem : MonoBehaviour, IPointerClickHandler
|
2022-10-19 13:51:46 +00:00
|
|
|
{
|
|
|
|
public static InventorySystem instance;
|
|
|
|
public Canvas inventoryUI;
|
|
|
|
public Canvas playerUI;
|
2022-12-11 03:03:30 +00:00
|
|
|
///private TextMeshProUGUI lootMessage;
|
2022-10-19 13:51:46 +00:00
|
|
|
public GameObject InventoryMenuUI;
|
|
|
|
public GameObject LootMenuUI;
|
|
|
|
public GameObject StatsMenuUI;
|
|
|
|
public KeyCode rotateKey;
|
|
|
|
public KeyCode menuKey;
|
|
|
|
public KeyCode interactKey;
|
2022-11-15 22:58:54 +00:00
|
|
|
public KeyCode dropItemKey;
|
2022-12-11 03:03:30 +00:00
|
|
|
public KeyCode equipItemKey;
|
2022-10-19 13:51:46 +00:00
|
|
|
protected KeyInput rotationKeyInput;
|
|
|
|
protected KeyInput menuKeyInput;
|
|
|
|
protected KeyInput interactKeyInput;
|
2022-11-15 22:58:54 +00:00
|
|
|
protected KeyInput dropItemKeyInput;
|
2022-12-11 03:03:30 +00:00
|
|
|
protected KeyInput equipItemKeyInput;
|
2022-10-19 13:51:46 +00:00
|
|
|
[SerializeField] private int DefaultWidthOnGrid = 100;
|
|
|
|
[SerializeField] private int DefaultHeightOnGrid = 100;
|
|
|
|
public Size DefaultSizeOnGrid;
|
|
|
|
public Camera playerCamera;
|
|
|
|
public GameObject EventsObject;
|
|
|
|
private GameObject toolbarEvents;
|
2022-10-29 19:56:00 +00:00
|
|
|
public StandaloneInputModule StandaloneInputModule;
|
|
|
|
public Vector2 MouseInCanvasPosition;
|
2023-02-04 01:42:50 +00:00
|
|
|
private ItemUI draggedItem;
|
|
|
|
public ItemUI DraggedItem {
|
|
|
|
set { draggedItem = value; IsDraggingItem = true; }
|
|
|
|
get { return draggedItem; }
|
|
|
|
}
|
2022-10-29 19:56:00 +00:00
|
|
|
public ContextMenuManagerUI ContextMenuUI;
|
2022-11-06 02:28:29 +00:00
|
|
|
public static List<GameObject> hoverResults;
|
2022-11-15 22:58:54 +00:00
|
|
|
public Player_IS player;
|
|
|
|
public List<TagSlotPairing> TagSlotPairings;
|
2023-01-15 11:39:47 +00:00
|
|
|
public List<TagSlotGridPairing> TagSlotGridPairings;
|
2022-12-11 03:03:30 +00:00
|
|
|
public List<Rarity> raritiesList;
|
|
|
|
[Range(0, 1)] public float ItemBackdropTransparency = .5f;
|
2023-01-15 11:39:47 +00:00
|
|
|
public GridUI LootGrid;
|
|
|
|
private Inventory LastLootedInventory;
|
|
|
|
public GameObject StorageWindowPrefab;
|
2023-01-31 02:12:08 +00:00
|
|
|
public Transform DefaultItemSpawn;
|
2023-02-04 01:42:50 +00:00
|
|
|
[HideInInspector] public bool IsDraggingItem;
|
2022-12-11 03:03:30 +00:00
|
|
|
|
|
|
|
public enum States { Undefined, Loot, PickUp };
|
|
|
|
public States CurrentState = States.Undefined;
|
2022-10-19 13:51:46 +00:00
|
|
|
|
|
|
|
private void Awake()
|
|
|
|
{
|
2022-10-29 19:56:00 +00:00
|
|
|
if (instance == null)
|
2022-10-19 13:51:46 +00:00
|
|
|
{
|
|
|
|
instance = this;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// TODO: Test this, make sure only one inventory system is active throughout the game
|
|
|
|
Destroy(gameObject);
|
|
|
|
}
|
|
|
|
DefaultSizeOnGrid = new Size(DefaultWidthOnGrid, DefaultHeightOnGrid);
|
|
|
|
|
|
|
|
rotationKeyInput = new KeyInput(rotateKey);
|
|
|
|
menuKeyInput = new KeyInput(menuKey);
|
|
|
|
interactKeyInput = new KeyInput(interactKey);
|
2022-11-15 22:58:54 +00:00
|
|
|
dropItemKeyInput = new KeyInput(dropItemKey);
|
2022-12-11 03:03:30 +00:00
|
|
|
equipItemKeyInput = new KeyInput(equipItemKey);
|
|
|
|
|
|
|
|
toolbarEvents = EventsObject.transform.Find("Toolbar").gameObject;
|
|
|
|
}
|
2022-10-19 13:51:46 +00:00
|
|
|
|
2022-12-11 03:03:30 +00:00
|
|
|
public Rarity GetRarityFromList(RarityType rarityType)
|
|
|
|
{
|
|
|
|
foreach(Rarity rarity in raritiesList)
|
2022-10-29 19:56:00 +00:00
|
|
|
{
|
2022-12-11 03:03:30 +00:00
|
|
|
if(rarity.rarityType == rarityType)
|
|
|
|
{
|
|
|
|
return rarity;
|
|
|
|
}
|
2022-10-29 19:56:00 +00:00
|
|
|
}
|
2022-12-11 03:03:30 +00:00
|
|
|
return null;
|
|
|
|
}
|
2022-10-19 13:51:46 +00:00
|
|
|
|
2022-12-11 03:03:30 +00:00
|
|
|
public void SetPlayerMessageToLoot()
|
|
|
|
{
|
2022-10-19 13:51:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Start is called before the first frame update
|
|
|
|
void Start()
|
|
|
|
{
|
2022-11-15 22:58:54 +00:00
|
|
|
InventoryMenuUI.SetActive(false);
|
2022-12-23 03:50:16 +00:00
|
|
|
inventoryUI.overrideSorting = true;
|
|
|
|
CheckForRequiredComponents();
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool CheckForRequiredComponents()
|
|
|
|
{
|
|
|
|
if (playerCamera == null || !playerCamera.gameObject.activeSelf)
|
|
|
|
{
|
|
|
|
Camera[] cameras = FindObjectsOfType<Camera>();
|
|
|
|
foreach(Camera cam in cameras)
|
|
|
|
{
|
|
|
|
if (cam.gameObject.activeSelf)
|
|
|
|
{
|
|
|
|
playerCamera = cam;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(playerCamera == null)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (player == null)
|
|
|
|
{
|
|
|
|
player = FindObjectOfType<Player_IS>();
|
|
|
|
return false;
|
|
|
|
// TODO: Temporary solution. We will need to find the exact player for the client player.
|
|
|
|
}
|
|
|
|
|
2023-01-15 11:39:47 +00:00
|
|
|
if(LootGrid == null)
|
|
|
|
{
|
|
|
|
LootGrid = GetComponentInChildren<GridUI>();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-12-23 03:50:16 +00:00
|
|
|
return true;
|
2022-10-19 13:51:46 +00:00
|
|
|
}
|
|
|
|
|
2023-01-15 11:39:47 +00:00
|
|
|
public GameObject OpenWindow()
|
|
|
|
{
|
|
|
|
if(InventorySystem.instance.StorageWindowPrefab.GetComponent<StorageWindowUI>() != null)
|
|
|
|
return Instantiate(InventorySystem.instance.StorageWindowPrefab, inventoryUI.transform);
|
|
|
|
else
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2022-10-19 13:51:46 +00:00
|
|
|
// Update is called once per frame
|
|
|
|
void Update()
|
|
|
|
{
|
2023-02-04 01:42:50 +00:00
|
|
|
if(DraggedItem == null)
|
|
|
|
{
|
|
|
|
IsDraggingItem = false;
|
|
|
|
}
|
2023-01-25 07:14:16 +00:00
|
|
|
|
2022-12-23 03:50:16 +00:00
|
|
|
CheckForRequiredComponents();
|
2022-10-19 13:51:46 +00:00
|
|
|
rotationKeyInput.Update();
|
|
|
|
menuKeyInput.Update();
|
|
|
|
interactKeyInput.Update();
|
2022-11-15 22:58:54 +00:00
|
|
|
dropItemKeyInput.Update();
|
2022-12-11 03:03:30 +00:00
|
|
|
equipItemKeyInput.Update();
|
2022-10-19 13:51:46 +00:00
|
|
|
|
2022-11-15 22:58:54 +00:00
|
|
|
//else
|
|
|
|
{
|
|
|
|
DetectObject();
|
|
|
|
}
|
2022-10-19 13:51:46 +00:00
|
|
|
|
|
|
|
if (menuKeyInput.PressedKey(true))
|
|
|
|
{
|
|
|
|
if(InventoryMenuUI != null)
|
|
|
|
{
|
|
|
|
ToggleInventory();
|
|
|
|
}
|
|
|
|
}
|
2022-11-06 02:28:29 +00:00
|
|
|
|
|
|
|
hoverResults = GetPointerOverUIObject();
|
|
|
|
}
|
|
|
|
|
|
|
|
private List<GameObject> GetPointerOverUIObject()
|
|
|
|
{
|
|
|
|
PointerEventData eventDataCurrentPosition = new PointerEventData(EventSystem.current);
|
|
|
|
eventDataCurrentPosition.position = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
|
|
|
|
List<RaycastResult> results = new List<RaycastResult>();
|
|
|
|
EventSystem.current.RaycastAll(eventDataCurrentPosition, results);
|
|
|
|
List<GameObject> rGOs = new List<GameObject>();
|
|
|
|
for (int i = 0; i < results.Count; i++)
|
|
|
|
{
|
|
|
|
if (results[i].gameObject.layer == LayerMask.GetMask("Ignore Raycast"))
|
|
|
|
{
|
|
|
|
results.RemoveAt(i);
|
|
|
|
i--;
|
|
|
|
}
|
|
|
|
else// if (results[i].gameObject.layer == LayerMask.GetMask("UI"))
|
|
|
|
{
|
|
|
|
rGOs.Add(results[i].gameObject);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return rGOs;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static bool IsMouseOverUI(GameObject go)
|
|
|
|
{
|
|
|
|
if(hoverResults == null || hoverResults.Count == 0)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return hoverResults.Contains(go);
|
|
|
|
}
|
|
|
|
public static bool IsMouseOverItemUITop(ItemUI item)
|
|
|
|
{
|
|
|
|
if (hoverResults == null || hoverResults.Count == 0)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
foreach(GameObject go in hoverResults)
|
|
|
|
{
|
|
|
|
if(go.GetComponent<ItemUI>() != null)
|
|
|
|
{
|
|
|
|
if (go.GetComponent<ItemUI>() == item)
|
|
|
|
return true;
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2022-10-19 13:51:46 +00:00
|
|
|
}
|
|
|
|
|
2022-10-29 19:56:00 +00:00
|
|
|
private void FixedUpdate()
|
|
|
|
{
|
|
|
|
Vector2 movePos;
|
|
|
|
RectTransformUtility.ScreenPointToLocalPointInRectangle(inventoryUI.transform as RectTransform, Input.mousePosition, inventoryUI.worldCamera, out movePos);
|
|
|
|
|
|
|
|
MouseInCanvasPosition = InventorySystem.instance.inventoryUI.transform.TransformPoint(movePos);
|
|
|
|
}
|
|
|
|
|
2022-10-19 13:51:46 +00:00
|
|
|
public void ToggleInventory()
|
|
|
|
{
|
|
|
|
if (InventoryMenuUI.activeInHierarchy)
|
|
|
|
{
|
2023-02-04 01:42:50 +00:00
|
|
|
if(DraggedItem != null)
|
|
|
|
{
|
|
|
|
Debug.Log("Return to Slot");
|
|
|
|
DraggedItem.ReturnToSlot(true);
|
|
|
|
}
|
2022-10-19 13:51:46 +00:00
|
|
|
CloseInventory();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
OpenInventory();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void OpenInventory()
|
|
|
|
{
|
|
|
|
InventoryMenuUI.SetActive(true);
|
2022-12-23 03:50:16 +00:00
|
|
|
Cursor.visible = true;
|
|
|
|
Cursor.lockState = CursorLockMode.Confined;
|
2022-10-19 13:51:46 +00:00
|
|
|
toolbarEvents.GetComponent<MoveChildrenUI>().MoveToTarget(false, true);
|
2023-01-25 07:14:16 +00:00
|
|
|
if(GetComponent<NeoFPSPause>() != null)
|
|
|
|
{
|
|
|
|
GetComponent<NeoFPSPause>().pauseMenu.PopEscapeHandlerShow();
|
|
|
|
}
|
2022-10-19 13:51:46 +00:00
|
|
|
}
|
2023-01-15 11:39:47 +00:00
|
|
|
|
2022-10-19 13:51:46 +00:00
|
|
|
public void CloseInventory()
|
|
|
|
{
|
2022-12-23 03:50:16 +00:00
|
|
|
toolbarEvents.GetComponent<MoveChildrenUI>().MoveToSource(true, false);
|
|
|
|
Cursor.lockState = CursorLockMode.Locked;
|
|
|
|
Cursor.visible = false;
|
2022-10-19 13:51:46 +00:00
|
|
|
InventoryMenuUI.SetActive(false);
|
2023-01-25 07:14:16 +00:00
|
|
|
if (GetComponent<NeoFPSPause>() != null)
|
|
|
|
{
|
|
|
|
GetComponent<NeoFPSPause>().pauseMenu.PushEscapeHandlerShow();
|
|
|
|
}
|
2022-10-19 13:51:46 +00:00
|
|
|
}
|
|
|
|
|
2022-10-29 19:56:00 +00:00
|
|
|
public void OpenContextMenu(MonoBehaviour uiContext)
|
|
|
|
{
|
|
|
|
if (uiContext.GetType() == typeof(ItemUI))
|
|
|
|
{
|
|
|
|
ContextMenuUI.OpenContextMenu((ItemUI)uiContext);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-19 13:51:46 +00:00
|
|
|
private void DetectObject()
|
|
|
|
{
|
2022-12-11 03:03:30 +00:00
|
|
|
CurrentState = States.Undefined;
|
|
|
|
|
2022-10-19 13:51:46 +00:00
|
|
|
if (playerCamera == null)
|
|
|
|
{
|
2022-10-29 19:56:00 +00:00
|
|
|
//Debug.Log("Uh OHHH. No camera detected");
|
2022-10-19 13:51:46 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-10-29 19:56:00 +00:00
|
|
|
//Debug.Log("Detecting...");
|
2022-10-19 13:51:46 +00:00
|
|
|
}
|
2022-11-15 22:58:54 +00:00
|
|
|
|
2022-12-11 03:03:30 +00:00
|
|
|
//Ray ray = playerCamera.ScreenPointToRay(new Vector2(Screen.width / 2, Screen.height / 2));//controls.Mouse.Position.ReadValue<Vector2>());
|
|
|
|
Vector3 direction = Vector3.forward;
|
|
|
|
Ray ray = new Ray(playerCamera.transform.position, playerCamera.transform.TransformDirection(direction * 200));
|
|
|
|
Debug.DrawRay(playerCamera.transform.position, playerCamera.transform.TransformDirection(direction * 200), Color.red);
|
|
|
|
|
|
|
|
//RaycastHit hit;
|
|
|
|
/*if (Physics.Raycast(ray, out hit))
|
2022-10-19 13:51:46 +00:00
|
|
|
{
|
2022-11-15 22:58:54 +00:00
|
|
|
// for single hits, i guess...
|
2022-12-11 03:03:30 +00:00
|
|
|
}*/
|
2022-11-15 22:58:54 +00:00
|
|
|
|
|
|
|
RaycastHit[] hits = Physics.RaycastAll(ray, 200);
|
|
|
|
for(int i = 0; i < hits.Length; i++)
|
|
|
|
{
|
|
|
|
if (hits[i].collider != null)
|
|
|
|
{
|
|
|
|
//Debug.Log("3D Hit All: " + hits[i].collider.gameObject.name);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-12-11 03:03:30 +00:00
|
|
|
if (hits[i].collider != null)// && hit.transform.parent.parent.parent != null)
|
2022-10-19 13:51:46 +00:00
|
|
|
{
|
2022-12-11 03:03:30 +00:00
|
|
|
PickUp response_pickUp = hits[i].collider.transform.GetComponent<PickUp>();
|
2022-11-15 22:58:54 +00:00
|
|
|
if (response_pickUp && !InventorySystem.instance.IsUsingInventoryMenuUI())
|
|
|
|
{
|
2022-12-23 03:50:16 +00:00
|
|
|
//Debug.Log("Detecting");
|
2022-12-11 03:03:30 +00:00
|
|
|
CurrentState = States.PickUp;
|
|
|
|
DisplayMessageSystem.instance.NameOfItemInWorldWithFocus = response_pickUp.itemUI.itemName;
|
2022-11-15 22:58:54 +00:00
|
|
|
|
2023-01-15 11:39:47 +00:00
|
|
|
//Debug.Log("IS: Detecting PickUp");
|
2023-01-31 02:12:08 +00:00
|
|
|
if (interactKeyInput.PressedKey(true))
|
2022-12-23 03:50:16 +00:00
|
|
|
{
|
2023-01-15 11:39:47 +00:00
|
|
|
//Debug.Log("IS: Pickup handle");
|
2022-11-15 22:58:54 +00:00
|
|
|
player.HandlePickup(response_pickUp);
|
2022-12-23 03:50:16 +00:00
|
|
|
}
|
2022-11-15 22:58:54 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-12-11 03:03:30 +00:00
|
|
|
CurrentState = States.Undefined;
|
2022-11-15 22:58:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-10-29 19:56:00 +00:00
|
|
|
//Debug.Log("3D Hit: " + hit.collider.transform.name);
|
2022-10-19 13:51:46 +00:00
|
|
|
// TODO: functionality here
|
|
|
|
|
2022-12-11 03:03:30 +00:00
|
|
|
Inventory response_inventory = hits[i].collider.transform.GetComponent<Inventory>();
|
2022-11-15 22:58:54 +00:00
|
|
|
|
2022-12-23 03:50:16 +00:00
|
|
|
if(response_inventory != null && response_inventory == player.inventory)
|
2022-11-15 22:58:54 +00:00
|
|
|
{
|
|
|
|
continue; // ignore self
|
|
|
|
}
|
|
|
|
|
2023-01-15 11:39:47 +00:00
|
|
|
if (response_inventory != null && !InventorySystem.instance.IsUsingInventoryMenuUI())
|
2022-10-19 13:51:46 +00:00
|
|
|
{
|
2023-01-31 02:12:08 +00:00
|
|
|
//Debug.Log("Opening Inventory");
|
2022-10-19 13:51:46 +00:00
|
|
|
if (interactKeyInput.PressedKey(true))
|
|
|
|
{
|
|
|
|
OpenInventory();
|
|
|
|
LootMenuUI.SetActive(true);
|
|
|
|
StatsMenuUI.SetActive(false);
|
2023-01-15 11:39:47 +00:00
|
|
|
Loot(response_inventory);
|
2022-12-11 03:03:30 +00:00
|
|
|
CurrentState = States.Undefined;
|
2022-10-19 13:51:46 +00:00
|
|
|
}
|
|
|
|
else if (!InventorySystem.instance.IsUsingInventoryMenuUI())
|
|
|
|
{
|
2022-12-11 03:03:30 +00:00
|
|
|
CurrentState = States.Loot;
|
2022-10-19 13:51:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(!InventorySystem.instance.IsUsingInventoryMenuUI())
|
|
|
|
{
|
2022-12-11 03:03:30 +00:00
|
|
|
CurrentState = States.Undefined;
|
2022-10-19 13:51:46 +00:00
|
|
|
LootMenuUI.SetActive(false);
|
|
|
|
StatsMenuUI.SetActive(true);
|
2023-01-15 11:39:47 +00:00
|
|
|
}
|
2022-10-19 13:51:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*RaycastHit[] hitsNonAlloc = new RaycastHit[1];
|
|
|
|
int numberOfHits = Physics.RaycastNonAlloc(ray, hitsNonAlloc);
|
|
|
|
for (int i = 0; i < numberOfHits; i++)
|
|
|
|
{
|
|
|
|
if (hitsNonAlloc[i].collider != null)
|
|
|
|
{
|
|
|
|
Debug.Log("3D Hit Non Alloc All: " + hitsNonAlloc[i].collider.tag);
|
|
|
|
}
|
|
|
|
}*/
|
|
|
|
}
|
|
|
|
|
2023-01-15 11:39:47 +00:00
|
|
|
public void Loot(Inventory inventory)
|
|
|
|
{
|
|
|
|
if (inventory != null && inventory != player.inventory && !inventory.hasBeenLooted)
|
|
|
|
{
|
|
|
|
inventory.Loot();
|
2023-01-31 02:12:08 +00:00
|
|
|
//Debug.Log($"Looting: {inventory.itemUIs.Count}");
|
2023-01-15 11:39:47 +00:00
|
|
|
StartCoroutine(LootGrid.PopulateItemsWithNewInventory(inventory.itemUIs));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-19 13:51:46 +00:00
|
|
|
/// <summary>
|
|
|
|
/// This can be called to check if player is interacting with the Inventory System's UI
|
|
|
|
/// </summary>
|
|
|
|
/// <returns></returns>
|
|
|
|
public bool IsUsingInventoryMenuUI()
|
|
|
|
{
|
|
|
|
return InventoryMenuUI.activeInHierarchy;
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool PressedKeyRotation(bool singlePress)
|
|
|
|
{
|
|
|
|
return rotationKeyInput.PressedKey(singlePress);
|
|
|
|
}
|
2022-12-11 03:03:30 +00:00
|
|
|
|
2022-11-15 22:58:54 +00:00
|
|
|
public bool PressedDropItemKey(bool singlePress)
|
|
|
|
{
|
2022-12-11 03:03:30 +00:00
|
|
|
return dropItemKeyInput.PressedKey(singlePress) && Input.GetMouseButton(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool PressedEquipItemKey(bool singlePress)
|
|
|
|
{
|
|
|
|
return equipItemKeyInput.PressedKey(singlePress) && Input.GetMouseButton(0);
|
2022-11-15 22:58:54 +00:00
|
|
|
}
|
2022-10-29 19:56:00 +00:00
|
|
|
|
|
|
|
public void OnPointerClick(PointerEventData eventData)
|
|
|
|
{
|
2022-12-11 03:03:30 +00:00
|
|
|
if(eventData.button == PointerEventData.InputButton.Left && !ContextMenuManagerUI.instance.ItemInspectMenuHasFocus() && ContextMenuManagerUI.instance.IsInspectingItem())
|
|
|
|
{
|
|
|
|
ContextMenuManagerUI.instance.CloseContextMenu();
|
|
|
|
}
|
2022-10-29 19:56:00 +00:00
|
|
|
}
|
2022-10-19 13:51:46 +00:00
|
|
|
}
|
|
|
|
}
|