diesmal wirklich
This commit is contained in:
parent
25f51c2622
commit
2ff7fc2c12
20 changed files with 247 additions and 194 deletions
|
|
@ -201,7 +201,7 @@ MonoBehaviour:
|
|||
m_Calls:
|
||||
- m_Target: {fileID: 8059809276634721085}
|
||||
m_TargetAssemblyTypeName: InventorySlot, Assembly-CSharp
|
||||
m_MethodName: useItem
|
||||
m_MethodName: UseItem
|
||||
m_Mode: 1
|
||||
m_Arguments:
|
||||
m_ObjectArgument: {fileID: 0}
|
||||
|
|
|
|||
|
|
@ -1499,7 +1499,7 @@ RectTransform:
|
|||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
m_AnchorMin: {x: 0.5, y: 0.5}
|
||||
m_AnchorMax: {x: 0.5, y: 0.5}
|
||||
m_AnchoredPosition: {x: -537.5, y: 251}
|
||||
m_AnchoredPosition: {x: -268, y: 152}
|
||||
m_SizeDelta: {x: 100, y: 100}
|
||||
m_Pivot: {x: 0.5, y: 0.5}
|
||||
--- !u!114 &857317350
|
||||
|
|
@ -1546,12 +1546,12 @@ MonoBehaviour:
|
|||
m_OnClick:
|
||||
m_PersistentCalls:
|
||||
m_Calls:
|
||||
- m_Target: {fileID: 888561712}
|
||||
m_TargetAssemblyTypeName: InventorySlot, Assembly-CSharp
|
||||
m_MethodName: addItem
|
||||
- m_Target: {fileID: 1179703187}
|
||||
m_TargetAssemblyTypeName: Inventory, Assembly-CSharp
|
||||
m_MethodName: tempAddItem
|
||||
m_Mode: 2
|
||||
m_Arguments:
|
||||
m_ObjectArgument: {fileID: 990796751}
|
||||
m_ObjectArgument: {fileID: 11400000, guid: 55fbb48b3a41c1049af9b40f3fd35db1, type: 2}
|
||||
m_ObjectArgumentAssemblyTypeName: Item, Assembly-CSharp
|
||||
m_IntArgument: 0
|
||||
m_FloatArgument: 0
|
||||
|
|
@ -1703,17 +1703,6 @@ RectTransform:
|
|||
m_CorrespondingSourceObject: {fileID: 3510585822996971025, guid: 44dae5fbdb6f7df4f93a10807f66956f, type: 3}
|
||||
m_PrefabInstance: {fileID: 3510585823742910013}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
--- !u!114 &888561712 stripped
|
||||
MonoBehaviour:
|
||||
m_CorrespondingSourceObject: {fileID: 8059809276634721085, guid: 44dae5fbdb6f7df4f93a10807f66956f, type: 3}
|
||||
m_PrefabInstance: {fileID: 3510585823742910013}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 0}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 92863b15e86b5b94e9a331f3c97dddca, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
--- !u!1 &897590124
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
|
@ -1750,7 +1739,7 @@ RectTransform:
|
|||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
m_AnchorMin: {x: 1, y: 0}
|
||||
m_AnchorMax: {x: 1, y: 0}
|
||||
m_AnchoredPosition: {x: -587.5, y: 215.38048}
|
||||
m_AnchoredPosition: {x: -348, y: 107}
|
||||
m_SizeDelta: {x: 720, y: 430}
|
||||
m_Pivot: {x: 0.5, y: 0.5}
|
||||
--- !u!222 &897590126
|
||||
|
|
@ -2065,6 +2054,139 @@ PrefabInstance:
|
|||
objectReference: {fileID: 0}
|
||||
m_RemovedComponents: []
|
||||
m_SourcePrefab: {fileID: 100100000, guid: 44dae5fbdb6f7df4f93a10807f66956f, type: 3}
|
||||
--- !u!1 &1031413640
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 1031413641}
|
||||
- component: {fileID: 1031413644}
|
||||
- component: {fileID: 1031413643}
|
||||
- component: {fileID: 1031413642}
|
||||
m_Layer: 5
|
||||
m_Name: tempButton (1)
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!224 &1031413641
|
||||
RectTransform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1031413640}
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 1940090458}
|
||||
m_RootOrder: 2
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
m_AnchorMin: {x: 0.5, y: 0.5}
|
||||
m_AnchorMax: {x: 0.5, y: 0.5}
|
||||
m_AnchoredPosition: {x: -156, y: 144}
|
||||
m_SizeDelta: {x: 100, y: 100}
|
||||
m_Pivot: {x: 0.5, y: 0.5}
|
||||
--- !u!114 &1031413642
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1031413640}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 4e29b1a8efbd4b44bb3f3716e73f07ff, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
m_Navigation:
|
||||
m_Mode: 0
|
||||
m_WrapAround: 0
|
||||
m_SelectOnUp: {fileID: 0}
|
||||
m_SelectOnDown: {fileID: 0}
|
||||
m_SelectOnLeft: {fileID: 0}
|
||||
m_SelectOnRight: {fileID: 0}
|
||||
m_Transition: 1
|
||||
m_Colors:
|
||||
m_NormalColor: {r: 1, g: 1, b: 1, a: 1}
|
||||
m_HighlightedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1}
|
||||
m_PressedColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 1}
|
||||
m_SelectedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1}
|
||||
m_DisabledColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 0.5019608}
|
||||
m_ColorMultiplier: 1
|
||||
m_FadeDuration: 0.1
|
||||
m_SpriteState:
|
||||
m_HighlightedSprite: {fileID: 0}
|
||||
m_PressedSprite: {fileID: 0}
|
||||
m_SelectedSprite: {fileID: 0}
|
||||
m_DisabledSprite: {fileID: 0}
|
||||
m_AnimationTriggers:
|
||||
m_NormalTrigger: Normal
|
||||
m_HighlightedTrigger: Highlighted
|
||||
m_PressedTrigger: Pressed
|
||||
m_SelectedTrigger: Selected
|
||||
m_DisabledTrigger: Disabled
|
||||
m_Interactable: 1
|
||||
m_TargetGraphic: {fileID: 1031413643}
|
||||
m_OnClick:
|
||||
m_PersistentCalls:
|
||||
m_Calls:
|
||||
- m_Target: {fileID: 1179703187}
|
||||
m_TargetAssemblyTypeName: Inventory, Assembly-CSharp
|
||||
m_MethodName: tempAddItem
|
||||
m_Mode: 2
|
||||
m_Arguments:
|
||||
m_ObjectArgument: {fileID: 11400000, guid: 03bae48711a435b4bb9c1892438a3b3a, type: 2}
|
||||
m_ObjectArgumentAssemblyTypeName: Item, Assembly-CSharp
|
||||
m_IntArgument: 0
|
||||
m_FloatArgument: 0
|
||||
m_StringArgument:
|
||||
m_BoolArgument: 0
|
||||
m_CallState: 2
|
||||
--- !u!114 &1031413643
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1031413640}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
m_Material: {fileID: 0}
|
||||
m_Color: {r: 1, g: 1, b: 1, a: 1}
|
||||
m_RaycastTarget: 1
|
||||
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
|
||||
m_Maskable: 1
|
||||
m_OnCullStateChanged:
|
||||
m_PersistentCalls:
|
||||
m_Calls: []
|
||||
m_Sprite: {fileID: 21300008, guid: 377d0838804322045b60e51d883c3c1c, type: 3}
|
||||
m_Type: 0
|
||||
m_PreserveAspect: 0
|
||||
m_FillCenter: 1
|
||||
m_FillMethod: 4
|
||||
m_FillAmount: 1
|
||||
m_FillClockwise: 1
|
||||
m_FillOrigin: 0
|
||||
m_UseSpriteMesh: 0
|
||||
m_PixelsPerUnitMultiplier: 1
|
||||
--- !u!222 &1031413644
|
||||
CanvasRenderer:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1031413640}
|
||||
m_CullTransparentMesh: 1
|
||||
--- !u!224 &1048061199 stripped
|
||||
RectTransform:
|
||||
m_CorrespondingSourceObject: {fileID: 3510585822996971025, guid: 44dae5fbdb6f7df4f93a10807f66956f, type: 3}
|
||||
|
|
@ -2565,6 +2687,7 @@ GameObject:
|
|||
m_Component:
|
||||
- component: {fileID: 1179703186}
|
||||
- component: {fileID: 1179703185}
|
||||
- component: {fileID: 1179703187}
|
||||
m_Layer: 0
|
||||
m_Name: PlayerController
|
||||
m_TagString: Untagged
|
||||
|
|
@ -2584,6 +2707,7 @@ MonoBehaviour:
|
|||
m_Script: {fileID: 11500000, guid: b18feac5270242d4a85c78ce72972d56, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
inventory: {fileID: 1179703187}
|
||||
startMoney: 100
|
||||
--- !u!4 &1179703186
|
||||
Transform:
|
||||
|
|
@ -2600,6 +2724,18 @@ Transform:
|
|||
m_Father: {fileID: 0}
|
||||
m_RootOrder: 1
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!114 &1179703187
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1179703184}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 938a668a83530b74a97d7a3f7eadbc33, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
--- !u!224 &1278879686 stripped
|
||||
RectTransform:
|
||||
m_CorrespondingSourceObject: {fileID: 3510585822996971025, guid: 44dae5fbdb6f7df4f93a10807f66956f, type: 3}
|
||||
|
|
@ -3609,6 +3745,7 @@ RectTransform:
|
|||
m_Children:
|
||||
- {fileID: 897590125}
|
||||
- {fileID: 857317349}
|
||||
- {fileID: 1031413641}
|
||||
m_Father: {fileID: 0}
|
||||
m_RootOrder: 4
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
|
|
|
|||
56
Assets/Scripts/Inventory.cs
Normal file
56
Assets/Scripts/Inventory.cs
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class Inventory : MonoBehaviour {
|
||||
#region Singleton
|
||||
|
||||
public static Inventory instance;
|
||||
|
||||
private void Awake() {
|
||||
if(instance != null) {
|
||||
Debug.LogWarning("More than one instance of Inventory found");
|
||||
}
|
||||
|
||||
instance = this;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public Dictionary<Item, int> items;
|
||||
public const int inventorySpace = 28;
|
||||
|
||||
public delegate void onItemChanged();
|
||||
public onItemChanged onItemChangedCallback;
|
||||
|
||||
private void Start() {
|
||||
items ??= new Dictionary<Item, int>();
|
||||
}
|
||||
|
||||
public void tempAddItem(Item item) {
|
||||
AddItem(item, 1);
|
||||
}
|
||||
|
||||
public void AddItem(Item item, int amount) {
|
||||
if(items.Count >= inventorySpace) {
|
||||
Debug.Log("Not enough inventory space!");
|
||||
return;
|
||||
}
|
||||
|
||||
if(!items.ContainsKey(item)) {
|
||||
items.Add(item, amount);
|
||||
} else {
|
||||
items[item] += amount;
|
||||
}
|
||||
|
||||
|
||||
onItemChangedCallback?.Invoke();
|
||||
}
|
||||
|
||||
public void removeItem(Item item, int amount) {
|
||||
items.Add(item, -amount);
|
||||
|
||||
onItemChangedCallback?.Invoke();
|
||||
}
|
||||
}
|
||||
|
|
@ -4,27 +4,32 @@ using UnityEngine.UI;
|
|||
public class InventorySlot : MonoBehaviour {
|
||||
public Image icon;
|
||||
|
||||
private Item item;
|
||||
private Item _item;
|
||||
|
||||
public void addItem(Item newItem) {
|
||||
item = newItem;
|
||||
public void AddItem(Item newItem) {
|
||||
_item = newItem;
|
||||
|
||||
icon.sprite = item.defaultSprite;
|
||||
icon.sprite = _item.defaultSprite;
|
||||
icon.enabled = true;
|
||||
}
|
||||
|
||||
public void clearSlot() {
|
||||
item = null;
|
||||
public void ClearSlot() {
|
||||
_item = null;
|
||||
icon.sprite = null;
|
||||
icon.enabled = false;
|
||||
}
|
||||
|
||||
public void removeItem() {
|
||||
PlayerController.instance.inventory.Remove(item);
|
||||
public void RemoveItem() {
|
||||
Inventory.instance.items.Remove(_item);
|
||||
}
|
||||
|
||||
public void useItem() {
|
||||
//TODO: use item
|
||||
Debug.Log("using " + item.displayName);
|
||||
public void UseItem() {
|
||||
if(_item.GetType() == typeof(UsableItem)) {
|
||||
((UsableItem) _item).select();
|
||||
Debug.Log("using " + _item.displayName);
|
||||
} else {
|
||||
Debug.Log("Item not usable " + _item.displayName);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -1,18 +1,19 @@
|
|||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
public class InventoryUI : MonoBehaviour {
|
||||
|
||||
public Transform itemsParent;
|
||||
public GameObject inventoryUI;
|
||||
private PlayerController playerController;
|
||||
private InventorySlot[] slots;
|
||||
private Inventory _inventory;
|
||||
private InventorySlot[] _slots;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start() {
|
||||
playerController = PlayerController.instance;
|
||||
playerController.onItemChangedCallback += updateUI;
|
||||
_inventory = Inventory.instance;
|
||||
_inventory.onItemChangedCallback += UpdateUI;
|
||||
|
||||
slots = itemsParent.GetComponentsInChildren<InventorySlot>();
|
||||
_slots = itemsParent.GetComponentsInChildren<InventorySlot>();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
|
|
@ -22,12 +23,12 @@ public class InventoryUI : MonoBehaviour {
|
|||
}
|
||||
}
|
||||
|
||||
private void updateUI() {
|
||||
for(int i = 0; i < slots.Length; i++) {
|
||||
if(i < playerController.inventory.Count) {
|
||||
// slots[i].addItem(playerController.inventory[i]); //TODO: dictionary "letztes" Item finden, Wie?!?!?!
|
||||
private void UpdateUI() {
|
||||
for(int i = 0; i < _slots.Length; i++) {
|
||||
if(i < _inventory.items.Count) {
|
||||
_slots[i].AddItem(_inventory.items.ElementAt(i).Key);
|
||||
} else {
|
||||
slots[i].clearSlot();
|
||||
_slots[i].ClearSlot();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,14 +1,10 @@
|
|||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
//TODO: Auf ScriptableItem umschreiben!!!!!!!!!!
|
||||
//
|
||||
//https://www.youtube.com/watch?v=YLhj7SfaxSE
|
||||
public class Item : MonoBehaviour, IComparable<Item> {
|
||||
public readonly string displayName;
|
||||
public readonly string description;
|
||||
public readonly int id; //TODO: create an actual ID System that makes snens
|
||||
public SpriteRenderer spriteRenderer;
|
||||
public class Item : ScriptableObject, IComparable<Item> {
|
||||
public string displayName;
|
||||
public string description;
|
||||
public int id; //TODO: create an actual ID System that makes snens
|
||||
public Sprite selectedSprite;
|
||||
public Sprite defaultSprite;
|
||||
|
||||
|
|
@ -16,7 +12,6 @@ public class Item : MonoBehaviour, IComparable<Item> {
|
|||
this.displayName = displayName;
|
||||
this.description = description;
|
||||
this.id = id;
|
||||
spriteRenderer.sprite ??= defaultSprite; // defaultSprite is set in UnityEditor
|
||||
}
|
||||
|
||||
public int CompareTo(Item other) {
|
||||
|
|
|
|||
|
|
@ -1,7 +0,0 @@
|
|||
using UnityEngine;
|
||||
|
||||
namespace Items {
|
||||
public class FishingRod : UsableItem {
|
||||
public FishingRod() : base("Fishing Rod", "Can be used to fish fishy fish.", 1) { }
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: b08796f3a5662aa43a460c7ddd6796b3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Items {
|
||||
public class Hoe : UsableItem {
|
||||
public Hoe() : base("Hoe", "Used to hoe the ground into farmland.", 2){}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: aa6ceecfb09ac614997702b2caf66e33
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Items {
|
||||
public class Scythe : UsableItem {
|
||||
public Scythe() : base("Scythe", "Used to cut down crops.", 3){}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 641048df0d7668f48a857c454e2bd320
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Items {
|
||||
public class WateringCan : UsableItem {
|
||||
public WateringCan():base("Watering Can", "Used to water planted crops.", 4){}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 7e19228f49932534e8af0218c51e5c63
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Items {
|
||||
public class Wheat : Item {
|
||||
public Wheat() : base("Wheat", "Wheat is a grass widely cultivated for its seed, a cereal grain which is a worldwide staple food.", 5){}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 207be0ed7f8f5714c97b7ac5deb8956d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Items {
|
||||
public class WheatSeed : UsableItem {
|
||||
public WheatSeed() : base("Wheat Seeds", "When planted on farmland, wheat will grow.", 6){}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 0808be748388ede4ba57db7d74401617
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -8,7 +8,7 @@ public class PlayerController : MonoBehaviour {
|
|||
|
||||
private void Awake() {
|
||||
if(instance != null) {
|
||||
Debug.LogWarning("More than one instance of PlayeController found");
|
||||
Debug.LogWarning("More than one instance of PlayerController found");
|
||||
}
|
||||
|
||||
instance = this;
|
||||
|
|
@ -16,8 +16,7 @@ public class PlayerController : MonoBehaviour {
|
|||
|
||||
#endregion
|
||||
|
||||
public Dictionary<Item, int> inventory;
|
||||
public readonly int inventorySpace = 28;
|
||||
public Inventory inventory;
|
||||
private int money;
|
||||
private UsableItem selectedItem;
|
||||
|
||||
|
|
@ -25,40 +24,18 @@ public class PlayerController : MonoBehaviour {
|
|||
|
||||
// Start is called before the first frame update
|
||||
void Start() {
|
||||
inventory ??= new Dictionary<Item, int>();
|
||||
money = startMoney;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update() { }
|
||||
|
||||
public void setSelectedItem(UsableItem item) {
|
||||
if(inventory.ContainsKey(item)) {
|
||||
public void SetSelectedItem(UsableItem item) {
|
||||
if(inventory.items.ContainsKey(item)) {
|
||||
selectedItem = item;
|
||||
Cursor.SetCursor(item.defaultSprite.texture, Vector2.zero, CursorMode.Auto);
|
||||
} else {
|
||||
Debug.Log("An item requested to select isn't in the inventory" + item);
|
||||
}
|
||||
}
|
||||
|
||||
public delegate void onItemChanged();
|
||||
|
||||
public onItemChanged onItemChangedCallback;
|
||||
|
||||
public void addItem(Item item, int amount) {
|
||||
if(inventory.Count >= inventorySpace) {
|
||||
Debug.Log("Not enough inventory space!");
|
||||
return;
|
||||
}
|
||||
|
||||
inventory.Add(item, amount);
|
||||
|
||||
onItemChangedCallback?.Invoke();
|
||||
}
|
||||
|
||||
public void removeItem(Item item, int amount) {
|
||||
inventory.Add(item, -amount);
|
||||
|
||||
onItemChangedCallback?.Invoke();
|
||||
}
|
||||
}
|
||||
|
|
@ -15,6 +15,6 @@ public class UsableItem : Item, IUsable {
|
|||
}
|
||||
|
||||
public void select() {
|
||||
PlayerController.instance.setSelectedItem(this);
|
||||
PlayerController.instance.SetSelectedItem(this);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue