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); } }; }
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 virtual void OnDrag(PointerEventData eventData) { if (item != null && itemCollection != null && itemCollection.canDragInCollection) // Can only drag existing item { InventoryUIUtility.Drag(this, index, itemCollection, eventData); } }
public virtual void OnEndDrag(PointerEventData eventData) { if (item != null && itemCollection != null && itemCollection.canDragInCollection) { var lookup = InventoryUIUtility.EndDrag(this, index, itemCollection, eventData); // Didn't end on a button or used wrong key. if (lookup == null) { return; } if (lookup.endOnButton) { // Place on a slot lookup.startItemCollection.SwapOrMerge((uint)lookup.startIndex, lookup.endItemCollection, (uint)lookup.endIndex); } else if (lookup.startItemCollection.useReferences) { lookup.startItemCollection.SetItem((uint)lookup.startIndex, null); lookup.startItemCollection[lookup.startIndex].Repaint(); } else if (InventoryUIUtility.clickedUIElement == false) { TriggerDrop(); } } }
public virtual void OnPointerClick(PointerEventData eventData) { if (onUse == null) { return; } button.onClick.AddListener(() => { InventoryUIUtility.AudioPlayOneShot(onUse); }); }
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); } }
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; } }
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); }
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(); } }
/// <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); } } }
public virtual void OnBeginDrag(PointerEventData eventData) { if (itemCollection == null) { return; } if (item != null && eventData.button == PointerEventData.InputButton.Left && itemCollection.canDragInCollection) { // Create a copy var copy = GameObject.Instantiate <InventoryUIItemWrapper>(this); copy.index = index; copy.itemCollection = itemCollection; var copyComp = copy.GetComponent <RectTransform>(); copyComp.SetParent(InventorySettingsManager.instance.guiRoot); copyComp.transform.localPosition = new Vector3(copyComp.transform.localPosition.x, copyComp.transform.localPosition.y, 0.0f); copyComp.sizeDelta = GetComponent <RectTransform>().sizeDelta; InventoryUIUtility.BeginDrag(copy, (uint)copy.index, itemCollection, eventData); // Make sure they're the same size, copy doesn't handle this. } }
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); } }
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 virtual void Update() { // If the item is no longer visible but still hovering if (InventoryUIUtility.hoveringItem != null && InventoryUIUtility.hoveringItem.gameObject.activeInHierarchy == false) { InventoryUIUtility.ExitItem(InventoryUIUtility.hoveringItem, InventoryUIUtility.hoveringItem.index, InventoryUIUtility.hoveringItem.itemCollection, null); } if (InventoryUIUtility.hoveringItem != null && InventoryUIUtility.hoveringItem.item != null) { #region Handling borders if (InventorySettingsManager.instance.isUIWorldSpace == false) { if (moveWhenHitBorderHorizontal) { // Change the box if its about to fall of the screen if (Input.mousePosition.x + currentTransform.sizeDelta.x > Screen.width - borderMargins.x) { // Falls of the right currentTransform.pivot = new Vector2(defaultPivot.y, currentTransform.pivot.x); // Swap } else { currentTransform.pivot = new Vector2(defaultPivot.x, currentTransform.pivot.y); // Swap } } if (moveWhenHitBorderVertical) { if (Input.mousePosition.y - currentTransform.sizeDelta.y < 0.0f - borderMargins.y) { // Falls of the bottom currentTransform.pivot = new Vector2(currentTransform.pivot.x, defaultPivot.x); // Swap } else { currentTransform.pivot = new Vector2(currentTransform.pivot.x, defaultPivot.y); // Swap } } } #endregion if (InventorySettingsManager.instance.isUIWorldSpace) { var r = InventorySettingsManager.instance.guiRoot.GetComponent <UnityEngine.UI.GraphicRaycaster>(); var l = new List <RaycastResult>(); Vector3 p = Input.mousePosition; if (Application.isMobilePlatform && Input.touchCount > 0) { p = Input.GetTouch(0).position; } r.Raycast(new PointerEventData(null) { position = p, pressPosition = p }, l); p = Camera.main.ScreenToWorldPoint(p); if (l.Count > 0) { transform.position = new Vector3(p.x, p.y, l[0].gameObject.transform.position.z); } } else { transform.position = Input.mousePosition; } if (InventoryUIUtility.hoveringItem != cacheItem) { cacheItem = InventoryUIUtility.hoveringItem; Repaint(cacheItem, cacheItem.item.GetInfo()); } //if (lastWindow != null) //{ // if (lastWindow.animator.enabled || lastWindow.isVisible == false) // return; //} if (window.isVisible == false) { window.Show(); } } else { if (window.isVisible) { window.Hide(); } } }
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(); }; }
public virtual void OnPointerExit(PointerEventData eventData) { InventoryUIUtility.ExitItem(this, index, itemCollection, eventData); }