protected override void OnGamePresentationUpdate() { if (SimWorld.TryGetBufferReadOnly(SimEntity, out DynamicBuffer <InventoryItemReference> items)) { if ((items.Length == 1)) { if (!_appearanceChanged) { _appearanceChanged = true; _spriteContainer.localScale = new Vector3(_scaleChange, _scaleChange, 1); InventoryItemReference item = items[0]; if (SimWorld.TryGetComponent(item.ItemEntity, out SimAssetId itemIDComponent)) { ItemAuth itemAuth = PresentationHelpers.FindItemAuth(itemIDComponent); _chestRenderer.sprite = itemAuth.Icon; } _bgRenderer.gameObject.SetActive(true); _currentAnimation = _spriteContainer.DOMoveY(transform.position.y + _yDisplacement, _animationDuration).SetLoops(-1, LoopType.Yoyo).SetEase(Ease.InOutSine); } } else { _appearanceChanged = false; _bgRenderer.gameObject.SetActive(false); _spriteContainer.localScale = new Vector3(1, 1, 1); _currentAnimation?.Kill(); } } }
private void UpdateInventorySlots() { if (SimWorld.TryGetBufferReadOnly(Cache.LocalPawn, out DynamicBuffer <InventoryItemReference> inventory)) { List <DisplayedItemData> displayedInventory = ListPool <DisplayedItemData> .Take(); // gather all items to display for (int i = 0; i < inventory.Length; i++) { Entity item = inventory[i].ItemEntity; if (SimWorld.TryGetComponent(item, out SimAssetId itemAssetId)) { ItemAuth itemGameActionAuth = PresentationHelpers.FindItemAuth(itemAssetId); if (itemGameActionAuth != null && !itemGameActionAuth.HideInInventory) { displayedInventory.Add(new DisplayedItemData() { ItemAuth = itemGameActionAuth, ItemRef = inventory[i], Index = i }); } } } // Ajust Slot amount accordiwdng to inventory max size InventoryCapacity inventoryCapacity = SimWorld.GetComponent <InventoryCapacity>(Cache.LocalPawn); _gridLayoutGroup.constraintCount = min(_maxCollumns, inventoryCapacity); PresentationHelpers.ResizeGameObjectList(_slotVisuals, max(min(_maxCollumns, inventoryCapacity), displayedInventory.Count), _inventorySlotPrefab, _slotsContainer); for (int i = 0; i < _slotVisuals.Count; i++) { if (i < displayedInventory.Count) { Entity item = displayedInventory[i].ItemRef.ItemEntity; int stacks = displayedInventory[i].ItemRef.Stacks; if (stacks == 1 && !SimWorld.GetComponent <StackableFlag>(item)) { stacks = -1; // used in display to hide stacks } _slotVisuals[i].UpdateCurrentInventorySlot(displayedInventory[i].ItemAuth, displayedInventory[i].Index, GetSlotShotcut(i), OnIntentionToUsePrimaryActionOnItem, OnIntentionToUseSecondaryActionOnItem, stacks); if (!CommonReads.CanUseItem(SimWorld, Cache.LocalPawn, item)) { _slotVisuals[i].UpdateDisplayAsUnavailable(item); } } else { _slotVisuals[i].UpdateCurrentInventorySlot(null, i, GetSlotShotcut(i), null, null); } } ListPool <DisplayedItemData> .Release(displayedInventory); } }