Merge branch 'dhain' into develop
# Conflicts: # Assets/Scenes/MainScene.unity # Assets/Scripts/PlayerController.cs
This commit is contained in:
commit
7a04d79aba
118 changed files with 14104 additions and 135 deletions
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();
|
||||
}
|
||||
}
|
||||
35
Assets/Scripts/InventorySlot.cs
Normal file
35
Assets/Scripts/InventorySlot.cs
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class InventorySlot : MonoBehaviour {
|
||||
public Image icon;
|
||||
|
||||
private Item _item;
|
||||
|
||||
public void AddItem(Item newItem) {
|
||||
_item = newItem;
|
||||
|
||||
icon.sprite = _item.defaultSprite;
|
||||
icon.enabled = true;
|
||||
}
|
||||
|
||||
public void ClearSlot() {
|
||||
_item = null;
|
||||
icon.sprite = null;
|
||||
icon.enabled = false;
|
||||
}
|
||||
|
||||
public void RemoveItem() {
|
||||
Inventory.instance.items.Remove(_item);
|
||||
}
|
||||
|
||||
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,5 +1,5 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 641048df0d7668f48a857c454e2bd320
|
||||
guid: 92863b15e86b5b94e9a331f3c97dddca
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
35
Assets/Scripts/InventoryUI.cs
Normal file
35
Assets/Scripts/InventoryUI.cs
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
public class InventoryUI : MonoBehaviour {
|
||||
|
||||
public Transform itemsParent;
|
||||
public GameObject inventoryUI;
|
||||
private Inventory _inventory;
|
||||
private InventorySlot[] _slots;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start() {
|
||||
_inventory = Inventory.instance;
|
||||
_inventory.onItemChangedCallback += UpdateUI;
|
||||
|
||||
_slots = itemsParent.GetComponentsInChildren<InventorySlot>();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update() {
|
||||
if(Input.GetButtonDown("Inventory")) {
|
||||
inventoryUI.SetActive(!inventoryUI.activeSelf);
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
fileFormatVersion: 2
|
||||
guid: b08796f3a5662aa43a460c7ddd6796b3
|
||||
guid: 07c8392e636669644a90cebd609eaf5a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
|
|
@ -1,11 +1,10 @@
|
|||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
public class Item : MonoBehaviour, IComparable<Item> {
|
||||
private readonly string displayName;
|
||||
private readonly string description;
|
||||
private 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;
|
||||
|
||||
|
|
@ -13,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,5 +1,5 @@
|
|||
fileFormatVersion: 2
|
||||
guid: bd6385a1b78fe80479618d50cf5ff510
|
||||
guid: 254b144606ebc994589f639e82f06591
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
|
|
|
|||
|
|
@ -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,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,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){}
|
||||
}
|
||||
}
|
||||
8
Assets/Scripts/Items/TerraformingTools.meta
Normal file
8
Assets/Scripts/Items/TerraformingTools.meta
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 3e2b622f17cf8c54c96818c5850d4c76
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
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,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:
|
||||
|
|
@ -4,42 +4,40 @@ using System.Collections.Generic;
|
|||
using UnityEngine;
|
||||
|
||||
public class PlayerController : MonoBehaviour {
|
||||
private Dictionary<Item, int> inventory;
|
||||
private int money;
|
||||
private UsableItem selectedItem;
|
||||
#region Singleton
|
||||
|
||||
public UsableItem SelectedItem => selectedItem;
|
||||
public static PlayerController instance;
|
||||
|
||||
private static PlayerController instance;
|
||||
|
||||
public int startMoney = 100;
|
||||
private void Awake() {
|
||||
if(instance != null) {
|
||||
Debug.LogWarning("More than one instance of PlayerController found");
|
||||
}
|
||||
|
||||
public static PlayerController getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
inventory ??= new Dictionary<Item, int>();
|
||||
money = startMoney;
|
||||
instance = this;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
#endregion
|
||||
|
||||
public Inventory inventory;
|
||||
private int money;
|
||||
private UsableItem selectedItem;
|
||||
|
||||
public int startMoney = 100;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start() {
|
||||
money = startMoney;
|
||||
}
|
||||
|
||||
public void setSelectedItem(UsableItem item) {
|
||||
if (inventory.ContainsKey(item)) {
|
||||
// Update is called once per frame
|
||||
void Update() { }
|
||||
|
||||
public void SetSelectedItem(UsableItem item) {
|
||||
if(inventory.items.ContainsKey(item)) {
|
||||
selectedItem = item;
|
||||
Cursor.SetCursor(item.defaultSprite.texture, Vector2.zero, CursorMode.Auto);
|
||||
Cursor.SetCursor(item.defaultSprite.texture, Vector2.zero, CursorMode.Auto);
|
||||
} else {
|
||||
Debug.Log("An item requested to select isn't in the inventory" + item);
|
||||
Debug.Log("An item requested to select isn't in the inventory" + item);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 7e19228f49932534e8af0218c51e5c63
|
||||
guid: b18feac5270242d4a85c78ce72972d56
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
fileFormatVersion: 2
|
||||
guid: aa6ceecfb09ac614997702b2caf66e33
|
||||
guid: 3fd8bc1d313319d4f89f11548ccb1b6a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
8
Assets/Scripts/Tiles.meta
Normal file
8
Assets/Scripts/Tiles.meta
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 5e750377f5419b7409015c1dac98c88e
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
11
Assets/Scripts/Tiles/BaseTile.cs.meta
Normal file
11
Assets/Scripts/Tiles/BaseTile.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 2619a266d1f1c0c468e81e5bfda1cd78
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
11
Assets/Scripts/Tiles/FarmlandTile.cs.meta
Normal file
11
Assets/Scripts/Tiles/FarmlandTile.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 5b78d95148d53bd4aa70e3d0d595ab93
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 9a992c82c9da0cd4f8759894ddfd5fb3
|
||||
guid: af8926946929c0644a4fbbe9d92b2729
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
11
Assets/Scripts/Tiles/WaterTile.cs.meta
Normal file
11
Assets/Scripts/Tiles/WaterTile.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: e1921bfec5aa63e44a32c0492c021809
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -2,26 +2,19 @@ using System.Collections;
|
|||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class UsableItem : Item, IUsable
|
||||
{
|
||||
public class UsableItem : Item, IUsable {
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
||||
void Start() {
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
void Update() {
|
||||
}
|
||||
|
||||
public UsableItem(string displayName, string description, int id) : base(displayName, description, id)
|
||||
{
|
||||
}
|
||||
|
||||
public void select()
|
||||
{
|
||||
PlayerController.getInstance().setSelectedItem(this);
|
||||
}
|
||||
public UsableItem(string displayName, string description, int id) : base(displayName, description, id) {
|
||||
}
|
||||
|
||||
public void select() {
|
||||
PlayerController.instance.SetSelectedItem(this);
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/UsableItem.cs.meta
Normal file
11
Assets/Scripts/UsableItem.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 761f645f009328845bc7851753024e92
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Loading…
Add table
Add a link
Reference in a new issue