using System; using System.Collections; using System.Collections.Generic; using UnityEngine; namespace SimpleInventorySystem { public class LimitStackSlotManager : MonoBehaviour { public int StackSlotLimit = 0; public int Count { get; private set; } public LimitStackSlot[] limitStackSlots; public bool combinedLimit = true; private RenderItemUIProperty renderProp; public SlotUI slot; private void Awake() { foreach (LimitStackSlot ls in limitStackSlots) { ls.limitStackSlotCapacities = this; } //slot = GetComponent(); renderProp = GetComponent(); if(slot != null) { SetRenderItemUIPropertyValue(); } } private void SetRenderItemUIPropertyValue() { if (renderProp != null) { renderProp.value = Count.ToString() + " / " + StackSlotLimit.ToString(); } } public void SetStackSlotLimit(ItemUI item) { if(item == null || item.GetComponent()) { Debug.LogWarning("LimitStackSlotManager: SetStackSlotLimit(ItemUI item): The passed item should not be null and should have a LimitStackSlotCapacity component."); return; } StackSlotLimit = item.GetComponent().Capacity; SetRenderItemUIPropertyValue(); } public void UnsetStackSlotLimit() { StackSlotLimit = 0; Count = 0; SetRenderItemUIPropertyValue(); } // Start is called before the first frame update void Start() { foreach (LimitStackSlot ls in limitStackSlots) { ls.limitStackSlotCapacities = this; } } // Update is called once per frame void Update() { } public void Increment(LimitStackSlot ls) { Count += ls.Weight; SetRenderItemUIPropertyValue(); } public void Decrement(LimitStackSlot ls) { Count -= ls.Weight; SetRenderItemUIPropertyValue(); } public bool HasReachedLimit() { return Count >= StackSlotLimit; } private LimitStackSlot GetLimitStackSlot(SlotUI slot) { foreach (LimitStackSlot ls in limitStackSlots) { if(slot == ls.Slot) { return ls; } } return null; } } }