Undo last purchase working again

Added Comments to AnimalShop, ItemShop and ShopUI classes
This commit is contained in:
d-hain 2022-06-23 22:24:22 +02:00
parent 441ffb900a
commit c01c592976
7 changed files with 25 additions and 194 deletions

View file

@ -1979,63 +1979,6 @@ PrefabInstance:
objectReference: {fileID: 0} objectReference: {fileID: 0}
m_RemovedComponents: [] m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 5719971c822f74e4ca86130b5e77b1d5, type: 3} m_SourcePrefab: {fileID: 100100000, guid: 5719971c822f74e4ca86130b5e77b1d5, type: 3}
--- !u!1001 &495860598
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 2510115116361252817, guid: 547dbbf4c5377dc409dfea772c096434, type: 3}
propertyPath: m_Name
value: Cow (2)
objectReference: {fileID: 0}
- target: {fileID: 2510115116361252819, guid: 547dbbf4c5377dc409dfea772c096434, type: 3}
propertyPath: m_RootOrder
value: 12
objectReference: {fileID: 0}
- target: {fileID: 2510115116361252819, guid: 547dbbf4c5377dc409dfea772c096434, type: 3}
propertyPath: m_LocalPosition.x
value: 1.94
objectReference: {fileID: 0}
- target: {fileID: 2510115116361252819, guid: 547dbbf4c5377dc409dfea772c096434, type: 3}
propertyPath: m_LocalPosition.y
value: -3.21
objectReference: {fileID: 0}
- target: {fileID: 2510115116361252819, guid: 547dbbf4c5377dc409dfea772c096434, type: 3}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2510115116361252819, guid: 547dbbf4c5377dc409dfea772c096434, type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 2510115116361252819, guid: 547dbbf4c5377dc409dfea772c096434, type: 3}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2510115116361252819, guid: 547dbbf4c5377dc409dfea772c096434, type: 3}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2510115116361252819, guid: 547dbbf4c5377dc409dfea772c096434, type: 3}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2510115116361252819, guid: 547dbbf4c5377dc409dfea772c096434, type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2510115116361252819, guid: 547dbbf4c5377dc409dfea772c096434, type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2510115116361252819, guid: 547dbbf4c5377dc409dfea772c096434, type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 547dbbf4c5377dc409dfea772c096434, type: 3}
--- !u!1 &496797767 --- !u!1 &496797767
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -9412,63 +9355,6 @@ Transform:
m_Father: {fileID: 0} m_Father: {fileID: 0}
m_RootOrder: 4 m_RootOrder: 4
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1001 &1840846247
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 2510115116361252817, guid: 547dbbf4c5377dc409dfea772c096434, type: 3}
propertyPath: m_Name
value: Cow (1)
objectReference: {fileID: 0}
- target: {fileID: 2510115116361252819, guid: 547dbbf4c5377dc409dfea772c096434, type: 3}
propertyPath: m_RootOrder
value: 11
objectReference: {fileID: 0}
- target: {fileID: 2510115116361252819, guid: 547dbbf4c5377dc409dfea772c096434, type: 3}
propertyPath: m_LocalPosition.x
value: 1.31
objectReference: {fileID: 0}
- target: {fileID: 2510115116361252819, guid: 547dbbf4c5377dc409dfea772c096434, type: 3}
propertyPath: m_LocalPosition.y
value: -1.48
objectReference: {fileID: 0}
- target: {fileID: 2510115116361252819, guid: 547dbbf4c5377dc409dfea772c096434, type: 3}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2510115116361252819, guid: 547dbbf4c5377dc409dfea772c096434, type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 2510115116361252819, guid: 547dbbf4c5377dc409dfea772c096434, type: 3}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2510115116361252819, guid: 547dbbf4c5377dc409dfea772c096434, type: 3}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2510115116361252819, guid: 547dbbf4c5377dc409dfea772c096434, type: 3}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2510115116361252819, guid: 547dbbf4c5377dc409dfea772c096434, type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2510115116361252819, guid: 547dbbf4c5377dc409dfea772c096434, type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2510115116361252819, guid: 547dbbf4c5377dc409dfea772c096434, type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 547dbbf4c5377dc409dfea772c096434, type: 3}
--- !u!1001 &1856825636 --- !u!1001 &1856825636
PrefabInstance: PrefabInstance:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -9681,63 +9567,6 @@ PrefabInstance:
objectReference: {fileID: 0} objectReference: {fileID: 0}
m_RemovedComponents: [] m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 44dae5fbdb6f7df4f93a10807f66956f, type: 3} m_SourcePrefab: {fileID: 100100000, guid: 44dae5fbdb6f7df4f93a10807f66956f, type: 3}
--- !u!1001 &1889531549
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 2510115116361252817, guid: 547dbbf4c5377dc409dfea772c096434, type: 3}
propertyPath: m_Name
value: Cow (3)
objectReference: {fileID: 0}
- target: {fileID: 2510115116361252819, guid: 547dbbf4c5377dc409dfea772c096434, type: 3}
propertyPath: m_RootOrder
value: 13
objectReference: {fileID: 0}
- target: {fileID: 2510115116361252819, guid: 547dbbf4c5377dc409dfea772c096434, type: 3}
propertyPath: m_LocalPosition.x
value: -0.61
objectReference: {fileID: 0}
- target: {fileID: 2510115116361252819, guid: 547dbbf4c5377dc409dfea772c096434, type: 3}
propertyPath: m_LocalPosition.y
value: -2.7
objectReference: {fileID: 0}
- target: {fileID: 2510115116361252819, guid: 547dbbf4c5377dc409dfea772c096434, type: 3}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2510115116361252819, guid: 547dbbf4c5377dc409dfea772c096434, type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 2510115116361252819, guid: 547dbbf4c5377dc409dfea772c096434, type: 3}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2510115116361252819, guid: 547dbbf4c5377dc409dfea772c096434, type: 3}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2510115116361252819, guid: 547dbbf4c5377dc409dfea772c096434, type: 3}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2510115116361252819, guid: 547dbbf4c5377dc409dfea772c096434, type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2510115116361252819, guid: 547dbbf4c5377dc409dfea772c096434, type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2510115116361252819, guid: 547dbbf4c5377dc409dfea772c096434, type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 547dbbf4c5377dc409dfea772c096434, type: 3}
--- !u!1 &1894722676 --- !u!1 &1894722676
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0

View file

@ -1,8 +1,6 @@
using UnityEngine; using UnityEngine;
namespace Shop { namespace Shop {
public class AnimalShop : ElementStorage<Animal> { public class AnimalShop : ElementStorage<Animal> {
#region Singleton #region Singleton

View file

@ -2,7 +2,6 @@ using TMPro;
using UnityEngine; using UnityEngine;
namespace Shop { namespace Shop {
public class AnimalShopSlot : ElementStorageSlot<Animal> { public class AnimalShopSlot : ElementStorageSlot<Animal> {
public TextMeshProUGUI nameText; public TextMeshProUGUI nameText;
public TextMeshProUGUI costText; public TextMeshProUGUI costText;
@ -16,8 +15,8 @@ namespace Shop {
} }
/** /**
* Clears the Shop Slot * Clears the Shop Slot
*/ */
public override void ClearSlot() { public override void ClearSlot() {
nameText.text = ""; nameText.text = "";
costText.text = ""; costText.text = "";
@ -26,8 +25,8 @@ namespace Shop {
} }
/** /**
* Gets called when the Shop Slot is clicked * Gets called when the Shop Slot is clicked
*/ */
public override void UseElement() { public override void UseElement() {
if(Element) { if(Element) {
if(_playerController.Money >= Element.price) { if(_playerController.Money >= Element.price) {
@ -46,6 +45,9 @@ namespace Shop {
} }
} }
/**
* Places cow randomly on Screen
*/
private void PlaceCowRandomlyOnScreen() { private void PlaceCowRandomlyOnScreen() {
float spawnY = Random.Range float spawnY = Random.Range
(Camera.main.ScreenToWorldPoint(new Vector2(0, 0)).y, (Camera.main.ScreenToWorldPoint(new Vector2(0, 0)).y,

View file

@ -1,8 +1,6 @@
using UnityEngine; using UnityEngine;
namespace Shop { namespace Shop {
public class ItemShop : ElementStorage<Item> { public class ItemShop : ElementStorage<Item> {
#region Singleton #region Singleton
@ -26,8 +24,8 @@ namespace Shop {
private int _lastBoughtItemAmount; private int _lastBoughtItemAmount;
/** /**
* Calls ElementStorage.RemoveItem() and sets 2 Variables to remember the last bought item * Calls ElementStorage.RemoveItem() and sets 2 Variables to remember the last bought item
*/ */
public override void RemoveElement(Item item, int amount) { public override void RemoveElement(Item item, int amount) {
base.RemoveElement(item, amount); base.RemoveElement(item, amount);
if(itemWasBought) { if(itemWasBought) {
@ -36,6 +34,9 @@ namespace Shop {
} }
} }
/**
* Undo the last purchase (refund money)
*/
public void UndoLastPurchase() { public void UndoLastPurchase() {
if(itemWasBought) { if(itemWasBought) {
_inventory = Inventory.instance; _inventory = Inventory.instance;

View file

@ -16,8 +16,8 @@ namespace Shop {
} }
/** /**
* Clears the Shop Slot * Clears the Shop Slot
*/ */
public override void ClearSlot() { public override void ClearSlot() {
nameText.text = ""; nameText.text = "";
costText.text = ""; costText.text = "";
@ -26,8 +26,8 @@ namespace Shop {
} }
/** /**
* Gets called when the Shop Slot is clicked * Gets called when the Shop Slot is clicked
*/ */
public override void UseElement() { public override void UseElement() {
if(Element) { if(Element) {
if(_playerController.Money >= Element.price) { if(_playerController.Money >= Element.price) {
@ -36,7 +36,6 @@ namespace Shop {
_itemShop.itemWasBought = true; _itemShop.itemWasBought = true;
// Debug.Log("Buying Item: " + Element.displayName); // Debug.Log("Buying Item: " + Element.displayName);
} }
_inventory.AddElement(Element, 1); _inventory.AddElement(Element, 1);
_itemShop.RemoveElement(Element, 1); _itemShop.RemoveElement(Element, 1);
} else { } else {

View file

@ -3,8 +3,6 @@ using UnityEngine;
using UnityEngine.UI; using UnityEngine.UI;
namespace Shop { namespace Shop {
public class ShopSwitcher : MonoBehaviour { public class ShopSwitcher : MonoBehaviour {
public Sprite animalShopSprite; public Sprite animalShopSprite;
public Sprite itemShopSprite; public Sprite itemShopSprite;
@ -22,6 +20,10 @@ namespace Shop {
viewportAnimals.SetActive(false); viewportAnimals.SetActive(false);
} }
/**
* Shops get switched between Animal and Item Shop
* The Image on the Button gets changes depending at which Shop you are
*/
public void SwitchShops() { public void SwitchShops() {
// switch Shop Title text and Image of the Button // switch Shop Title text and Image of the Button
if(shopTitleText.text.StartsWith("Item")) { if(shopTitleText.text.StartsWith("Item")) {

View file

@ -45,8 +45,8 @@ namespace Shop {
} }
/** /**
* Turn on/off the Shop UI * Turn on/off the Shop UI
*/ */
private void ToggleShop() { private void ToggleShop() {
inventoryUI.gameObject.SetActive(!shopUI.activeSelf); inventoryUI.gameObject.SetActive(!shopUI.activeSelf);
HoverManager.instance.HideDescription(); HoverManager.instance.HideDescription();
@ -54,10 +54,10 @@ namespace Shop {
} }
/** /**
* Is called when something in the Shop UI should update * Is called when something in the Shop UI should update
*/ */
private void UpdateUI() { private void UpdateUI() {
// Add all items to the correct slots and clear the ones where no item should be // Add all items and animals to the correct slots and clear the ones where no item/animal should be
for(int i = 0; i < _itemSlots.Length; i++) { for(int i = 0; i < _itemSlots.Length; i++) {
// Item Slots // Item Slots
if(i < _itemShop.Elements.Count) { if(i < _itemShop.Elements.Count) {