mirror of
				https://github.com/DerTyp7/example-top-down-unity.git
				synced 2025-10-30 04:47:09 +01:00 
			
		
		
		
	i
This commit is contained in:
		| @@ -24,9 +24,9 @@ public class Inventory : MonoBehaviour | ||||
|  | ||||
|     public Item testItemType; | ||||
|  | ||||
|     public static Action OnInventoryChanged; | ||||
|     public static Action OnItemAdded; | ||||
|     public static Action OnItemRemoved; | ||||
|     public static Action OnPlayerInventoryChanged; | ||||
|     public static Action OnPlayerItemAdded; | ||||
|     public static Action OnPlayerItemRemoved; | ||||
|  | ||||
|     [Header("Inventory")] | ||||
|     [SerializeField] | ||||
| @@ -35,16 +35,22 @@ public class Inventory : MonoBehaviour | ||||
|     [SerializeField] | ||||
|     int maxSpaceOfSlots = 10; | ||||
|  | ||||
|     [SerializeField] | ||||
|     bool isPlayerInventory = true; | ||||
|  | ||||
|     [SerializeField] | ||||
|     List<Slot> inventory = new List<Slot>(); | ||||
|  | ||||
|     public List<Slot> GetInventory() => inventory; | ||||
|  | ||||
|     public void AddSlots(int _numberOfSlots) | ||||
|     { | ||||
|         for (int i = 0; i < _numberOfSlots; i++) | ||||
|         { | ||||
|             inventory.Add(new Slot()); | ||||
|         } | ||||
|         OnInventoryChanged?.Invoke(); | ||||
|         if(isPlayerInventory) | ||||
|             OnPlayerInventoryChanged?.Invoke(); | ||||
|     } | ||||
|     Slot GetEmptySlot() | ||||
|     { | ||||
| @@ -143,8 +149,13 @@ public class Inventory : MonoBehaviour | ||||
|                 rest = count - slot.GetCount(); | ||||
|                 slot.Clear(); | ||||
|             } | ||||
|             OnInventoryChanged?.Invoke(); | ||||
|             OnItemRemoved?.Invoke(); | ||||
|  | ||||
|             if (isPlayerInventory) | ||||
|             { | ||||
|                 OnPlayerInventoryChanged?.Invoke(); | ||||
|                 OnPlayerItemRemoved?.Invoke(); | ||||
|             } | ||||
|              | ||||
|             return rest; | ||||
|         } | ||||
|         else | ||||
| @@ -204,8 +215,12 @@ public class Inventory : MonoBehaviour | ||||
|         else | ||||
|             return -1; | ||||
|  | ||||
|         OnInventoryChanged?.Invoke(); | ||||
|         OnItemAdded?.Invoke(); | ||||
|         if (isPlayerInventory) | ||||
|         { | ||||
|             OnPlayerInventoryChanged?.Invoke(); | ||||
|             OnPlayerItemAdded?.Invoke(); | ||||
|         } | ||||
|         | ||||
|         return rest; | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -13,6 +13,7 @@ public class Slot | ||||
|     int count = 0; | ||||
|  | ||||
|     public Item GetItem() => item; | ||||
|     public void SetItem(Item _item) => item = _item; | ||||
|  | ||||
|     public int GetCount() => count; | ||||
|     | ||||
| @@ -38,7 +39,14 @@ public class Slot | ||||
|         item = null; | ||||
|         count = 0; | ||||
|     } | ||||
|     public Slot Copy() | ||||
|     { | ||||
|         Slot slot = new Slot(); | ||||
|         slot.SetCount(count); | ||||
|         slot.SetItem(item); | ||||
|  | ||||
|         return slot; | ||||
|     } | ||||
|     public void Set(Item _item, int _count = 1) | ||||
|     { | ||||
|         item = _item; | ||||
|   | ||||
| @@ -6,14 +6,15 @@ using UnityEngine.UI; | ||||
|  | ||||
| public class UI_Inventory : MonoBehaviour | ||||
| { | ||||
|  /*   Inventory playerInventory; | ||||
|     [SerializeField] | ||||
|     Inventory inventory; | ||||
|     public Transform inventoryContainer; | ||||
|     public Transform itemSlotTemplate; | ||||
|     private RectTransform[] UIItemSlots; | ||||
|     private Button[] buttons; | ||||
|     private Slot pickedItem = new Slot(); | ||||
|     private RectTransform pickedItemSlot; | ||||
|     private void Awake() | ||||
|     private void Start() | ||||
|     { | ||||
|         //itemSlotTemplate = inventoryContainer.Find("containerTemplate"); | ||||
|         pickedItemSlot = Instantiate(itemSlotTemplate, this.transform).GetComponent<RectTransform>(); | ||||
| @@ -21,8 +22,8 @@ public class UI_Inventory : MonoBehaviour | ||||
|  | ||||
|     void pickItem(int index)  | ||||
|     { | ||||
|         pickedItem = playerInventory.getInventory[index].copy(); | ||||
|         playerInventory.getInventory[index].clear(); | ||||
|         pickedItem = inventory.GetInventory()[index].Copy(); | ||||
|         inventory.GetInventory()[index].Clear(); | ||||
|         UIItemSlots[index].GetChild(0).Find("Icon").gameObject.SetActive(false); | ||||
|     } | ||||
|     void placeItem()  | ||||
| @@ -31,18 +32,18 @@ public class UI_Inventory : MonoBehaviour | ||||
|     } | ||||
|     public void buttonEvent(int index)  | ||||
|     { | ||||
|         if (pickedItem.ItemType == null && playerInventory.getInventory[index].ItemType != null) | ||||
|         if (pickedItem.GetItem() == null && inventory.GetInventory()[index].GetItem() != null) | ||||
|         { | ||||
|             pickItem(index); | ||||
|         } | ||||
|         else | ||||
|         { | ||||
|             if (pickedItem.ItemType != null)  | ||||
|             if (pickedItem.GetItem() != null)  | ||||
|             { | ||||
|                 int rest = playerInventory.addItemAt(index, pickedItem.ItemType, pickedItem.Count); | ||||
|                 int rest = inventory.Add(pickedItem.GetItem(), pickedItem.GetCount(), index); | ||||
|                 if (rest == 0) | ||||
|                 { | ||||
|                     pickedItem.clear(); | ||||
|                     pickedItem.Clear(); | ||||
|                 } | ||||
|                 else | ||||
|                 { | ||||
| @@ -57,7 +58,6 @@ public class UI_Inventory : MonoBehaviour | ||||
|     } | ||||
|     public void setInventory(Inventory inventory)  | ||||
|     { | ||||
|         playerInventory = inventory; | ||||
|         inventory.onItemChangedCallback += updateInventory; | ||||
|         updateInventory(); | ||||
|     } | ||||
| @@ -98,10 +98,10 @@ public class UI_Inventory : MonoBehaviour | ||||
|             } | ||||
|         } | ||||
|          | ||||
|         UIItemSlots = new RectTransform[playerInventory.getInventory.Count]; | ||||
|         buttons = new Button[playerInventory.getInventory.Count]; | ||||
|         UIItemSlots = new RectTransform[inventory.Count]; | ||||
|         buttons = new Button[inventory.Count]; | ||||
|         //inventoryContainer.GetComponent<RectTransform>(). | ||||
|         foreach (Slot slot in playerInventory.getInventory)  | ||||
|         foreach (Slot slot in inventory)  | ||||
|         { | ||||
|             RectTransform itemSlotRectTransform = Instantiate(itemSlotTemplate, inventoryContainer).GetComponent<RectTransform>(); | ||||
|             buttons[index] = itemSlotRectTransform.Find("Button").GetComponent<Button>(); | ||||
| @@ -111,16 +111,16 @@ public class UI_Inventory : MonoBehaviour | ||||
|             itemSlotRectTransform.gameObject.SetActive(true); | ||||
|             itemSlotRectTransform.gameObject.name = "ItemSlot" + index; | ||||
|  | ||||
|             if (slot.ItemType != null)  | ||||
|             if (slot.GetItem() != null)  | ||||
|             { | ||||
|                 Transform item = itemSlotRectTransform.GetChild(0).Find("Icon"); | ||||
|                 Transform itemCount = itemSlotRectTransform.GetChild(0).Find("Count"); | ||||
|                 item.gameObject.SetActive(true); | ||||
|                 item.GetComponent<Image>().sprite = slot.ItemType.sprite; | ||||
|                 if (slot.Count > 1)  | ||||
|                 item.GetComponent<Image>().sprite = slot.GetItem().sprite; | ||||
|                 if (slot.GetCount() > 1)  | ||||
|                 { | ||||
|                     itemCount.gameObject.SetActive(true); | ||||
|                     itemCount.GetComponent<TextMeshProUGUI>().text = slot.Count.ToString(); | ||||
|                     itemCount.GetComponent<TextMeshProUGUI>().text = slot.GetCount().ToString(); | ||||
|                 } | ||||
|             } | ||||
|             x++; | ||||
| @@ -132,5 +132,5 @@ public class UI_Inventory : MonoBehaviour | ||||
|             UIItemSlots[index] = itemSlotRectTransform; | ||||
|             index++; | ||||
|         } | ||||
|     }*/ | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -12,10 +12,11 @@ public class TimeUI : MonoBehaviour | ||||
|     private void Start() | ||||
|     { | ||||
|         timeManager = GameObject.Find("GameManager").GetComponent<TimeManager>(); | ||||
|         TimeManager.OnTimeInterval += OnInterval; | ||||
|          | ||||
|     } | ||||
|  | ||||
|     private void Update() | ||||
|     void OnInterval() | ||||
|     { | ||||
|         DateTime dateTime = timeManager.GetDateTime(); | ||||
|         if (dateTimeText != null) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Janis M
					Janis M