public virtual void UnUse(bool fireEvents = true)
        {
            if (isActive == false)
            {
                return;
            }

            if (handleWindowDirectly && fireEvents)
            {
                window.Hide();
            }

            if (unUseAnimation != null && animator != null)
            {
                animator.Play(unUseAnimation.name);
            }

            if (unUseAudioClip != null)
            {
                InventoryUIUtility.AudioPlayOneShot(unUseAudioClip);
            }

            isActive = false;

            if (OnTriggerUnUse != null && fireEvents)
            {
                OnTriggerUnUse();
            }
        }
        public AudioClip onAddItemAudioClip; // When an item is added to the inventory


        public override void Awake()
        {
            base.Awake();

            InventoryManager.AddBankCollection(this);

            if (sortButton != null)
            {
                sortButton.onClick.AddListener(() =>
                {
                    SortCollection();

                    if (sortAudioClip)
                    {
                        InventoryUIUtility.AudioPlayOneShot(sortAudioClip);
                    }
                });
            }

            // Listen for events
            OnAddedItem += (InventoryItemBase item, uint slot, uint amount) =>
            {
                if (onAddItemAudioClip != null)
                {
                    InventoryUIUtility.AudioPlayOneShot(onAddItemAudioClip);
                }
            };
            OnSwappedItems += (ItemCollectionBase fromCollection, uint fromSlot, ItemCollectionBase toCollection, uint toSlot) =>
            {
                if (swapItemAudioClip != null)
                {
                    InventoryUIUtility.AudioPlayOneShot(swapItemAudioClip);
                }
            };
        }
예제 #3
0
        public virtual void OnPointerClick(PointerEventData eventData)
        {
            if (onUse == null)
            {
                return;
            }

            button.onClick.AddListener(() =>
            {
                InventoryUIUtility.AudioPlayOneShot(onUse);
            });
        }
예제 #4
0
        public AudioClip onAddItemAudioClip; // When an item is added to the inventory


        public override void Awake()
        {
            base.Awake();

            if (isLootToInventory)
            {
                InventoryManager.AddInventoryCollection(this, lootPriority);
            }

            if (sortButton != null)
            {
                sortButton.onClick.AddListener(() =>
                {
                    SortCollection();

                    if (sortAudioClip)
                    {
                        InventoryUIUtility.AudioPlayOneShot(sortAudioClip);
                    }
                });
            }

            // Listen for events
            OnAddedItem += (InventoryItemBase items, uint slot, uint amount) =>
            {
                if (onAddItemAudioClip != null)
                {
                    InventoryUIUtility.AudioPlayOneShot(onAddItemAudioClip);
                }
            };
            OnSwappedItems += (ItemCollectionBase fromCollection, uint fromSlot, ItemCollectionBase toCollection, uint toSlot) =>
            {
                if (swapItemAudioClip != null)
                {
                    InventoryUIUtility.AudioPlayOneShot(swapItemAudioClip);
                }
            };
            OnDroppedItem += (InventoryItemBase item, uint slot, GameObject droppedObj) =>
            {
            };
            OnResized += (uint fromSize, uint toSize) =>
            {
                StartCoroutine(SetScrollToZero());
            };
            OnSorted += () =>
            {
            };
            OnGoldChanged += (float goldAdded) =>
            {
            };
        }
        public virtual void NotifyItemBoughtFromVendor(InventoryItemBase item, uint amount)
        {
            InventoryManager.instance.lang.vendorBoughtItemFromVendor.Show(item.name, item.description, amount, currentVendor.vendorName, InventorySettingsManager.instance.currencyFormatter.Format(item.buyPrice * amount));

            if (audioWhenBoughtItemFromVendor != null)
            {
                InventoryUIUtility.AudioPlayOneShot(audioWhenBoughtItemFromVendor);
            }

            if (OnBoughtItemFromVendor != null)
            {
                OnBoughtItemFromVendor(item, amount, currentVendor);
            }
        }
예제 #6
0
        public virtual void AddMessage(InventoryNoticeMessage message)
        {
            // Fire even if we do the nullcheck, just incase other people want to use their own implementation.
            if (OnNewMessage != null)
            {
                OnNewMessage(message, message.parameters);
            }

            if (string.IsNullOrEmpty(message.message))
            {
                return;
            }

            bool scrollbarAtBottom = false;

            if (scrollRect != null && scrollRect.verticalScrollbar != null && scrollRect.verticalScrollbar.value < 0.05f)
            {
                scrollbarAtBottom = true;
            }

            // Incase we don't actually want to display anything and just port the data to some other class through events.
            if (noticeRowPrefab != null)
            {
                var item = pool.Get();
                //var item = GameObject.Instantiate<NoticeMessageUI>(noticeRowPrefab);
                item.transform.SetParent(container);
                item.transform.SetSiblingIndex(0); // Move to the top of the list
                item.SetMessage(message);

                if (onNewMessageAudioClip != null)
                {
                    InventoryUIUtility.AudioPlayOneShot(onNewMessageAudioClip);
                }

                messages.Add(item);
            }

            if (messages.Count > maxMessages)
            {
                StartCoroutine(DestroyAfter(messages[0], messages[0].hideAnimation.length));
                messages[0].Hide();
                messages.RemoveAt(0);
            }

            if (scrollbarAtBottom)
            {
                scrollRect.verticalNormalizedPosition = 0.0f;
            }
        }
예제 #7
0
        public virtual void Show()
        {
            if (isVisible)
            {
                return;
            }

            isVisible        = true;
            animator.enabled = true;

            SetChildrenActive(true);
            if (showAnimation != null)
            {
                animator.Play(showAnimation.name);
                if (showCoroutine != null)
                {
                    StopCoroutine(showCoroutine);
                }

                showCoroutine = _Show(showAnimation);
                StartCoroutine(showCoroutine);
            }

            // Show pages
            foreach (var page in pages)
            {
                if (page.isDefaultPage)
                {
                    page.Show();
                }
                else if (page.isVisible)
                {
                    page.Hide();
                }
            }

            if (showAudioClip != null)
            {
                InventoryUIUtility.AudioPlayOneShot(showAudioClip);
            }

            if (OnShow != null)
            {
                OnShow();
            }
        }
예제 #8
0
        public bool Equip()
        {
            // Used from some collection, equip
            bool added = InventoryManager.instance.inventory.AddSlots(extendInventoryBySlots);

            if (added)
            {
                if (playOnEquip)
                {
                    InventoryUIUtility.AudioPlayOneShot(playOnEquip);
                }

                return(true);
            }

            return(false);
        }
        /// <summary>
        /// Cancels any crafting action that is active. For example when you're crafting an item with a timer, cancel it when you walk away.
        /// </summary>
        public void CancelActiveCraft()
        {
            if (activeCraft != null)
            {
                StopCoroutine(activeCraft);
                InventoryManager.instance.lang.craftingCanceled.Show(currentBlueprint.itemResult.name, currentBlueprint.itemResult.description);
                activeCraft = null;

                if (canceledCraftItem != null)
                {
                    InventoryUIUtility.AudioPlayOneShot(canceledCraftItem);
                }

                if (OnCraftCanceled != null)
                {
                    OnCraftCanceled(currentCategory, currentBlueprint, currentCraftProgress);
                }
            }
        }
예제 #10
0
        public virtual void Hide()
        {
            //Debug.Log("isfuckC# " + isVisible);
            if (isVisible == false)
            {
                return;
            }


            isVisible = false;
            if (OnHide != null)
            {
                OnHide();
            }

            if (hideAudioClip != null)
            {
                InventoryUIUtility.AudioPlayOneShot(hideAudioClip);
            }

            if (hideAnimation != null)
            {
                animator.enabled = true;
                animator.Play(hideAnimation.name);

                if (hideCoroutine != null)
                {
                    StopCoroutine(hideCoroutine);
                }

                hideCoroutine = _Hide(hideAnimation);
                StartCoroutine(hideCoroutine);
            }
            else
            {
                animator.enabled = false;
                SetChildrenActive(false);
            }
        }
예제 #11
0
        public override int Use()
        {
            int used = base.Use();

            if (used < 0)
            {
                return(used);
            }

            // Do something with item
            currentStackSize--; // Remove 1

            // TODO: Add some health or something

            NotifyItemUsed(1, true);

            if (audioClipWhenUsed != null)
            {
                InventoryUIUtility.AudioPlayOneShot(audioClipWhenUsed);
            }

            return(1); // 1 item used
        }
        public virtual void Use(bool fireEvents = true)
        {
            if (isActive)
            {
                return;
            }

            if (handleWindowDirectly && fireEvents)
            {
                if (toggleWhenTriggered)
                {
                    window.Toggle();
                }
                else if (window.isVisible == false)
                {
                    window.Show();
                }
            }

            if (useAnimation != null)
            {
                animator.Play(useAnimation.name);
            }

            if (useAudioClip != null)
            {
                InventoryUIUtility.AudioPlayOneShot(useAudioClip);
            }

            isActive = true;

            if (OnTriggerUse != null && fireEvents)
            {
                OnTriggerUse();
            }
        }
        public override void Awake()
        {
            equipSlotFields = container.GetComponentsInChildren <InventoryEquippableField>(true);
            characterStats  = new Dictionary <string, List <InventoryEquipStatRowLookup> >(ItemManager.instance.equipStats.Length);
            base.Awake();


            if (statusRowPrefab != null)
            {
                rowsPool = new InventoryPool <InventoryEquipStatRowUI>(statusRowPrefab, 64);
            }

            if (statusCategoryPrefab != null)
            {
                categoryPool = new InventoryPool <InventoryEquipStatCategoryUI>(statusCategoryPrefab, 8);
            }

            InventoryManager.AddEquipCollection(this, equipPriority);
            //UpdateCharacterStats();



            OnSwappedItems += (fromCollection, fromSlot, toCollection, toSlot) =>
            {
                if (fromCollection == toCollection)
                {
                    return; // Just moving inside collection, no need to re-do anything.
                }
                if (toCollection[toSlot].item != null && fromCollection[fromSlot].item != null)
                {
                    // Actually swapped item
                    var item = fromCollection[fromSlot].item as EquippableInventoryItem;
                    if (item != null)
                    {
                        item.NotifyItemUnEquipped();
                    }
                }

                if (toCollection == this)
                {
                    // Move to this inventory
                    UpdateCharacterStats();

                    var i = toCollection[toSlot].item as EquippableInventoryItem;
                    if (i != null)
                    {
                        bool handled = i.HandleLocks(equipSlotFields[i.index], this);
                        if (handled)
                        {
                            i.NotifyItemEquipped(equipSlotFields[i.index]);

                            if (i.playOnEquip != null)
                            {
                                InventoryUIUtility.AudioPlayOneShot(i.playOnEquip);
                            }
                        }
                    }
                }
                else if (fromCollection == this)
                {
                    UpdateCharacterStats();

                    // Moved from this collection to -> toCollection
                    var i = toCollection[toSlot].item as EquippableInventoryItem;
                    if (i != null)
                    {
                        i.NotifyItemUnEquipped();
                    }
                }
            };


            window.OnShow += () =>
            {
                RepaintStats();
            };
        }