145 lines
3.7 KiB
C#
145 lines
3.7 KiB
C#
|
using System;
|
||
|
using BlueWater.Items;
|
||
|
using Sirenix.OdinInspector;
|
||
|
using TMPro;
|
||
|
using UnityEngine;
|
||
|
using UnityEngine.EventSystems;
|
||
|
using UnityEngine.UI;
|
||
|
|
||
|
namespace BlueWater.Uis
|
||
|
{
|
||
|
public class TycoonItemSlotUi : MonoBehaviour, IPointerDownHandler, IPointerUpHandler
|
||
|
{
|
||
|
[Title("컴포넌트")]
|
||
|
[SerializeField, Required]
|
||
|
private Image _itemBoxImage;
|
||
|
|
||
|
[SerializeField, Required]
|
||
|
private Image _backgroundImage;
|
||
|
|
||
|
[SerializeField, Required]
|
||
|
private Image _itemImage;
|
||
|
|
||
|
[SerializeField, Required]
|
||
|
private TMP_Text _quantityText;
|
||
|
|
||
|
[Title("옵션")]
|
||
|
[SerializeField]
|
||
|
private bool _isUsingBackgroundColor;
|
||
|
|
||
|
[SerializeField]
|
||
|
private bool _isUsingQuantityText;
|
||
|
|
||
|
[SerializeField]
|
||
|
private bool _isLocked;
|
||
|
|
||
|
[Title("현재 아이템 데이터")]
|
||
|
[SerializeField]
|
||
|
private ItemData _itemData;
|
||
|
|
||
|
[SerializeField]
|
||
|
private FoodData _foodData;
|
||
|
|
||
|
private void Awake()
|
||
|
{
|
||
|
DisuseBackgroundColor();
|
||
|
DisuseQuantityText();
|
||
|
SetItemData(null);
|
||
|
SetItemImage(null);
|
||
|
}
|
||
|
|
||
|
private void OnEnable()
|
||
|
{
|
||
|
if (_isUsingBackgroundColor)
|
||
|
{
|
||
|
UseBackgroundColor();
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
DisuseBackgroundColor();
|
||
|
}
|
||
|
|
||
|
if (_isUsingQuantityText)
|
||
|
{
|
||
|
UseQuantityText();
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
DisuseQuantityText();
|
||
|
}
|
||
|
|
||
|
if (_isLocked)
|
||
|
{
|
||
|
SetItemData(null);
|
||
|
SetItemImage(ItemManager.Instance.ItemSlotDataSo.LockSprite);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public void OnPointerDown(PointerEventData eventData)
|
||
|
{
|
||
|
_itemBoxImage.color = ItemManager.Instance.ItemSlotDataSo.HighlightingItemBox;
|
||
|
}
|
||
|
|
||
|
public void OnPointerUp(PointerEventData eventData)
|
||
|
{
|
||
|
_itemBoxImage.color = ItemManager.Instance.ItemSlotDataSo.NormalItemBox;
|
||
|
}
|
||
|
|
||
|
// Background Color
|
||
|
public void UseBackgroundColor()
|
||
|
{
|
||
|
var itemSlotDataSo = ItemManager.Instance.ItemSlotDataSo;
|
||
|
var newColor = Color.white;
|
||
|
|
||
|
switch (_foodData.Type)
|
||
|
{
|
||
|
case FoodType.None:
|
||
|
break;
|
||
|
case FoodType.Skewer:
|
||
|
newColor = itemSlotDataSo.SkewerPanFood;
|
||
|
break;
|
||
|
case FoodType.Soup:
|
||
|
newColor = itemSlotDataSo.SoupFood;
|
||
|
break;
|
||
|
case FoodType.FryingPan:
|
||
|
newColor = itemSlotDataSo.FryingPanFood;
|
||
|
break;
|
||
|
case FoodType.Dessert:
|
||
|
break;
|
||
|
default:
|
||
|
throw new ArgumentOutOfRangeException();
|
||
|
}
|
||
|
|
||
|
_backgroundImage.color = newColor;
|
||
|
_backgroundImage.enabled = true;
|
||
|
}
|
||
|
|
||
|
public void DisuseBackgroundColor()
|
||
|
{
|
||
|
_backgroundImage.enabled = false;
|
||
|
_backgroundImage.color = Color.white;
|
||
|
}
|
||
|
|
||
|
// Quantity Text
|
||
|
public void UseQuantityText()
|
||
|
{
|
||
|
_quantityText.enabled = true;
|
||
|
}
|
||
|
|
||
|
public void DisuseQuantityText()
|
||
|
{
|
||
|
_quantityText.enabled = false;
|
||
|
}
|
||
|
|
||
|
public void SetItemData(ItemData itemData)
|
||
|
{
|
||
|
_itemData = itemData;
|
||
|
}
|
||
|
|
||
|
public void SetItemImage(Sprite sprite)
|
||
|
{
|
||
|
_itemImage.sprite = sprite;
|
||
|
_itemImage.enabled = _itemImage.sprite;
|
||
|
}
|
||
|
}
|
||
|
}
|