This commit is contained in:
Nim XD
2024-08-27 21:01:33 +05:30
parent 99eaf514fd
commit 121a1b7c73
31803 changed files with 623461 additions and 623399 deletions

View File

@@ -1,125 +1,125 @@
using System;
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
public class Inventory : MonoBehaviour
{
public Transform inventorySlotsParent;
public InventoryItemsCollection lootData;
public InventoryManager inventoryManager;
playerNetwork playerNet;
void Awake(){
playerNet = GetComponent<playerNetwork>();
}
private void UseItem(int index){
if(playerNet.health >= 100){
return;
}
RemoveItem(lootData.items[index].type);
switch(lootData.items[index].type){
case "apple" :
playerNet.SetHealth(playerNet.health + 10 );
break;
case "potion" :
playerNet.SetHealth(playerNet.health + 35 );
break;
case "potion2" :
playerNet.SetHealth(playerNet.health + 25 );
break;
case "meat" :
playerNet.SetHealth(playerNet.health + 40 );
break;
case "strawberry" :
playerNet.SetHealth(playerNet.health + 5 );
break;
//
}
}
void DropItem(int index){
Debug.Log("Dropping item " + index);
if(RemoveItem(lootData.items[index].type)){
playerNet.DropPickup(lootData.items[index].type);
}else{
Debug.Log("No items to drop in slot " + index);
}
}
public void AddItem(string type){
inventoryManager.AddInvItem(type);
return;
foreach(item loot in lootData.items){
if(loot.type == type){
loot.count++;
break;
}
}
UpdateUI();
playerNet.SavePlayerData();
}
public bool RemoveItem(string type){
playerNet.SavePlayerData();
foreach(item loot in lootData.items){
if(loot.type == type){
if(loot.count <=0){return false;}
loot.count--;
break;
}
}
UpdateUI();
return true;
}
public int GetStock(string type){
int count =0;
foreach(item loot in lootData.items){
if(loot.type == type){
count = loot.count;
break;
}
}
UpdateUI();
return count;
}
public void UpdateUI(){
// for(int i =0; i < inventorySlotsParent.childCount; i++){
// Sprite chosenSprite = null;
// if(i < lootData.items.Length){
// chosenSprite= (lootData.items[i].count >0) ? lootData.items[i].image : null;
// }
// inventorySlotsParent.GetChild(i).GetChild(0).GetComponent<Image>().sprite = chosenSprite;
// inventorySlotsParent.GetChild(i).GetChild(0).gameObject.SetActive(chosenSprite != null);
// inventorySlotsParent.GetChild(i).GetChild(2).GetComponent<TMP_Text>().text = chosenSprite != null ? lootData.items[i].count.ToString() : "";
// }
}
}
[Serializable]
public class LootData{
public string type;
public Sprite image;
public GameObject prefab;
public int count;
public int spawnProbability = 50;
using System;
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
public class Inventory : MonoBehaviour
{
public Transform inventorySlotsParent;
public InventoryItemsCollection lootData;
public InventoryManager inventoryManager;
playerNetwork playerNet;
void Awake(){
playerNet = GetComponent<playerNetwork>();
}
private void UseItem(int index){
if(playerNet.health >= 100){
return;
}
RemoveItem(lootData.items[index].type);
switch(lootData.items[index].type){
case "apple" :
playerNet.SetHealth(playerNet.health + 10 );
break;
case "potion" :
playerNet.SetHealth(playerNet.health + 35 );
break;
case "potion2" :
playerNet.SetHealth(playerNet.health + 25 );
break;
case "meat" :
playerNet.SetHealth(playerNet.health + 40 );
break;
case "strawberry" :
playerNet.SetHealth(playerNet.health + 5 );
break;
//
}
}
void DropItem(int index){
Debug.Log("Dropping item " + index);
if(RemoveItem(lootData.items[index].type)){
playerNet.DropPickup(lootData.items[index].type);
}else{
Debug.Log("No items to drop in slot " + index);
}
}
public void AddItem(string type){
inventoryManager.AddInvItem(type);
return;
foreach(item loot in lootData.items){
if(loot.type == type){
loot.count++;
break;
}
}
UpdateUI();
playerNet.SavePlayerData();
}
public bool RemoveItem(string type){
playerNet.SavePlayerData();
foreach(item loot in lootData.items){
if(loot.type == type){
if(loot.count <=0){return false;}
loot.count--;
break;
}
}
UpdateUI();
return true;
}
public int GetStock(string type){
int count =0;
foreach(item loot in lootData.items){
if(loot.type == type){
count = loot.count;
break;
}
}
UpdateUI();
return count;
}
public void UpdateUI(){
// for(int i =0; i < inventorySlotsParent.childCount; i++){
// Sprite chosenSprite = null;
// if(i < lootData.items.Length){
// chosenSprite= (lootData.items[i].count >0) ? lootData.items[i].image : null;
// }
// inventorySlotsParent.GetChild(i).GetChild(0).GetComponent<Image>().sprite = chosenSprite;
// inventorySlotsParent.GetChild(i).GetChild(0).gameObject.SetActive(chosenSprite != null);
// inventorySlotsParent.GetChild(i).GetChild(2).GetComponent<TMP_Text>().text = chosenSprite != null ? lootData.items[i].count.ToString() : "";
// }
}
}
[Serializable]
public class LootData{
public string type;
public Sprite image;
public GameObject prefab;
public int count;
public int spawnProbability = 50;
}

View File

@@ -1,11 +1,11 @@
fileFormatVersion: 2
guid: 49c91741a6de5437a88e05174cb996c0
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 49c91741a6de5437a88e05174cb996c0
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -67,8 +67,9 @@ public class ItemInventory : MonoBehaviour, IBeginDragHandler, IDragHandler, IEn
public void OnPointerClick(PointerEventData eventData)
{
//inventoryManager.SelectItem(item);
//inventoryManager.SelectItem(item);
if (item.isUsable == false)return;
if (inventoryManager.UseItem(item))
{
Destroy(gameObject);

View File

@@ -8,7 +8,8 @@ using UnityEngine.UI;
public class item : ScriptableObject
{
public string type;
public Sprite image;
public bool isUsable;
public Sprite image;
public GameObject prefab;
public int count;
public int spawnProbability = 50;