示例#1
0
        public void EquipItem(string name)
        {
            var item = items.FirstOrDefault(i => i.item.name == name);

            if (item == null)
            {
                Debug.Log("[MobileVRInventory]:: Attempted to equip an item that wasn't in the inventory! ('" + name + "')");
                return;
            }

            if (equippedItem != null)
            {
                var stopHere = false;

                // if we're 'deselecting' the currently equipped item, then don't re-equip it
                if (equippedItem == item.item)
                {
                    stopHere = true;
                }

                UnEquipItem();

                if (stopHere)
                {
                    return;
                }
            }

            equippedItem = item.item;
            var prefab = item.item.itemPrefab;

            if (prefab != null)
            {
                var handItem = GameObject.Instantiate(prefab);
                handItem.SetParent(handPosition);


                handItem.localPosition = prefab.localPosition;
                handItem.localRotation = prefab.localRotation;
                handItem.localScale    = prefab.localScale;

                equippedItemInstance  = handItem.GetComponent <EquippableInventoryItemBase>();
                equippedItemTransform = handItem;

                // fire the equip event
                if (equippedItemInstance != null)
                {
                    equippedItemInstance.OnItemEquipped();
                }
            }

            itemEquippedThisFrame = true;
        }
        public void SetData(InventoryItemData data, int quantity = 1)
        {
            itemData = data;

            if (image != null)
            {
                image.sprite = data.image;
            }
            if (nameText != null)
            {
                nameText.text = data.name;
            }

            if (quantityText != null)
            {
                quantityText.text = String.Format("x{0}", quantity);
                // only show the quantity text if we have more than one of the item
                quantityText.gameObject.SetActive(quantity > 1);
            }
        }
        public override void OnInspectorGUI()
        {
            serializedObject.Update();

            InventoryItemData itemData = itemTarget.itemData;

            EditorGUI.BeginChangeCheck();

            itemDatabase.objectReferenceValue = EditorGUILayout.ObjectField("Item Database", itemDatabase.objectReferenceValue, typeof(InventoryItemDatabase), false);

            if (itemDatabase.objectReferenceValue == null)
            {
                EditorGUILayout.HelpBox("Please select an Inventory Item Database", MessageType.Warning);
            }
            else if (itemTarget.itemDatabase != null)
            {
                var _itemDatabase  = itemTarget.itemDatabase;
                var availableItems = _itemDatabase.items.Select(i => i.name).ToArray();
                var selectedIndex  = itemTarget.itemData != null?availableItems.ToList().IndexOf(itemTarget.itemData.name) : 0;

                selectedIndex = EditorGUILayout.Popup("Item", selectedIndex, availableItems);

                if (selectedIndex >= 0)
                {
                    itemData = _itemDatabase.GetItem(availableItems[selectedIndex]);
                }

                quantity.intValue = EditorGUILayout.IntField("Quantity", quantity.intValue);
            }

            if (EditorGUI.EndChangeCheck())
            {
                serializedObject.ApplyModifiedProperties();

                foreach (var t in targets)
                {
                    (t as InventoryItem).itemData = itemData;
                }
                UnityEditor.SceneManagement.EditorSceneManager.MarkSceneDirty(itemTarget.gameObject.scene);
            }
        }
示例#4
0
        public void UnEquipItem()
        {
            if (equippedItem == null)
            {
                return;
            }

            equippedItem = null;

            // fire the Unequip event
            if (equippedItemInstance != null)
            {
                equippedItemInstance.OnItemUnequipped();
            }

            // Remove the object
            if (equippedItemTransform != null)
            {
                GameObject.Destroy(equippedItemTransform.gameObject);
            }
        }