[Add] Universal modifier system, shop, inventory & persistence
Replace hardcoded BonusForOnes/MultiplierForSixes with data-driven modifier system supporting 2 scopes (SelectedCategory, AnyCategoryClosed), 4 effect types, durability modes (Permanent, LimitedUses), and configurable targets via ScriptableObject (ModifierData). - Modifier domain: ModifierEnums, ModifierTarget, ModifierData, ModifierRuntime, ModifierEffect (dict-based strategy), ModifierPipeline (4-pass: cat-additive → cat-multiplicative → final-additive → final-multiplicative) - ScoringSystem: replaced old modifier list with ModifierPipeline integration, added OnCategoryConfirmed event - Shop MVC: ShopCatalog (SO), ShopModel, ShopView, ShopItemView, ShopController - Inventory MVC: InventoryModel (activate/deactivate/sell/durability), InventoryView, InventorySlotView, InventoryController - CurrencyBank: editor-adjustable balance with events - Persistence: SaveData + SaveSystem (Newtonsoft JSON + PlayerPrefs) - Editor: ModifierAssetCreator menu item to generate 6 example modifiers + catalog - Tests: 6 test classes covering effects, pipeline, scoring, shop, inventory, save - GameController: wired shop/inventory/save lifecycle - GameInfoView: added currency display, shop/inventory toggle buttons Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public sealed class InventoryView : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private Transform slotContainer;
|
||||
[SerializeField] private InventorySlotView slotPrefab;
|
||||
[SerializeField] private TMP_Text slotCountText;
|
||||
[SerializeField] private Button closeButton;
|
||||
|
||||
private readonly List<InventorySlotView> spawnedSlots = new();
|
||||
|
||||
public event Action<ModifierRuntime> OnActivateClicked;
|
||||
public event Action<ModifierRuntime> OnDeactivateClicked;
|
||||
public event Action<ModifierRuntime> OnSellClicked;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (closeButton != null)
|
||||
closeButton.onClick.AddListener(Hide);
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
if (closeButton != null)
|
||||
closeButton.onClick.RemoveListener(Hide);
|
||||
}
|
||||
|
||||
public void Show() => gameObject.SetActive(true);
|
||||
public void Hide() => gameObject.SetActive(false);
|
||||
public bool IsVisible => gameObject.activeSelf;
|
||||
|
||||
public void Refresh(IReadOnlyList<ModifierRuntime> owned, int maxSlots)
|
||||
{
|
||||
ClearSlots();
|
||||
|
||||
int activeCount = 0;
|
||||
|
||||
for (int i = 0; i < owned.Count; i++)
|
||||
{
|
||||
var runtime = owned[i];
|
||||
if (runtime.IsActive) activeCount++;
|
||||
|
||||
var slot = Instantiate(slotPrefab, slotContainer);
|
||||
slot.Setup(runtime, activeCount <= maxSlots);
|
||||
slot.OnActivateClicked += HandleActivate;
|
||||
slot.OnDeactivateClicked += HandleDeactivate;
|
||||
slot.OnSellClicked += HandleSell;
|
||||
spawnedSlots.Add(slot);
|
||||
}
|
||||
|
||||
if (slotCountText != null)
|
||||
slotCountText.text = $"{activeCount}/{maxSlots}";
|
||||
}
|
||||
|
||||
private void ClearSlots()
|
||||
{
|
||||
for (int i = 0; i < spawnedSlots.Count; i++)
|
||||
{
|
||||
spawnedSlots[i].OnActivateClicked -= HandleActivate;
|
||||
spawnedSlots[i].OnDeactivateClicked -= HandleDeactivate;
|
||||
spawnedSlots[i].OnSellClicked -= HandleSell;
|
||||
Destroy(spawnedSlots[i].gameObject);
|
||||
}
|
||||
spawnedSlots.Clear();
|
||||
}
|
||||
|
||||
private void HandleActivate(ModifierRuntime runtime) => OnActivateClicked?.Invoke(runtime);
|
||||
private void HandleDeactivate(ModifierRuntime runtime) => OnDeactivateClicked?.Invoke(runtime);
|
||||
private void HandleSell(ModifierRuntime runtime) => OnSellClicked?.Invoke(runtime);
|
||||
}
|
||||
Reference in New Issue
Block a user