public void PickupWithRaycast() { RaycastHit hit = new RaycastHit(); if (Physics.Raycast(playerCamera.transform.position, playerCamera.transform.forward, out hit, raycastPickupDistance)) { if (itemNameTooltip) { itemNameTooltip.text = string.Empty; } if (hit.collider.CompareTag("Item") && hit.collider.GetComponent <Item>() != null) { var item = hit.collider.GetComponent <Item>(); if (itemNameTooltip) { if (item.stackable) { itemNameTooltip.text = string.Format("{0}x{1}", item.title, item.stackSize); } else { itemNameTooltip.text = string.Format("{0}", item.title); } } if (Input.GetKeyDown(pickupKey)) { inventory.AddItem(hit.collider.GetComponent <Item>()); } } if (hit.collider.CompareTag("LootBox") && hit.collider.GetComponent <LootBox>() != null && !InventoryManager.showInventory) { if (itemNameTooltip) { itemNameTooltip.text = "Search"; } if (Input.GetKeyDown(pickupKey)) { inventory.SearchLootBox(hit.collider.GetComponent <LootBox>()); } } } else { if (itemNameTooltip != null && itemNameTooltip.text != string.Empty) { itemNameTooltip.text = string.Empty; } } }
public void OnItemPickUp(GameObject selectItem) { // var mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition); Debug.Log("pickup Item"); // selectFolder.transform.position = mousePos; inventory.AddItem(selectItem.GetComponent <Item>()); }
public void OnPointerClick(PointerEventData eventData) { if (pickupItem.interactionType != InteractionType.clickToPickup) { return; } if (eventData.hovered[0].gameObject.GetComponent <Item>() != null) { inventory.AddItem(eventData.hovered[0].gameObject.GetComponent <Item>()); } }
private void Start() { if (inventory == null) { inventory = FindObjectOfType <DTInventory>(); } if (PlayerPrefs.GetInt("ar15Save") == 1) { inventory.AddItem(ar15.GetComponent <Item>()); } if (PlayerPrefs.GetInt("ShotgunSave") == 1) { inventory.AddItem(shotgun.GetComponent <Item>()); } if (PlayerPrefs.GetInt("BarretItemSave") == 1) { inventory.AddItem(sniper.GetComponent <Item>()); } if (PlayerPrefs.GetInt("ar15magSave") == 1) { inventory.AddItem(ar15mag.GetComponent <Item>()); } if (PlayerPrefs.GetInt("bottleSave") == 1) { inventory.AddItem(bottle.GetComponent <Item>()); } if (PlayerPrefs.GetInt("conserveSave") == 1) { inventory.AddItem(conserve.GetComponent <Item>()); } }
public void Load() { print("Load started"); var itemsToDestroy = FindObjectsOfType <Item>(); var sceneLootBoxes = FindObjectsOfType <LootBox>(); foreach (var item in itemsToDestroy) { Destroy(item.gameObject); } foreach (var lootbox in sceneLootBoxes) { lootbox.lootBoxItems.Clear(); } //Inventory DTInventory inventory = FindObjectOfType <DTInventory>(); InventoryData inventoryData = JsonUtility.FromJson <InventoryData>(File.ReadAllText(Application.persistentDataPath + "/" + SceneManager.GetActiveScene().name + "_inventoryData")); var inventoryItems = inventoryData.itemNames; var stackSize = inventoryData.stackSize; var itemPos = inventoryData.itemGridPos; bool isAutoEquipEnabled = inventory.autoEquipItems; inventory.autoEquipItems = false; if (inventoryItems != null) { for (int i = 0; i < inventoryItems.Length; i++) { var findItem = assetsDatabase.FindItem(inventoryItems[i]); if (findItem != null) { var item = Instantiate(findItem); item.stackSize = stackSize[i]; inventory.AddItem(item, (int)itemPos[i].x, (int)itemPos[i].y); } else { Debug.LogAssertion("Missing item. Check if it exists in the ItemsDatabase inspector"); } } } inventory.autoEquipItems = isAutoEquipEnabled; print("Looking for data for scene " + SceneManager.GetActiveScene().name); LevelData itemsLevelData = JsonUtility.FromJson <LevelData>(File.ReadAllText(Application.persistentDataPath + "/" + SceneManager.GetActiveScene().name + "_itemsLevelData")); for (int i = 0; i < itemsLevelData.itemName.Length; i++) { if (itemsLevelData.itemName[i] != null) { try { var item = Instantiate(assetsDatabase.FindItem(itemsLevelData.itemName[i])); item.transform.position = itemsLevelData.itemPos[i]; item.transform.rotation = itemsLevelData.itemRot[i]; item.stackSize = itemsLevelData.itemStackSize[i]; } catch { Debug.LogAssertion("Item you try to restore from save: " + itemsLevelData.itemName[i] + " is null or not exist in database"); } } } LootBoxData lootBoxData = JsonUtility.FromJson <LootBoxData>(File.ReadAllText(Application.persistentDataPath + "/" + SceneManager.GetActiveScene().name + "_lootboxData")); for (int i = 0; i < sceneLootBoxes.Length; i++) { var lootbox = sceneLootBoxes[i]; char[] separator = new char[] { '|' }; string[] itemsTitles = lootBoxData.itemNames[i].Split(separator, System.StringSplitOptions.RemoveEmptyEntries); //foreach (string t in itemsTitles) // print(t); string[] itemStackSizes = lootBoxData.stackSize[i].Split(separator, System.StringSplitOptions.RemoveEmptyEntries); //foreach (string jk in itemStackSizes) // print(jk); List <int> itemStackSizesInt = new List <int>(); foreach (string itemStackSizeString in itemStackSizes) { int resultInt = -1; int.TryParse(itemStackSizeString, out resultInt); itemStackSizesInt.Add(resultInt); } for (int j = 0; j < itemsTitles.Length; j++) { if (assetsDatabase.FindItem(itemsTitles[j]) != null) { var item = Instantiate(assetsDatabase.FindItem(itemsTitles[j])); item.gameObject.SetActive(false); if (itemStackSizesInt[j] > -1) { item.stackSize = itemStackSizesInt[j]; } lootbox.lootBoxItems.Add(item); } } } }