added Item changing Sprite when hovering over Slot in Shop or Inventory
This commit is contained in:
parent
fe63511825
commit
24fa26ddb2
11 changed files with 46 additions and 23 deletions
8
Assets/Farming Asset Pack/Split Assets.meta
Normal file
8
Assets/Farming Asset Pack/Split Assets.meta
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: c73478f9c6622694193b6b0525d76af5
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
%YAML 1.1
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!114 &11400000
|
||||
MonoBehaviour:
|
||||
|
|
|
|||
|
|
@ -1639,7 +1639,7 @@ MonoBehaviour:
|
|||
m_HandleRect: {fileID: 2006577138}
|
||||
m_Direction: 2
|
||||
m_Value: 1
|
||||
m_Size: 0.59324205
|
||||
m_Size: 0.5932421
|
||||
m_NumberOfSteps: 0
|
||||
m_OnValueChanged:
|
||||
m_PersistentCalls:
|
||||
|
|
@ -4996,7 +4996,7 @@ GameObject:
|
|||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
m_IsActive: 0
|
||||
--- !u!114 &1291863650
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
|
|
@ -5010,7 +5010,7 @@ MonoBehaviour:
|
|||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
tile: {fileID: 4752245148499717901, guid: ea81011a3ce83fb4386934728a92ee2d, type: 3}
|
||||
cameraGameObject: {fileID: 0}
|
||||
cameraGameObject: {fileID: 598358736}
|
||||
--- !u!4 &1291863651
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
|
|
|
|||
|
|
@ -6,16 +6,16 @@ public class HoverManager : MonoBehaviour {
|
|||
public TextMeshProUGUI descriptionText;
|
||||
public RectTransform descriptionHoverBackground;
|
||||
|
||||
public static Action<string, Vector2> onMouseHover;
|
||||
public static Action<string, Vector2> onMouseHoverDescription;
|
||||
public static Action onMouseExit;
|
||||
|
||||
private void OnEnable() {
|
||||
onMouseHover += ShowDescription;
|
||||
onMouseHoverDescription += ShowDescription;
|
||||
onMouseExit += HideDescription;
|
||||
}
|
||||
|
||||
private void OnDisable() {
|
||||
onMouseHover -= ShowDescription;
|
||||
onMouseHoverDescription -= ShowDescription;
|
||||
onMouseExit -= HideDescription;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -15,13 +15,13 @@ public class Inventory : ItemStorage {
|
|||
|
||||
#endregion
|
||||
|
||||
public const int InventorySpace = 28;
|
||||
private const int _InventorySpace = 28;
|
||||
|
||||
/**
|
||||
* Adds the specified amount of items to the Inventory
|
||||
*/
|
||||
public override void AddItem(Item item, int amount) {
|
||||
if(items.Count >= InventorySpace) {
|
||||
if(items.Count >= _InventorySpace) {
|
||||
Debug.Log("Not enough inventory space!");
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ public class ItemStorage : MonoBehaviour {
|
|||
* Removes the specified amount of items in the Item Storage
|
||||
*/
|
||||
public void RemoveItem(Item item, int amount) {
|
||||
if(items[item] <= 0) {
|
||||
if(items[item]-amount <= 0) {
|
||||
items.Remove(item);
|
||||
} else {
|
||||
items[item] -= amount;
|
||||
|
|
|
|||
|
|
@ -13,23 +13,36 @@ public class ItemStorageSlot : MonoBehaviour, IPointerEnterHandler, IPointerExit
|
|||
|
||||
private Item _item;
|
||||
|
||||
#region DescriptionHover
|
||||
#region HoverOverItem
|
||||
|
||||
public float timeToWait;
|
||||
|
||||
public void OnPointerEnter(PointerEventData eventData) {
|
||||
StopAllCoroutines();
|
||||
StartCoroutine(StartTimer());
|
||||
|
||||
ChangeItemSelectedSprite(true);
|
||||
}
|
||||
|
||||
public void OnPointerExit(PointerEventData eventData) {
|
||||
StopAllCoroutines();
|
||||
ChangeItemSelectedSprite(false);
|
||||
HoverManager.onMouseExit();
|
||||
}
|
||||
|
||||
private void ShowMessage() {
|
||||
if(_item){
|
||||
HoverManager.onMouseHover(_item.description, Input.mousePosition);
|
||||
HoverManager.onMouseHoverDescription(_item.description, Input.mousePosition);
|
||||
}
|
||||
}
|
||||
|
||||
private void ChangeItemSelectedSprite(bool on) {
|
||||
if(_item) {
|
||||
if(on) {
|
||||
icon.sprite = _item.selectedSprite;
|
||||
} else {
|
||||
icon.sprite = _item.defaultSprite;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class Shop : ItemStorage {
|
||||
|
|
|
|||
|
|
@ -19,10 +19,11 @@ public class ShopSlot : ItemStorageSlot {
|
|||
* Clears the Shop Slot
|
||||
*/
|
||||
public override void ClearSlot() {
|
||||
base.ClearSlot();
|
||||
nameText.text = "";
|
||||
costText.text = "";
|
||||
amountText.text = "";
|
||||
// _shop.RemoveItem(Item, 1);
|
||||
base.ClearSlot();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -35,7 +36,6 @@ public class ShopSlot : ItemStorageSlot {
|
|||
_playerController.ChangeMoney(-Item.cost);
|
||||
|
||||
Debug.Log("Buying Item: " + Item.displayName);
|
||||
Debug.Log("money left: " + _playerController.Money);
|
||||
} else {
|
||||
Debug.Log("Not enough money to buy item.");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@ using UnityEngine;
|
|||
public class ShopUI : MonoBehaviour {
|
||||
public Transform itemsParent;
|
||||
public GameObject shopUI;
|
||||
public bool shopIsOpen;
|
||||
|
||||
private Shop _shop;
|
||||
private ShopSlot[] _slots;
|
||||
|
||||
|
|
@ -14,6 +16,7 @@ public class ShopUI : MonoBehaviour {
|
|||
|
||||
// Add all ShopSlot GameObjects to _slots and turn off the Shop UI
|
||||
_slots = itemsParent.GetComponentsInChildren<ShopSlot>();
|
||||
shopIsOpen = false;
|
||||
ToggleShop();
|
||||
|
||||
// Set the icon to not be a raycast target for the Description Hovering to work
|
||||
|
|
@ -25,6 +28,7 @@ public class ShopUI : MonoBehaviour {
|
|||
private void Update() {
|
||||
// When "Shop" button is pressed turn on/off Shop UI
|
||||
if(Input.GetButtonDown("Shop")) {
|
||||
shopIsOpen = true;
|
||||
ToggleShop();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ MonoBehaviour:
|
|||
m_EditorClassIdentifier:
|
||||
m_Material: {fileID: 0}
|
||||
m_Color: {r: 1, g: 1, b: 1, a: 1}
|
||||
m_RaycastTarget: 1
|
||||
m_RaycastTarget: 0
|
||||
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
|
||||
m_Maskable: 1
|
||||
m_OnCullStateChanged:
|
||||
|
|
@ -136,7 +136,7 @@ MonoBehaviour:
|
|||
m_EditorClassIdentifier:
|
||||
m_Material: {fileID: 0}
|
||||
m_Color: {r: 1, g: 1, b: 1, a: 1}
|
||||
m_RaycastTarget: 1
|
||||
m_RaycastTarget: 0
|
||||
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
|
||||
m_Maskable: 1
|
||||
m_OnCullStateChanged:
|
||||
|
|
@ -271,7 +271,7 @@ MonoBehaviour:
|
|||
m_EditorClassIdentifier:
|
||||
m_Material: {fileID: 0}
|
||||
m_Color: {r: 1, g: 1, b: 1, a: 1}
|
||||
m_RaycastTarget: 1
|
||||
m_RaycastTarget: 0
|
||||
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
|
||||
m_Maskable: 1
|
||||
m_OnCullStateChanged:
|
||||
|
|
@ -406,7 +406,7 @@ MonoBehaviour:
|
|||
m_EditorClassIdentifier:
|
||||
m_Material: {fileID: 0}
|
||||
m_Color: {r: 1, g: 1, b: 1, a: 1}
|
||||
m_RaycastTarget: 1
|
||||
m_RaycastTarget: 0
|
||||
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
|
||||
m_Maskable: 1
|
||||
m_OnCullStateChanged:
|
||||
|
|
@ -633,11 +633,10 @@ MonoBehaviour:
|
|||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
icon: {fileID: 5121261191727116855}
|
||||
item: {fileID: 0}
|
||||
nameText: {fileID: 5121261192692990484}
|
||||
costText: {fileID: 5121261192300927449}
|
||||
amountText: {fileID: 5121261192606669392}
|
||||
timeToWait: 0.5
|
||||
nameText: {fileID: 5121261192692990484}
|
||||
costText: {fileID: 5121261192300927449}
|
||||
--- !u!61 &5121261193055935941
|
||||
BoxCollider2D:
|
||||
m_ObjectHideFlags: 0
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue