From 770c4f751b83fcd15a85eb3be63be59f9bcac6fc Mon Sep 17 00:00:00 2001 From: darrelmarek Date: Thu, 19 Apr 2018 13:45:53 -0500 Subject: [PATCH] Basic inventory system --- MoCha/Assets/Prefabs/ItemSlot.prefab | Bin 0 -> 8184 bytes MoCha/Assets/Prefabs/ItemSlot.prefab.meta | 10 +++++ MoCha/Assets/Scripts/Inventory.cs | 37 ++++++++++++++++++ MoCha/Assets/Scripts/Inventory.cs.meta | 13 +++++++ MoCha/Assets/Scripts/InventoryEditor.cs | 39 +++++++++++++++++++ MoCha/Assets/Scripts/InventoryEditor.cs.meta | 13 +++++++ MoCha/Assets/Scripts/Item.cs | 7 ++++ MoCha/Assets/Scripts/Item.cs.meta | 13 +++++++ 8 files changed, 132 insertions(+) create mode 100644 MoCha/Assets/Prefabs/ItemSlot.prefab create mode 100644 MoCha/Assets/Prefabs/ItemSlot.prefab.meta create mode 100644 MoCha/Assets/Scripts/Inventory.cs create mode 100644 MoCha/Assets/Scripts/Inventory.cs.meta create mode 100644 MoCha/Assets/Scripts/InventoryEditor.cs create mode 100644 MoCha/Assets/Scripts/InventoryEditor.cs.meta create mode 100644 MoCha/Assets/Scripts/Item.cs create mode 100644 MoCha/Assets/Scripts/Item.cs.meta diff --git a/MoCha/Assets/Prefabs/ItemSlot.prefab b/MoCha/Assets/Prefabs/ItemSlot.prefab new file mode 100644 index 0000000000000000000000000000000000000000..141dc69335e7543ccf232f99f8736a054ba19442 GIT binary patch literal 8184 zcmdT|ZEO_B8J_d`i+oU;kCO0dzyT6m2Lnkc#q`dH0RsldHbiPg$ojlKFJA9DdwT~? zRk2Z(_D7mZm6C>rKY)^oeh5WX+mNU#{rXXqq>(B`Dp88)r_}stkq|U$mAKC{v$Nj4 zJ0m0dCu@y&=Gk|i_nmiU-g)PQxc8b6OFtAsd|HSF^Y9ky)^H8quL z0QQeG{!LB2?HzkB{mx&{=l=80WeZ>165I#$J(N0>i*+J+M2G-grqD!9h!p<5n-;;3 zQX;4al!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t3o-hWi^InkH^{r@0pKZ=@`=Oke|)+@97FvpA+{j>YUhrICUFl0 zCPVDwjn6;6e9a4~W59UVs004fW8cXg>Uc4A8V!vt@4Wjj>n`7wK8s^^HDq|&4*lxt zV=G^ppS~2sHXM6>)g5h%)6Ljq)Xlxte6{hbJ1#FtpNL`ea#OcGxp`@NBS!OTC`Y?l z&YbeR@54Jr`O=kBJk+wcO*I;{&$qv%b&qjRKO@TDo=r%5R!q4_W(> za(X^k*YicabV!$xA1ff&b%uM!je;p{`G4rwb4#6i?pfDsi28XhbKFX^^22O&*YbfL zKXvG}%Q_#*>vbZ5s(%5la??fge;IQ7xIDTY--zMl48qc~;^+2(f7m>9M4YbtLM z@_y0QlI+#ivY)pG*XitNU(3I?7WDH=p4sV`B`i3*t);ItWLx=N=H#F|W;&e??k!bT z5}<9|C$v}FsoxR~|Hb{G_qUeg`;+Jo?(yU5(2{=OP&t;H^#^(M6Ze~5N7`>%hVNQ( z@$YIq#gXatrBNLNYVcz{ig*dT{I*L77WJ)0zl2?S-nBmUrXBHTX1n52VLfhBjOWJe b((y9MKeJsjwnI1`)8g?Z$&+Z!%HID0E7UM< literal 0 HcmV?d00001 diff --git a/MoCha/Assets/Prefabs/ItemSlot.prefab.meta b/MoCha/Assets/Prefabs/ItemSlot.prefab.meta new file mode 100644 index 0000000..2e52d9b --- /dev/null +++ b/MoCha/Assets/Prefabs/ItemSlot.prefab.meta @@ -0,0 +1,10 @@ +fileFormatVersion: 2 +guid: ffb3a2b5c7f8d144f83ef1f1166b178f +timeCreated: 1524162403 +licenseType: Free +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 100100000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/MoCha/Assets/Scripts/Inventory.cs b/MoCha/Assets/Scripts/Inventory.cs new file mode 100644 index 0000000..24ce640 --- /dev/null +++ b/MoCha/Assets/Scripts/Inventory.cs @@ -0,0 +1,37 @@ +using UnityEngine; +using System.Collections; +using UnityEngine.UI; + + +public class Inventory : MonoBehaviour +{ + public Image[] itemImages = new Image[numItemSlots]; + public Item[] items = new Item[numItemSlots]; + public const int numItemSlots = 4; + public void AddItem(Item itemToAdd) + { + for (int i = 0; i < items.Length; i++) + { + if (items[i] == null) + { + items[i] = itemToAdd; + itemImages[i].sprite = itemToAdd.sprite; + itemImages[i].enabled = true; + return; + } + } + } + public void RemoveItem (Item itemToRemove) + { + for (int i = 0; i < items.Length; i++) + { + if (items[i] == itemToRemove) + { + items[i] = null; + itemImages[i].sprite = null; + itemImages[i].enabled = false; + return; + } + } + } +} \ No newline at end of file diff --git a/MoCha/Assets/Scripts/Inventory.cs.meta b/MoCha/Assets/Scripts/Inventory.cs.meta new file mode 100644 index 0000000..2e4bc3b --- /dev/null +++ b/MoCha/Assets/Scripts/Inventory.cs.meta @@ -0,0 +1,13 @@ +fileFormatVersion: 2 +guid: b43850ea4963ca144a2219ebc0e3b6fd +timeCreated: 1524161696 +licenseType: Free +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/MoCha/Assets/Scripts/InventoryEditor.cs b/MoCha/Assets/Scripts/InventoryEditor.cs new file mode 100644 index 0000000..46a379e --- /dev/null +++ b/MoCha/Assets/Scripts/InventoryEditor.cs @@ -0,0 +1,39 @@ +using UnityEngine; +using UnityEditor; +[CustomEditor(typeof(Inventory))] +public class InventoryEditor : Editor +{ + private bool[] showItemSlots = new bool[Inventory.numItemSlots]; + private SerializedProperty itemImagesProperty; + private SerializedProperty itemsProperty; + private const string inventoryPropItemImagesName = "itemImages"; + private const string inventoryPropItemsName = "items"; + private void OnEnable () + { + itemImagesProperty = serializedObject.FindProperty (inventoryPropItemImagesName); + itemsProperty = serializedObject.FindProperty (inventoryPropItemsName); + } + public override void OnInspectorGUI () + { + serializedObject.Update (); + for (int i = 0; i < Inventory.numItemSlots; i++) + { + ItemSlotGUI (i); + } + serializedObject.ApplyModifiedProperties (); + } + private void ItemSlotGUI (int index) + { + EditorGUILayout.BeginVertical (GUI.skin.box); + EditorGUI.indentLevel++; + + showItemSlots[index] = EditorGUILayout.Foldout (showItemSlots[index], "Item slot " + index); + if (showItemSlots[index]) + { + EditorGUILayout.PropertyField (itemImagesProperty.GetArrayElementAtIndex (index)); + EditorGUILayout.PropertyField (itemsProperty.GetArrayElementAtIndex (index)); + } + EditorGUI.indentLevel--; + EditorGUILayout.EndVertical (); + } +} \ No newline at end of file diff --git a/MoCha/Assets/Scripts/InventoryEditor.cs.meta b/MoCha/Assets/Scripts/InventoryEditor.cs.meta new file mode 100644 index 0000000..4c760c1 --- /dev/null +++ b/MoCha/Assets/Scripts/InventoryEditor.cs.meta @@ -0,0 +1,13 @@ +fileFormatVersion: 2 +guid: dd2ab8002901b644bbc724fa04249955 +timeCreated: 1524163165 +licenseType: Free +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/MoCha/Assets/Scripts/Item.cs b/MoCha/Assets/Scripts/Item.cs new file mode 100644 index 0000000..0dd481b --- /dev/null +++ b/MoCha/Assets/Scripts/Item.cs @@ -0,0 +1,7 @@ +using UnityEngine; + +[CreateAssetMenu] +public class Item : ScriptableObject { + + public Sprite sprite; +} diff --git a/MoCha/Assets/Scripts/Item.cs.meta b/MoCha/Assets/Scripts/Item.cs.meta new file mode 100644 index 0000000..7b1ca9b --- /dev/null +++ b/MoCha/Assets/Scripts/Item.cs.meta @@ -0,0 +1,13 @@ +fileFormatVersion: 2 +guid: 2b57d2e6ebe4089498537815ff9350ee +timeCreated: 1524162707 +licenseType: Free +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: