購入ボタンの挙動修正
This commit is contained in:
parent
c1eb72cb26
commit
a23e3e5c72
|
|
@ -242,6 +242,8 @@ MonoBehaviour:
|
|||
onObject: {fileID: 8536603422629144349}
|
||||
offObject: {fileID: 8536603424418812070}
|
||||
soldOutObject: {fileID: 8536603424566114136}
|
||||
learnedObject: {fileID: 8536603424476639146}
|
||||
purchasedObject: {fileID: 1735230268650569057}
|
||||
--- !u!114 &1342298367473717200
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
|
|
|
|||
|
|
@ -5,15 +5,18 @@ using UnityEngine.UI;
|
|||
|
||||
public class ShopItemPurchaseButton : MonoBehaviour
|
||||
{
|
||||
private ShopItemType itemType;
|
||||
[SerializeField] private Button purchaseButton;
|
||||
[SerializeField] private GameObject onObject;
|
||||
[SerializeField] private GameObject offObject;
|
||||
[SerializeField] private GameObject soldOutObject;
|
||||
[SerializeField] private GameObject learnedObject;
|
||||
[SerializeField] private GameObject purchasedObject;
|
||||
private ShopItemType itemType;
|
||||
private bool isPurchased;
|
||||
|
||||
public IObservable<Unit> ClickObservable => purchaseButton.OnClickAsObservable().TakeUntilDestroy(this);
|
||||
|
||||
public void SetItemType(ShopItemType type)
|
||||
public void SetItemType(ItemCategory category, ShopItemType type)
|
||||
{
|
||||
itemType = type;
|
||||
switch (type)
|
||||
|
|
@ -22,13 +25,19 @@ public class ShopItemPurchaseButton : MonoBehaviour
|
|||
soldOutObject.SetActive(false);
|
||||
break;
|
||||
case ShopItemType.NonConsumable:
|
||||
offObject.SetActive(false);
|
||||
learnedObject.SetActive(category == ItemCategory.Recipe);
|
||||
purchasedObject.SetActive(category == ItemCategory.Pan);
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException(nameof(type), type, null);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetItemPurchased(bool active)
|
||||
{
|
||||
isPurchased = active;
|
||||
}
|
||||
|
||||
public void SetButtonActive(bool active)
|
||||
{
|
||||
switch (itemType)
|
||||
|
|
@ -38,8 +47,9 @@ public class ShopItemPurchaseButton : MonoBehaviour
|
|||
offObject.SetActive(!active);
|
||||
break;
|
||||
case ShopItemType.NonConsumable:
|
||||
onObject.SetActive(active);
|
||||
soldOutObject.SetActive(!active);
|
||||
onObject.SetActive(active && !isPurchased);
|
||||
offObject.SetActive(!active && !isPurchased);
|
||||
soldOutObject.SetActive(isPurchased);
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
|
|
|
|||
|
|
@ -23,12 +23,13 @@ public class ShopItemView : MonoBehaviour
|
|||
{
|
||||
stockCount.transform.parent.gameObject.SetActive(false);
|
||||
}
|
||||
purchaseButton.SetItemType(shopData.ConsumeType);
|
||||
purchaseButton.SetItemType(shopData.Category, shopData.ConsumeType);
|
||||
}
|
||||
|
||||
public void SetStockCount(int stock)
|
||||
{
|
||||
stockCount.text = $"{stock}";
|
||||
purchaseButton.SetItemPurchased(stock > 0);
|
||||
}
|
||||
|
||||
public void SetItemActive(bool active)
|
||||
|
|
|
|||
|
|
@ -25,15 +25,12 @@ public class Shopping : MonoBehaviour
|
|||
// コインを監視して購入可能状態を切り替え
|
||||
changeCoinSubject.Subscribe(ownCoin =>
|
||||
{
|
||||
if (shopData.ConsumeType == ShopItemType.NonConsumable && GetItemAmount(shopData) > 0)
|
||||
{
|
||||
itemView.SetItemActive(false);
|
||||
return;
|
||||
}
|
||||
itemView.SetItemActive(shopData.price < ownCoin);
|
||||
itemView.SetItemActive(shopData.price <= ownCoin);
|
||||
}).AddTo(this);
|
||||
// アイテム購入クリック購読
|
||||
itemView.PurchaseButtonObservable.Subscribe(_ =>
|
||||
itemView.PurchaseButtonObservable
|
||||
.Where(_ => shopData.price <= CoinManager.Instance.OwnCoin)
|
||||
.Subscribe(_ =>
|
||||
{
|
||||
// アイテムを増やす
|
||||
AddItem(shopData);
|
||||
|
|
|
|||
Loading…
Reference in New Issue