mirror of
				https://github.com/DerTyp7/example-top-down-unity.git
				synced 2025-10-30 12:57:08 +01:00 
			
		
		
		
	tool
This commit is contained in:
		| @@ -30,6 +30,8 @@ public class Inventory : MonoBehaviour | ||||
|     [SerializeField] | ||||
|     List<Slot> inventory = new List<Slot>(); | ||||
|  | ||||
|     public static Inventory PlayerInstance { get; private set; } // instance of PlayerInventory | ||||
|  | ||||
|     public List<Slot> GetInventory() => inventory; | ||||
|  | ||||
|     /// <summary> | ||||
| @@ -119,7 +121,7 @@ public class Inventory : MonoBehaviour | ||||
|     /// </summary> | ||||
|     /// <param name="index"></param> | ||||
|     /// <returns>True: Is in range. False: Is not in range.</returns> | ||||
|     bool IndexIsInRange(int index) | ||||
|     public bool IndexIsInRange(int index) | ||||
|     { | ||||
|         // Returns true if a given index is in the bounds of the inventory. | ||||
|         // Example (maxSize = 10) index = -10 : false , index =  100: false, index = 7 : true  | ||||
| @@ -260,9 +262,12 @@ public class Inventory : MonoBehaviour | ||||
|     } | ||||
|  | ||||
|  | ||||
|     void Start() | ||||
|     void Awake() | ||||
|     { | ||||
|         // Initialize Inventory Slots | ||||
|         AddSlots(numberOfSlots);         | ||||
|         AddSlots(numberOfSlots); | ||||
|  | ||||
|         if (isPlayerInventory) | ||||
|             PlayerInstance = this; | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -4,35 +4,39 @@ using UnityEngine; | ||||
|  | ||||
| public class InventoryController : MonoBehaviour | ||||
| { | ||||
|     /*[SerializeField] Item item1;// not needed | ||||
|     [SerializeField] Item item2;// not needed | ||||
|     public Inventory inventory; | ||||
|     [SerializeField] UI_Inventory uiInventory; | ||||
|     private void Awake() | ||||
|     { | ||||
|         inventory = transform.GetComponent<Inventory>(); | ||||
|         inventory.createEmptyInventory(8,10); | ||||
|          | ||||
|         inventory.addItemAt(0, item1, 8); | ||||
|         inventory.addItemAt(0, item1, 1); | ||||
|         inventory.addItemAt(3, item2, 15); | ||||
|         inventory.addItemAt(4, item1, 3); | ||||
|     [SerializeField] | ||||
|     int selectedSlotIndex; | ||||
|  | ||||
|         Debug.Log(inventory.addItemAt(0, item2, 15)); | ||||
|         Debug.Log(inventory.getInventory[0].Count); | ||||
|         Debug.Log(inventory.removeItemAt(0, 10)); | ||||
|         Debug.Log(inventory.getInventory[0].Count); | ||||
|          | ||||
|         uiInventory.setInventory(inventory); | ||||
|     Inventory inventory; | ||||
|  | ||||
|     public static InventoryController PlayerInstance { get; private set; } | ||||
|  | ||||
|     public Slot GetSelectedSlot() | ||||
|     { | ||||
|         return inventory.GetInventory()[selectedSlotIndex]; | ||||
|     } | ||||
|     void Start() | ||||
|     { | ||||
|  | ||||
|         PlayerInstance = this; | ||||
|         inventory = Inventory.PlayerInstance; | ||||
|         selectedSlotIndex = 0; | ||||
|     } | ||||
|  | ||||
|     // Update is called once per frame | ||||
|     void Update() | ||||
|     { | ||||
|  | ||||
|     }*/ | ||||
|         if (Input.GetAxis("Mouse ScrollWheel") < 0) | ||||
|         { | ||||
|             if (inventory.IndexIsInRange(selectedSlotIndex - 1)) | ||||
|             { | ||||
|                 selectedSlotIndex -= 1; | ||||
|             } | ||||
|         } | ||||
|         if (Input.GetAxis("Mouse ScrollWheel") > 0) | ||||
|         { | ||||
|             if (inventory.IndexIsInRange(selectedSlotIndex + 1)) | ||||
|             { | ||||
|                 selectedSlotIndex += 1; | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| } | ||||
|   | ||||
							
								
								
									
										20
									
								
								Assets/Scripts/Inventory/Items/Axe.asset
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								Assets/Scripts/Inventory/Items/Axe.asset
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,20 @@ | ||||
| %YAML 1.1 | ||||
| %TAG !u! tag:unity3d.com,2011: | ||||
| --- !u!114 &11400000 | ||||
| MonoBehaviour: | ||||
|   m_ObjectHideFlags: 0 | ||||
|   m_CorrespondingSourceObject: {fileID: 0} | ||||
|   m_PrefabInstance: {fileID: 0} | ||||
|   m_PrefabAsset: {fileID: 0} | ||||
|   m_GameObject: {fileID: 0} | ||||
|   m_Enabled: 1 | ||||
|   m_EditorHideFlags: 0 | ||||
|   m_Script: {fileID: 11500000, guid: c9a450f431b33414ab3a1f3b08250700, type: 3} | ||||
|   m_Name: Axe | ||||
|   m_EditorClassIdentifier:  | ||||
|   name: Axe | ||||
|   id: 3 | ||||
|   isStackable: 0 | ||||
|   sprite: {fileID: 21300000, guid: 475f050511847c0499c1ca4f47fcaefa, type: 3} | ||||
|   isSelected: 0 | ||||
|   toolType: 0 | ||||
							
								
								
									
										8
									
								
								Assets/Scripts/Inventory/Items/Axe.asset.meta
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								Assets/Scripts/Inventory/Items/Axe.asset.meta
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,8 @@ | ||||
| fileFormatVersion: 2 | ||||
| guid: 83d7c41047fbb504bb67f024912542e6 | ||||
| NativeFormatImporter: | ||||
|   externalObjects: {} | ||||
|   mainObjectFileID: 11400000 | ||||
|   userData:  | ||||
|   assetBundleName:  | ||||
|   assetBundleVariant:  | ||||
							
								
								
									
										19
									
								
								Assets/Scripts/Inventory/Items/Wood.asset
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								Assets/Scripts/Inventory/Items/Wood.asset
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,19 @@ | ||||
| %YAML 1.1 | ||||
| %TAG !u! tag:unity3d.com,2011: | ||||
| --- !u!114 &11400000 | ||||
| MonoBehaviour: | ||||
|   m_ObjectHideFlags: 0 | ||||
|   m_CorrespondingSourceObject: {fileID: 0} | ||||
|   m_PrefabInstance: {fileID: 0} | ||||
|   m_PrefabAsset: {fileID: 0} | ||||
|   m_GameObject: {fileID: 0} | ||||
|   m_Enabled: 1 | ||||
|   m_EditorHideFlags: 0 | ||||
|   m_Script: {fileID: 11500000, guid: 0fae7bba50a98204883e78d8d6c96fc2, type: 3} | ||||
|   m_Name: Wood | ||||
|   m_EditorClassIdentifier:  | ||||
|   name: Wood | ||||
|   id: 2 | ||||
|   isStackable: 1 | ||||
|   sprite: {fileID: 0} | ||||
|   isSelected: 0 | ||||
							
								
								
									
										8
									
								
								Assets/Scripts/Inventory/Items/Wood.asset.meta
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								Assets/Scripts/Inventory/Items/Wood.asset.meta
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,8 @@ | ||||
| fileFormatVersion: 2 | ||||
| guid: e6de4c0f524fecd418672a51c89d547e | ||||
| NativeFormatImporter: | ||||
|   externalObjects: {} | ||||
|   mainObjectFileID: 11400000 | ||||
|   userData:  | ||||
|   assetBundleName:  | ||||
|   assetBundleVariant:  | ||||
		Reference in New Issue
	
	Block a user
	 j.mei7
					j.mei7