Merge remote-tracking branch 'origin/develop' into develop
# Conflicts: # Assets/Scripts/TileBehaviour.cs
This commit is contained in:
commit
0ffbb31b39
17 changed files with 1009 additions and 246 deletions
|
|
@ -1,15 +1,17 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
public class HouseController : MonoBehaviour {
|
||||
private int dayCount = 0;
|
||||
private int dayCount = 1;
|
||||
private static UnityEvent newDayEvent;
|
||||
public static UnityEvent NewDayEvent => newDayEvent;
|
||||
|
||||
public Canvas menu;
|
||||
public TextMeshProUGUI dayCountTextMeshProUGUI;
|
||||
|
||||
private void OnMouseDown() {
|
||||
toggleMenu();
|
||||
|
|
@ -21,7 +23,7 @@ public class HouseController : MonoBehaviour {
|
|||
|
||||
public void newDay() {
|
||||
dayCount++;
|
||||
Debug.Log("New day: " + dayCount);
|
||||
dayCountTextMeshProUGUI.text = dayCount.ToString();
|
||||
newDayEvent?.Invoke();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class Inventory : MonoBehaviour {
|
||||
public class Inventory : ItemStorage {
|
||||
#region Singleton
|
||||
|
||||
public static Inventory instance;
|
||||
|
|
@ -16,51 +15,17 @@ public class Inventory : MonoBehaviour {
|
|||
|
||||
#endregion
|
||||
|
||||
public Dictionary<Item, int> items;
|
||||
public Item[] startItems;
|
||||
public const int InventorySpace = 28;
|
||||
|
||||
/**
|
||||
* Methods can be added to this and they will get called every time onItemChangedCallback gets Invoked
|
||||
*/
|
||||
public delegate void OnItemChanged();
|
||||
public OnItemChanged onItemChangedCallback;
|
||||
|
||||
private void Start() {
|
||||
items ??= new Dictionary<Item, int>();
|
||||
foreach(Item item in startItems) {
|
||||
AddItem(item, 1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the specified amount of items to the Inventory
|
||||
*/
|
||||
public void AddItem(Item item, int amount) {
|
||||
public override 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();
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the specified amount of items in the Inventory
|
||||
*/
|
||||
public void RemoveItem(Item item, int amount) {
|
||||
if(items[item] <= 0) {
|
||||
items.Remove(item);
|
||||
} else {
|
||||
items[item] -= amount;
|
||||
}
|
||||
|
||||
onItemChangedCallback?.Invoke();
|
||||
|
||||
base.AddItem(item, amount);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,72 +1,15 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class InventorySlot : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler {
|
||||
public Image icon;
|
||||
public TextMeshProUGUI amountText;
|
||||
|
||||
public Item _item;
|
||||
|
||||
#region DescriptionHover
|
||||
|
||||
public float timeToWait;
|
||||
|
||||
public void OnPointerEnter(PointerEventData eventData) {
|
||||
StopAllCoroutines();
|
||||
StartCoroutine(StartTimer());
|
||||
}
|
||||
|
||||
public void OnPointerExit(PointerEventData eventData) {
|
||||
StopAllCoroutines();
|
||||
HoverManager.onMouseExit();
|
||||
}
|
||||
|
||||
private void ShowMessage() {
|
||||
if(_item){
|
||||
HoverManager.onMouseHover(_item.description, Input.mousePosition);
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerator StartTimer() {
|
||||
yield return new WaitForSeconds(timeToWait);
|
||||
|
||||
ShowMessage();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/**
|
||||
* Sets the Item of the Inventory Slot
|
||||
*/
|
||||
public void AddItem(Item newItem) {
|
||||
_item = newItem;
|
||||
|
||||
icon.sprite = _item.defaultSprite;
|
||||
icon.enabled = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the Inventory Slot
|
||||
*/
|
||||
public void ClearSlot() {
|
||||
_item = null;
|
||||
icon.sprite = null;
|
||||
icon.enabled = false;
|
||||
}
|
||||
|
||||
public class InventorySlot : ItemStorageSlot {
|
||||
/**
|
||||
* Gets called when the Inventory Slot is clicked
|
||||
*/
|
||||
public void UseItem() {
|
||||
if(_item.GetType() == typeof(UsableItem)) {
|
||||
((UsableItem) _item).Select();
|
||||
Debug.Log("using " + _item.displayName);
|
||||
public override void UseItem() {
|
||||
if(Item.GetType() == typeof(UsableItem)) {
|
||||
((UsableItem) Item).Select();
|
||||
Debug.Log("using " + Item.displayName);
|
||||
} else {
|
||||
Debug.Log("Item not usable " + _item.displayName);
|
||||
Debug.Log("Item not usable " + Item.displayName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,3 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
|
|
|
|||
46
Assets/Scripts/ItemStorage.cs
Normal file
46
Assets/Scripts/ItemStorage.cs
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class ItemStorage : MonoBehaviour {
|
||||
public Dictionary<Item, int> items;
|
||||
public Item[] startItems;
|
||||
|
||||
/**
|
||||
* Methods can be added to this and they will get called every time onItemChangedCallback gets Invoked
|
||||
*/
|
||||
public delegate void OnItemChanged();
|
||||
public OnItemChanged onItemChangedCallback;
|
||||
|
||||
private void Start() {
|
||||
items ??= new Dictionary<Item, int>();
|
||||
foreach(Item item in startItems) {
|
||||
AddItem(item, 1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the specified amount of items to the Item Storage
|
||||
*/
|
||||
public virtual void AddItem(Item item, int amount) {
|
||||
if(!items.ContainsKey(item)) {
|
||||
items.Add(item, amount);
|
||||
} else {
|
||||
items[item] += amount;
|
||||
}
|
||||
|
||||
onItemChangedCallback?.Invoke();
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the specified amount of items in the Item Storage
|
||||
*/
|
||||
public void RemoveItem(Item item, int amount) {
|
||||
if(items[item] <= 0) {
|
||||
items.Remove(item);
|
||||
} else {
|
||||
items[item] -= amount;
|
||||
}
|
||||
|
||||
onItemChangedCallback?.Invoke();
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/ItemStorage.cs.meta
Normal file
11
Assets/Scripts/ItemStorage.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 21c02dc661faff342aca965c68c2c13a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
68
Assets/Scripts/ItemStorageSlot.cs
Normal file
68
Assets/Scripts/ItemStorageSlot.cs
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class ItemStorageSlot : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler {
|
||||
public Image icon;
|
||||
public TextMeshProUGUI amountText;
|
||||
|
||||
public Item Item => _item;
|
||||
|
||||
private Item _item;
|
||||
|
||||
#region DescriptionHover
|
||||
|
||||
public float timeToWait;
|
||||
|
||||
public void OnPointerEnter(PointerEventData eventData) {
|
||||
StopAllCoroutines();
|
||||
StartCoroutine(StartTimer());
|
||||
}
|
||||
|
||||
public void OnPointerExit(PointerEventData eventData) {
|
||||
StopAllCoroutines();
|
||||
HoverManager.onMouseExit();
|
||||
}
|
||||
|
||||
private void ShowMessage() {
|
||||
if(_item){
|
||||
HoverManager.onMouseHover(_item.description, Input.mousePosition);
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerator StartTimer() {
|
||||
yield return new WaitForSeconds(timeToWait);
|
||||
|
||||
ShowMessage();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/**
|
||||
* Sets the Item of the Item Storage Slot
|
||||
*/
|
||||
public void AddItem(Item newItem) {
|
||||
_item = newItem;
|
||||
|
||||
icon.sprite = _item.defaultSprite;
|
||||
icon.enabled = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the Item Storage Slot
|
||||
*/
|
||||
public virtual void ClearSlot() {
|
||||
_item = null;
|
||||
icon.sprite = null;
|
||||
icon.enabled = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets called when the Item Storage Slot is clicked
|
||||
*/
|
||||
public virtual void UseItem() {
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/ItemStorageSlot.cs.meta
Normal file
11
Assets/Scripts/ItemStorageSlot.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: b6f14e8c24660e04e9ceb50a7d8e659d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
using Cursor = UnityEngine.Cursor;
|
||||
|
|
@ -21,15 +22,19 @@ public class PlayerController : MonoBehaviour {
|
|||
#endregion
|
||||
|
||||
private Inventory _inventory;
|
||||
public int money;
|
||||
private int _money;
|
||||
private UsableItem _selectedItem;
|
||||
|
||||
public int startMoney = 100;
|
||||
public TextMeshProUGUI moneyTextMeshProUGUI;
|
||||
|
||||
public int Money => _money;
|
||||
|
||||
// Start is called before the first frame update
|
||||
private void Start() {
|
||||
money = startMoney;
|
||||
_money = startMoney;
|
||||
_inventory = Inventory.instance;
|
||||
moneyTextMeshProUGUI.text = _money + "µ";
|
||||
}
|
||||
|
||||
public void SetSelectedItem(UsableItem item) {
|
||||
|
|
@ -44,4 +49,9 @@ public class PlayerController : MonoBehaviour {
|
|||
public UsableItem GetSelectedItem() {
|
||||
return _selectedItem;
|
||||
}
|
||||
|
||||
public void ChangeMoney(int amount) {
|
||||
_money += amount;
|
||||
moneyTextMeshProUGUI.text = _money + "µ";
|
||||
}
|
||||
}
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class Shop : MonoBehaviour {
|
||||
public class Shop : ItemStorage {
|
||||
#region Singleton
|
||||
|
||||
public static Shop instance;
|
||||
|
|
@ -15,46 +15,4 @@ public class Shop : MonoBehaviour {
|
|||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public Dictionary<Item, int> items;
|
||||
public Item[] tempItems;
|
||||
|
||||
/**
|
||||
* Methods can be added to this and they will get called every time onItemChangedCallback gets Invoked
|
||||
*/
|
||||
public delegate void OnItemChanged();
|
||||
public OnItemChanged onItemChangedCallback;
|
||||
|
||||
private void Start() {
|
||||
items ??= new Dictionary<Item, int>();
|
||||
foreach(Item item in tempItems) {
|
||||
AddItem(item, 1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the specified amount of items to the Shop
|
||||
*/
|
||||
public void AddItem(Item item, int amount) {
|
||||
if(!items.ContainsKey(item)) {
|
||||
items.Add(item, amount);
|
||||
} else {
|
||||
items[item] += amount;
|
||||
}
|
||||
|
||||
onItemChangedCallback?.Invoke();
|
||||
}
|
||||
// TODO: add to buy more than one item
|
||||
/**
|
||||
* Removes the specified amount of items in the Shop
|
||||
*/
|
||||
public void RemoveItem(Item item, int amount) {
|
||||
if(items[item] <= 0) {
|
||||
items.Remove(item);
|
||||
} else {
|
||||
items[item] -= amount;
|
||||
}
|
||||
|
||||
onItemChangedCallback?.Invoke();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,72 +1,25 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class ShopSlot : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler {
|
||||
public Image icon;
|
||||
public Item item;
|
||||
public class ShopSlot : ItemStorageSlot {
|
||||
public TextMeshProUGUI nameText;
|
||||
public TextMeshProUGUI costText;
|
||||
public TextMeshProUGUI amountText;
|
||||
|
||||
|
||||
private Shop _shop;
|
||||
private Inventory _inventory;
|
||||
private PlayerController _playerController;
|
||||
|
||||
#region DescriptionHover
|
||||
|
||||
public float timeToWait;
|
||||
|
||||
public void OnPointerEnter(PointerEventData eventData) {
|
||||
StopAllCoroutines();
|
||||
StartCoroutine(StartTimer());
|
||||
}
|
||||
|
||||
public void OnPointerExit(PointerEventData eventData) {
|
||||
StopAllCoroutines();
|
||||
HoverManager.onMouseExit();
|
||||
}
|
||||
|
||||
private void ShowMessage() {
|
||||
if(item) {
|
||||
HoverManager.onMouseHover(item.description, Input.mousePosition);
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerator StartTimer() {
|
||||
yield return new WaitForSeconds(timeToWait);
|
||||
|
||||
ShowMessage();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private void Start() {
|
||||
_shop = Shop.instance;
|
||||
_inventory = Inventory.instance;
|
||||
_playerController = PlayerController.instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the Item of the Shop Slot
|
||||
*/
|
||||
public void AddItem(Item newItem) {
|
||||
item = newItem;
|
||||
|
||||
icon.sprite = item.defaultSprite;
|
||||
icon.enabled = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the Shop Slot
|
||||
*/
|
||||
public void ClearSlot() {
|
||||
item = null;
|
||||
icon.sprite = null;
|
||||
icon.enabled = false;
|
||||
public override void ClearSlot() {
|
||||
base.ClearSlot();
|
||||
nameText.text = "";
|
||||
costText.text = "";
|
||||
amountText.text = "";
|
||||
|
|
@ -75,14 +28,14 @@ public class ShopSlot : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
|
|||
/**
|
||||
* Gets called when the Shop Slot is clicked
|
||||
*/
|
||||
public void UseItem() {
|
||||
if(_playerController.money >= item.cost) {
|
||||
_inventory.AddItem(item, 1);
|
||||
_shop.RemoveItem(item, 1);
|
||||
_playerController.money -= item.cost;
|
||||
public override void UseItem() {
|
||||
if(_playerController.Money >= Item.cost) {
|
||||
_inventory.AddItem(Item, 1);
|
||||
_shop.RemoveItem(Item, 1);
|
||||
_playerController.ChangeMoney(-Item.cost);
|
||||
|
||||
Debug.Log("Buying Item: " + item.displayName);
|
||||
Debug.Log("money left: " + _playerController.money);
|
||||
Debug.Log("Buying Item: " + Item.displayName);
|
||||
Debug.Log("money left: " + _playerController.Money);
|
||||
} else {
|
||||
Debug.Log("Not enough money to buy item.");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,12 +6,12 @@ public class ShopUI : MonoBehaviour {
|
|||
public GameObject shopUI;
|
||||
private Shop _shop;
|
||||
private ShopSlot[] _slots;
|
||||
|
||||
|
||||
private void Start() {
|
||||
// Get Shop instance and add UpdateUI method to OnItemChanged delegate
|
||||
_shop = Shop.instance;
|
||||
_shop.onItemChangedCallback += UpdateUI;
|
||||
|
||||
|
||||
// Add all ShopSlot GameObjects to _slots and turn off the Shop UI
|
||||
_slots = itemsParent.GetComponentsInChildren<ShopSlot>();
|
||||
ToggleShop();
|
||||
|
|
@ -20,8 +20,6 @@ public class ShopUI : MonoBehaviour {
|
|||
foreach(ShopSlot slot in _slots) {
|
||||
slot.icon.raycastTarget = false;
|
||||
}
|
||||
|
||||
UpdateUI();
|
||||
}
|
||||
|
||||
private void Update() {
|
||||
|
|
@ -46,8 +44,8 @@ public class ShopUI : MonoBehaviour {
|
|||
for(int i = 0; i < _slots.Length; i++) {
|
||||
if(i < _shop.items.Count) {
|
||||
_slots[i].AddItem(_shop.items.ElementAt(i).Key);
|
||||
_slots[i].nameText.text = _slots[i].item.displayName;
|
||||
_slots[i].costText.text = _slots[i].item.cost + " €";
|
||||
_slots[i].nameText.text = _slots[i].Item.displayName;
|
||||
_slots[i].costText.text = _slots[i].Item.cost + " µ";
|
||||
_slots[i].amountText.text = _shop.items[_shop.items.ElementAt(i).Key] + " #";
|
||||
} else {
|
||||
_slots[i].ClearSlot();
|
||||
|
|
|
|||
|
|
@ -3,38 +3,25 @@ using System.Collections;
|
|||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class TileController : MonoBehaviour
|
||||
{
|
||||
public class TileController : MonoBehaviour {
|
||||
public GameObject tile;
|
||||
|
||||
public GameObject CameraGameObject;
|
||||
|
||||
public GameObject cameraGameObject;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
Camera camera = CameraGameObject.GetComponent<Camera>();
|
||||
Vector3 screen = camera.ViewportToWorldPoint(new Vector3(1,1,camera.nearClipPlane));
|
||||
void Start() {
|
||||
Camera camera = cameraGameObject.GetComponent<Camera>();
|
||||
Vector3 screen = camera.ViewportToWorldPoint(new Vector3(1, 1, camera.nearClipPlane));
|
||||
int x = Convert.ToInt32(Math.Ceiling(screen.x));
|
||||
int y = Convert.ToInt32(Math.Ceiling(screen.y));
|
||||
|
||||
|
||||
Debug.Log(screen);
|
||||
for (int xx = -x; xx <= x; xx++)
|
||||
{
|
||||
for (int yy = -y; yy <= y; yy++)
|
||||
{
|
||||
if (tile != null)
|
||||
{
|
||||
for(int xx = -x; xx <= x; xx++) {
|
||||
for(int yy = -y; yy <= y; yy++) {
|
||||
if(tile != null) {
|
||||
Instantiate(tile, new Vector3(xx, yy, 0), Quaternion.identity);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue