public override void SetCraftingBlueprint(CraftingBlueprint blueprint)
        {
            base.SetCraftingBlueprint(blueprint);

            if (window.isVisible == false)
            {
                return;
            }

            blueprintRequiredItemsPool.DestroyAll();
            foreach (var item in blueprint.requiredItems)
            {
                var ui = blueprintRequiredItemsPool.Get();
                item.item.currentStackSize = (uint)item.amount;
                ui.transform.SetParent(blueprintRequiredItemsContainer);
                InventoryUtility.ResetTransform(ui.transform);

                ui.item = item.item;
                if (InventoryManager.GetItemCount(item.item.ID, currentCategory.alsoScanBankForRequiredItems) >= item.amount)
                {
                    ui.icon.color = itemsAvailableColor;
                }
                else
                {
                    ui.icon.color = itemsNotAvailableColor;
                }

                ui.Repaint();
                item.item.currentStackSize = 1; // Reset
            }
        }
        protected virtual void SetBlueprintResults(CraftingBlueprint blueprint)
        {
            if (blueprintItemResultContainer != null)
            {
                if (blueprint != null)
                {
                    foreach (Transform child in blueprintItemResultContainer)
                    {
                        Destroy(child.gameObject);
                    }

                    foreach (var row in blueprint.resultItems)
                    {
                        var wrapper = Instantiate <ItemCollectionSlotUIBase>(blueprintItemResultPrefab);

                        wrapper.item = row.item;
                        wrapper.item.currentStackSize = row.amount;
                        wrapper.Repaint();
                        wrapper.item.currentStackSize = 1; // Reset

                        wrapper.transform.SetParent(blueprintItemResultContainer);
                        InventoryUtility.ResetTransform(wrapper.transform);
                    }
                }
                else
                {
                    foreach (Transform child in blueprintItemResultContainer)
                    {
                        Destroy(child.gameObject);
                    }
                }
            }
        }
 private void CopyToSynced()
 {
     foreach (var item in toSyncFrom.items)
     {
         var c = item as UnityEngine.Component;
         if (c != null)
         {
             c.transform.SetParent(toSyncToContainer);
             InventoryUtility.ResetTransform(c.transform);
         }
     }
 }
        protected virtual void UpdateEquipLocations(Transform rootTransform)
        {
            foreach (var equipLoc in equipmentBinders)
            {
                if (equipLoc.findDynamic && string.IsNullOrEmpty(equipLoc.equipTransformPath) == false)
                {
                    Transform equipTransform = null;
                    InventoryUtility.FindChildTransform(rootTransform, equipLoc.equipTransformPath, ref equipTransform);
                    equipLoc.equipTransform = equipTransform;

                    Assert.IsNotNull(equipLoc.equipTransform, "Equip transform path is not valid (" + equipLoc.equipTransformPath + ")");
                }
            }
        }
Ejemplo n.º 5
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
                InventoryUtility.ResetTransform(item.transform);

                item.Repaint(message);

                AudioManager.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;
            }
        }
//        [SerializeField]
//        protected bool copySphereColliders;

        protected EquippableInventoryItem CreateDefaultCopy(EquippableInventoryItem item)
        {
            var copy = Instantiate <EquippableInventoryItem>(item);

            // Remove the default components, to prevent the user from looting an equipped item.
            Destroy(copy.GetComponent <ITriggerInputHandler>() as UnityEngine.Component);
            Destroy(copy.GetComponent <TriggerBase>());
            Destroy(copy.GetComponent <InventoryItemBase>());

            var rigid = copy.gameObject.GetComponent <Rigidbody>();

            if (rigid != null)
            {
                rigid.isKinematic = true;
            }

            var rigid2D = copy.gameObject.GetComponent <Rigidbody2D>();

            if (rigid2D != null)
            {
                rigid2D.isKinematic = true;
            }

            var cols = copy.gameObject.GetComponentsInChildren <Collider>(true);

            foreach (var col in cols)
            {
                col.isTrigger = true;
            }

            var cols2D = copy.gameObject.GetComponentsInChildren <Collider2D>(true);

            foreach (var col2D in cols2D)
            {
                col2D.isTrigger = true;
            }

            copy.gameObject.SetActive(true);
            InventoryUtility.SetLayerRecursive(copy.gameObject, InventorySettingsManager.instance.settings.equipmentLayer);

            if (resizeItemsToScale1)
            {
                copy.transform.localScale = Vector3.one;
            }

            return(copy);
        }
Ejemplo n.º 7
0
        protected virtual void DrawUsageRequirements(InventoryItemBase item)
        {
            var separator = poolSeparators.Get();

            separator.transform.SetParent(container);
            InventoryUtility.ResetTransform(separator.transform);

            var box = poolCategoryBoxes.Get();

            // loop through all usage requirements...
            foreach (var itemProperty in item.usageRequirement)
            {
                // row title, message...
                var row  = poolRows.Get();
                var prop = itemProperty.stat;

                row.transform.SetParent(box.transform);
                InventoryUtility.ResetTransform(row.transform);

                row.title.text  = prop.statName;
                row.title.color = prop.color;

                row.message.text = prop.ToString(itemProperty.value,
                                                 overrideUsageRequirementString ? overrideUsageRequirementStringFormat : prop.valueStringFormat);

                if (changeUsageRequirementsColors)
                {
                    var p = PlayerManager.instance.currentPlayer;
                    if (p != null)
                    {
                        if (itemProperty.CanUse(p.inventoryPlayer))
                        {
                            row.message.color = usageRequirementHighEnoughColor;
                        }
                        else
                        {
                            row.message.color = usageRequirementToLowColor;
                        }
                    }
                }
            }

            box.transform.SetParent(container);
            InventoryUtility.ResetTransform(box.transform);
        }
Ejemplo n.º 8
0
        public virtual void AddMenuOption(string name, InventoryItemBase item, Action <InventoryItemBase> callback)
        {
            var obj = _pool.Get();

            obj.transform.SetParent(container);
            InventoryUtility.ResetTransform(obj.transform);

            obj.item      = item;
            obj.text.text = name;

            obj.button.onClick.AddListener(() =>
            {
                callback(obj.item);
                window.Hide();
            });

            _menuOptions.Add(new ContextMenuOption(name, callback, obj));
        }
Ejemplo n.º 9
0
        protected virtual void DrawItemInfo(InventoryItemBase item, LinkedList <ItemInfoRow[]> itemInfo)
        {
            int i = 0;

            foreach (var box in itemInfo)
            {
                i++;

                var boxObj = poolCategoryBoxes.Get();

                int addedRows = 0;
                foreach (var row in box)
                {
                    var rowObj = poolRows.Get();
                    rowObj.transform.SetParent(boxObj.transform);
                    InventoryUtility.ResetTransform(rowObj.transform);

                    rowObj.title.text  = row.title;
                    rowObj.title.color = row.titleColor;

                    rowObj.message.text  = row.text;
                    rowObj.message.color = row.textColor;

                    addedRows++;
                }

                boxObj.transform.SetParent(container);
                InventoryUtility.ResetTransform(boxObj.transform);

                if (i < itemInfo.Count && addedRows > 0 && separatorPrefab != null)
                {
                    // Add a separator
                    if (separatorPrefab != null)
                    {
                        var separator = poolSeparators.Get();
                        separator.transform.SetParent(container);
                        InventoryUtility.ResetTransform(separator.transform);
                    }
                }
            }
        }
        public override void SetCraftingCategory(CraftingCategory category)
        {
//            if (currentCategory == category)
//            {
//                return;
//            }

            base.SetCraftingCategory(category);

            categoryPool.DestroyAll();
            blueprintPool.DestroyAll();
            if (blueprintCraftAmountInput != null)
            {
                blueprintCraftAmountInput.text = "1"; // Reset
            }
            if (currentCategoryTitle != null)
            {
                currentCategoryTitle.text = category.name;
            }

            if (currentCategoryDescription != null)
            {
                currentCategoryDescription.text = category.description;
            }

            if (noBlueprintSelectedPage != null)
            {
                noBlueprintSelectedPage.Show();
            }

//            var blueprints = GetBlueprints(category);
//            if (blueprintCraftPage != null && blueprints.Length > 0)
//            {
//                SetBlueprint(blueprints[0]); // Select first blueprint
//                blueprintCraftPage.Show();
//            }

            ItemCategory lastItemCategory = null;
            Button       firstButton      = null;

            foreach (var b in GetBlueprints(category))
            {
                if (b.playerLearnedBlueprint == false)
                {
                    continue;
                }

                var blueprintObj = blueprintPool.Get();
                blueprintObj.transform.SetParent(blueprintsContainer);
                InventoryUtility.ResetTransform(blueprintObj.transform);
                blueprintObj.Repaint(b);

                if (blueprintCategoryPrefab != null)
                {
                    Assert.IsTrue(b.resultItems.Length > 0, "No reward items set");
                    var item = b.resultItems.First().item;
                    Assert.IsNotNull(item, "Empty reward row on blueprint!");

                    if (lastItemCategory != item.category)
                    {
                        lastItemCategory = item.category;

                        var uiCategory = categoryPool.Get();
                        uiCategory.Repaint(category, item.category);

                        uiCategory.transform.SetParent(blueprintsContainer);
                        blueprintObj.transform.SetParent(uiCategory.container);

                        InventoryUtility.ResetTransform(uiCategory.transform);
                        InventoryUtility.ResetTransform(blueprintObj.transform);
                    }
                }

                if (firstButton == null)
                {
                    firstButton = blueprintObj.button;
                }

                var bTemp = b; // Store capture list, etc.
                blueprintObj.button.onClick.AddListener(() =>
                {
                    currentBlueprint = bTemp;
                    SetCraftingBlueprint(currentBlueprint);

                    if (blueprintCraftPage != null && blueprintCraftPage.isVisible == false)
                    {
                        blueprintCraftPage.Show();
                    }
                });
            }

            if (firstButton != null)
            {
                firstButton.Select();
            }
        }