示例#1
0
        private void CanUseItem(vItem item, ref List <bool> validateResult)
        {
            // search for the attribute 'Health'
            if (item.GetItemAttribute(vItemAttributes.Health) != null)
            {
                // the variable valid will identify if the currentHealth is lower than the maxHealth, allowing to use the item
                var valid = tpController.currentHealth < tpController.maxHealth;
                if (valid != canUse || !firstRun)
                {
                    canUse   = valid;
                    firstRun = true;
                    // trigger a custom text if there is a HUDController in the scene
                    vHUDController.instance.ShowText(valid ? "Increase health" : "Can't use " + item.name + " because your health is full", 4f);
                }

                if (!valid)
                {
                    validateResult.Add(valid);
                }
            }
        }
示例#2
0
        protected virtual void CheckTwoHandItem(EquipPoint equipPoint, vItem item)
        {
            if (item == null)
            {
                return;
            }
            var opposite = equipPoints.Find(ePoint => ePoint.area != null && ePoint.equipPointName.Equals("LeftArm") && ePoint.area.currentEquipedItem != null);

            if (equipPoint.equipPointName.Equals("LeftArm"))
            {
                opposite = equipPoints.Find(ePoint => ePoint.area != null && ePoint.equipPointName.Equals("RightArm") && ePoint.area.currentEquipedItem != null);
            }
            else if (!equipPoint.equipPointName.Equals("RightArm"))
            {
                return;
            }
            if (opposite != null && (item.twoHandWeapon || opposite.area.currentEquipedItem.twoHandWeapon))
            {
                opposite.area.RemoveCurrentItem();
            }
        }
示例#3
0
 public void LeaveItem(vItem item, int amount)
 {
     onLeaveItem.Invoke(item, amount);
     item.amount -= amount;
     if (item.amount <= 0 && items.Contains(item))
     {
         if (item.type != vItemType.Consumable)
         {
             var equipPoint = equipPoints.Find(ep => ep.equipmentReference.item == item || ep.area != null && ep.area.ValidSlots.Find(slot => slot.item == item));
             if (equipPoint != null)
             {
                 if (equipPoint.area)
                 {
                     equipPoint.area.RemoveItem(item);
                 }
             }
         }
         items.Remove(item);
         Destroy(item);
     }
 }
示例#4
0
        /// <summary>
        /// Event called from inventory UI to open <see cref="vItemWindow"/> when submit slot
        /// </summary>
        /// <param name="slot">target slot</param>
        public void OnPickItem(vItemSlot slot)
        {
            if (!currentSelectedSlot)
            {
                currentSelectedSlot = lastSelectedSlot;
            }

            if (!currentSelectedSlot)
            {
                return;
            }

            if (currentSelectedSlot.item != null && slot.item != currentSelectedSlot.item)
            {
                currentSelectedSlot.item.isInEquipArea = false;
                var item = currentSelectedSlot.item;
                if (item == slot.item)
                {
                    lastEquipedItem = item;
                }
                currentSelectedSlot.RemoveItem();
                onUnequipItem.Invoke(this, item);
            }

            if (slot.item != currentSelectedSlot.item)
            {
                if (onPickUpItemCallBack != null)
                {
                    onPickUpItemCallBack(this, slot);
                }
                currentSelectedSlot.AddItem(slot.item);
                onEquipItem.Invoke(this, currentSelectedSlot.item);
            }
            currentSelectedSlot.OnCancel();
            currentSelectedSlot = null;
            lastSelectedSlot    = null;
            itemPicker.gameObject.SetActive(false);
            onFinishPickUpItem.Invoke();
        }
        public virtual void UnequipItem(vEquipArea equipArea, vItem item)
        {
            onUnequipItem.Invoke(equipArea, item);

            //if (item != equipArea.lastEquipedItem) return;
            var equipPoint = equipPoints.Find(ep => ep.equipPointName == equipArea.equipPointName && ep.equipmentReference.item != null && ep.equipmentReference.item == item);

            if (equipPoint != null && item != null)
            {
                equipTimer = item.disableDelayTime;
                var type = item.type;
                if (type != vItemType.Consumable)
                {
                    if (!inventory.isOpen && !inEquip && equipPoint.equipmentReference.equipedObject.activeInHierarchy)
                    {
                        animator.SetBool("FlipEquip", equipArea.equipPointName.Contains("Left"));
                        animator.CrossFade(item.DisableAnim, 0.25f);
                    }
                    StartCoroutine(UnequipItemRoutine(equipPoint, item));
                }
            }
        }
示例#6
0
 public virtual void UseItem(vItem item)
 {
     if (item)
     {
         onUseItem.Invoke(item);
         if (item.attributes != null && item.attributes.Count > 0 && applyAttributeEvents.Count > 0)
         {
             foreach (ApplyAttributeEvent attributeEvent in applyAttributeEvents)
             {
                 var attributes = item.attributes.FindAll(a => a.name.Equals(attributeEvent.attribute));
                 foreach (vItemAttribute attribute in attributes)
                 {
                     attributeEvent.onApplyAttribute.Invoke(attribute.value);
                 }
             }
         }
         if (item.amount <= 0 && items.Contains(item))
         {
             items.Remove(item);
         }
     }
 }
示例#7
0
        public virtual void UnequipItem(vEquipArea equipArea, vItem item)
        {
            onUnequipItem.Invoke(equipArea, item);

            //if (item != equipArea.lastEquipedItem) return;
            var equipPoint = equipPoints.Find(ep => ep.equipPointName == equipArea.equipPointName && ep.equipmentReference.item != null && ep.equipmentReference.item == item);

            if (equipPoint != null && item != null)
            {
                equipTimer = item.unequipDelayTime;
                var type = item.type;
                if (type != vItemType.Consumable)
                {
                    if (!inventory.isOpen && !inEquip && equipPoint.equipmentReference.equipedObject.activeInHierarchy)
                    {
                        animator.SetInteger("EquipItemID", equipArea.equipPointName.Contains("Right") ? item.EquipID : -item.EquipID);
                        animator.SetTrigger("EquipItem");
                    }
                    StartCoroutine(UnequipItemRoutine(equipPoint, item));
                }
            }
        }
示例#8
0
        /// <summary>
        /// Updates the <seealso cref="ChangeEquipmentControl.display"/>
        /// </summary>
        /// <param name="equipArea"></param>
        /// <param name="item"></param>
        /// <param name="removeItem"></param>
        protected virtual void ChangeEquipmentDisplay(vEquipArea equipArea, vItem item, bool removeItem = true)
        {
            if (changeEquipmentControllers.Count > 0)
            {
                var changeEquipControl = changeEquipmentControllers.Find(changeEquip => changeEquip.equipArea != null &&
                                                                         changeEquip.equipArea == equipArea && changeEquip.display != null);

                if (changeEquipControl != null)
                {
                    if (removeItem && changeEquipControl.display.item == item)
                    {
                        changeEquipControl.display.RemoveItem();
                        changeEquipControl.display.ItemIdentifier(changeEquipControl.equipArea.indexOfEquipedItem + 1, true);
                    }
                    else if (equipArea.currentEquipedItem == item)
                    {
                        changeEquipControl.display.AddItem(item);
                        changeEquipControl.display.ItemIdentifier(changeEquipControl.equipArea.indexOfEquipedItem + 1, true);
                    }
                }
            }
        }
 protected virtual void ShowItemListWindow(vItem item = null)
 {
     if (item == null)
     {
         vItemListWindow.CreateWindow(manager.itemListData);
     }
     else if (manager.itemListData.inEdition)
     {
         if (vItemListWindow.Instance == null)
         {
             vItemListWindow.CreateWindow(manager.itemListData, manager.itemListData.items.IndexOf(item));
         }
     }
     else
     {
         vItemListWindow.CreateWindow(manager.itemListData, manager.itemListData.items.IndexOf(item));
     }
     if (item)
     {
         vItemListWindow.SetCurrentSelectedItem(manager.itemListData.items.IndexOf(item));
     }
 }
示例#10
0
        public void AddItemToEquipSlot(int indexOfSlot, vItem item)
        {
            if (indexOfSlot < equipSlots.Count && item != null)
            {
                var slot = equipSlots[indexOfSlot];

                if (slot != null && slot.isValid && slot.itemType.Contains(item.type))
                {
                    if (slot.item != null && slot.item != item)
                    {
                        if (currentEquipedItem == slot.item)
                        {
                            lastEquipedItem = slot.item;
                        }
                        slot.item.isInEquipArea = false;
                        onUnequipItem.Invoke(this, item);
                    }
                    slot.AddItem(item);
                    onEquipItem.Invoke(this, item);
                }
            }
        }
示例#11
0
        /// <summary>
        /// Add an item to an slot
        /// </summary>
        /// <param name="indexOfSlot">index of target Slot</param>
        /// <param name="item">target Item</param>
        public void AddItemToEquipSlot(int indexOfSlot, vItem item, bool autoEquip = false)
        {
            if (indexOfSlot < equipSlots.Count && item != null)
            {
                var slot = equipSlots[indexOfSlot];

                if (slot != null && slot.isValid && slot.itemType.Contains(item.type))
                {
                    var sameSlot = equipSlots.Find(s => s.item == item && s != slot);

                    if (sameSlot != null)
                    {
                        RemoveItemOfEquipSlot(equipSlots.IndexOf(sameSlot));
                    }

                    if (slot.item != null && slot.item != item)
                    {
                        if (currentEquippedItem == slot.item)
                        {
                            lastEquipedItem = slot.item;
                        }
                        slot.item.isInEquipArea = false;
                        onUnequipItem.Invoke(this, slot.item);
                    }

                    item.isInEquipArea = true;
                    slot.AddItem(item);
                    if (autoEquip)
                    {
                        SetEquipSlot(indexOfSlot);
                    }
                    else
                    {
                        onEquipItem.Invoke(this, item);
                    }
                }
            }
        }
        private void AddItem(vItem item)
        {
            if (item.name.Contains("(Clone)"))
            {
                item.name = item.name.Replace("(Clone)", string.Empty);
            }

            if (item && !itemList.items.Find(it => it.name.ToClearUpper().Equals(item.name.ToClearUpper())))
            {
                AssetDatabase.AddObjectToAsset(item, AssetDatabase.GetAssetPath(itemList));
                item.hideFlags = HideFlags.HideInHierarchy;

                if (itemList.items.Exists(it => it.id.Equals(item.id)))
                {
                    item.id = GetUniqueID();
                }
                itemList.items.Add(item);
                OrderByID(ref itemList.items);
                serializedObject.ApplyModifiedProperties();
                EditorUtility.SetDirty(itemList);
                AssetDatabase.SaveAssets();
            }
        }
示例#13
0
 /// <summary>
 /// Equip item to specific area and specific slot
 /// </summary>
 /// <param name="indexOfArea">Index of Equip Area</param>
 /// <param name="indexOfSlot">Index of Slot in Equip Area</param>
 /// <param name="item">Item to Equip</param>
 /// <param name="immediate">Force immediate</param>
 public virtual void EquipItemToEquipArea(int indexOfArea, int indexOfSlot, vItem item, bool immediate = false)
 {
     if (!inventory)
     {
         return;
     }
     if (immediate)
     {
         inventory.isOpen = immediate;
     }
     if (inventory.equipAreas != null && indexOfArea < inventory.equipAreas.Length)
     {
         var area = inventory.equipAreas[indexOfArea];
         if (area != null)
         {
             area.AddItemToEquipSlot(indexOfSlot, item);
         }
     }
     if (immediate)
     {
         inventory.isOpen = false;
     }
 }
        public void EquipWeapon(vEquipArea equipArea, vItem item)
        {
            var slotsInArea = equipArea.ValidSlots;

            if (slotsInArea != null && slotsInArea.Count > 0 && holderAreas.ContainsKey(equipArea.equipPointName))
            {
                // Check All Holders to Display
                for (int i = 0; i < slotsInArea.Count; i++)
                {
                    if (slotsInArea[i].item != null)
                    {
                        var holder = holderAreas[equipArea.equipPointName].Find(h => slotsInArea[i].item && slotsInArea[i].item.id == h.itemID &&
                                                                                ((equipArea.currentEquipedItem &&
                                                                                  equipArea.currentEquipedItem != item &&
                                                                                  equipArea.currentEquipedItem != slotsInArea[i].item &&
                                                                                  equipArea.currentEquipedItem.id != item.id) || !equipArea.currentEquipedItem));

                        if (holder)
                        {
                            holder.SetActiveHolder(true);
                            holder.SetActiveWeapon(true);
                        }
                    }
                }
                // Check Current Item to Equip with time
                if (equipArea.currentEquipedItem != null)
                {
                    var holder = holderAreas[equipArea.equipPointName].Find(h => h.itemID == equipArea.currentEquipedItem.id);
                    if (holder)
                    {
                        // Unhide Holder and hide Equiped weapon
                        StartCoroutine(EquipRoutine(equipArea.currentEquipedItem.equipDelayTime, (itemManager.inventory != null && itemManager.inventory.isOpen),
                                                    () => { holder.SetActiveHolder(true); }, () => { holder.SetActiveWeapon(false); }));
                    }
                }
            }
        }
示例#15
0
 public void OnUnequip(vItem item)
 {
     if (!weapon)
     {
         return;
     }
     if (!item)
     {
         return;
     }
     weapon.changeAmmoHandle = null;
     weapon.checkAmmoHandle  = null;
     if (weapon.secundaryWeapon)
     {
         var _equipments = weapon.secundaryWeapon.GetComponents <vIEquipment>();
         for (int i = 0; i < _equipments.Length; i++)
         {
             if (_equipments[i] != null)
             {
                 _equipments[i].OnUnequip(item);
             }
         }
     }
 }
示例#16
0
        //IEnumerator EquipItemRoutine(EquipPoint equipPoint, vItem item)
        protected virtual IEnumerator EquipItemRoutine(EquipPoint equipPoint, vItem item)
        {
            if (!inEquip)
            {
                inventory.canEquip = false;
                inEquip            = true;

                if (equipPoint != null)
                {
                    if (item.originalObject)
                    {
                        if (equipPoint.equipmentReference != null && equipPoint.equipmentReference.equipedObject != null)
                        {
                            var _equipmentsA = equipPoint.equipmentReference.equipedObject.GetComponents <vIEquipment>();
                            for (int i = 0; i < _equipmentsA.Length; i++)
                            {
                                if (_equipmentsA[i] != null)
                                {
                                    _equipmentsA[i].OnUnequip(equipPoint.equipmentReference.item);
                                    _equipmentsA[i].equipPoint = null;
                                }
                            }
                            Destroy(equipPoint.equipmentReference.equipedObject);
                        }
                        if (!inventory.isOpen)
                        {
                            while (equipTimer > 0)
                            {
                                if (item == null)
                                {
                                    break;
                                }
                                yield return(null);

                                equipTimer -= Time.deltaTime;
                            }
                        }
                        var point          = equipPoint.handler.customHandlers.Find(p => p.name == item.customHandler);
                        var equipTransform = point != null ? point : equipPoint.handler.defaultHandler;
                        var equipedObject  = Instantiate(item.originalObject, equipTransform.position, equipTransform.rotation) as GameObject;

                        equipedObject.transform.parent = equipTransform;

                        if (equipPoint.equipPointName.Contains("Left"))
                        {
                            var scale = equipedObject.transform.localScale;
                            scale.x *= -1;
                            equipedObject.transform.localScale = scale;
                        }

                        equipPoint.equipmentReference.item          = item;
                        equipPoint.equipmentReference.equipedObject = equipedObject;
                        var _equipments = equipPoint.equipmentReference.equipedObject.GetComponents <vIEquipment>();
                        for (int i = 0; i < _equipments.Length; i++)
                        {
                            if (_equipments[i] != null)
                            {
                                _equipments[i].OnEquip(equipPoint.equipmentReference.item);
                                _equipments[i].equipPoint = equipPoint;
                            }
                        }
                        equipPoint.onInstantiateEquiment.Invoke(equipedObject);
                    }
                    else if (equipPoint.equipmentReference != null && equipPoint.equipmentReference.equipedObject != null)
                    {
                        var _equipments = equipPoint.equipmentReference.equipedObject.GetComponents <vIEquipment>();
                        for (int i = 0; i < _equipments.Length; i++)
                        {
                            if (_equipments[i] != null)
                            {
                                _equipments[i].OnUnequip(equipPoint.equipmentReference.item);
                                _equipments[i].equipPoint = null;
                            }
                        }
                        Destroy(equipPoint.equipmentReference.equipedObject);
                        equipPoint.equipmentReference.item = null;
                    }
                }
                inEquip            = false;
                inventory.canEquip = true;
                if (equipPoint != null)
                {
                    CheckTwoHandItem(equipPoint, item);
                }
            }
        }
示例#17
0
 public void OnUnequip(vItem item)
 {
 }
        public virtual void OnGUI()
        {
            if (skin)
            {
                GUI.skin = skin;
            }
            var _color = GUI.color;

            if (OnSelectItem != null)
            {
                GUI.color = Color.red;
            }
            GUILayout.BeginVertical("Item List", "window");
            GUI.color = _color;
            GUILayout.Label(m_Logo, GUILayout.MaxHeight(25));

            GUILayout.BeginVertical("box");

            GUI.enabled  = !Application.isPlaying;
            itemList     = EditorGUILayout.ObjectField("ItemListData", itemList, typeof(vItemListData), false) as vItemListData;
            this.minSize = new Vector2(250, minSize.y);
            if (serializedObject == null && itemList != null)
            {
                serializedObject = new SerializedObject(itemList);
            }
            else if (itemList == null)
            {
                GUILayout.EndVertical();
                return;
            }

            serializedObject.Update();
            if (OnSelectItem == null)
            {
                if (!inDragItens && GUILayout.Button("Add Items"))
                {
                    inDragItens = true;
                }
                if (!inAddItem && GUILayout.Button("Create New Item"))
                {
                    addItem      = ScriptableObject.CreateInstance <vItem>();
                    addItem.name = "New Item";

                    currentItemDrawer = null;
                    inAddItem         = true;
                }
                if (inDragItens)
                {
                    GUILayout.BeginVertical("window");
                    EditorGUILayout.HelpBox("You can add items from other lists by selecting other lists in the ProjectWindow, click on 'Show items in Hierarchy' and drag & drop the item to the field bellow", MessageType.Info);
                    EditorGUILayout.HelpBox("New items will have their IDs modified if Same ID exits in Items List", MessageType.Warning);
                    DrawDragBox(ref newItems);
                    GUILayout.BeginVertical();
                    newItemsScrool = GUILayout.BeginScrollView(newItemsScrool, false, false, GUILayout.MaxHeight(Mathf.Clamp(newItems.Count * 25, 0, 500)));
                    OrderByID(ref newItems);
                    for (int i = 0; i < newItems.Count; i++)
                    {
                        GUILayout.BeginHorizontal();
                        if (itemList.items.Find(it => it.name.ToClearUpper().Equals(newItems[i].name.ToClearUpper())))
                        {
                            GUI.color = Color.red;
                            GUILayout.Label("EXIST"); EditorGUILayout.ObjectField(newItems[i], typeof(vItem), false);
                        }
                        else
                        {
                            GUI.color = Color.white;
                            EditorGUILayout.ObjectField(newItems[i], typeof(vItem), false);
                        }
                        GUI.color = Color.white;
                        if (GUILayout.Button("x", EditorStyles.miniButton, GUILayout.Width(20)))
                        {
                            newItems.RemoveAt(i);
                            i--;
                        }
                        GUILayout.EndHorizontal();
                    }
                    GUILayout.EndScrollView();
                    GUILayout.EndVertical();
                    GUILayout.BeginHorizontal();
                    GUI.enabled = newItems.Count > 0;
                    if (GUILayout.Button("ADD", GUILayout.MinWidth(50), GUILayout.MaxWidth(100)))
                    {
                        AddItem(newItems);
                        newItems.Clear();
                        inDragItens = false;
                    }
                    GUI.enabled = true;
                    GUILayout.FlexibleSpace();
                    if (GUILayout.Button("CLEAR", GUILayout.MinWidth(50), GUILayout.MaxWidth(100)))
                    {
                        newItems.Clear();
                    }
                    GUILayout.FlexibleSpace();
                    if (GUILayout.Button("CANCEL", GUILayout.MinWidth(50), GUILayout.MaxWidth(100)))
                    {
                        inDragItens = false;
                    }
                    GUILayout.EndHorizontal();
                    GUILayout.EndVertical();
                }
                if (inAddItem)
                {
                    DrawAddItem();
                }
                if (GUILayout.Button("Open ItemEnums Editor"))
                {
                    vItemEnumsWindow.CreateWindow();
                }
            }

            GUILayout.Space(10);
            GUILayout.EndVertical();

            GUILayout.Box(itemList.items.Count.ToString("00") + " Items");
            DrawFilter();
            scroolView = GUILayout.BeginScrollView(scroolView, GUILayout.ExpandWidth(true));
            int count = 0;

            for (int i = 0; i < itemList.items.Count; i++)
            {
                if (itemList.items[i] != null && FilterItems(itemList.items[i]))
                {
                    Color color = GUI.color;
                    GUI.color = currentItemDrawer != null && currentItemDrawer.item == itemList.items[i] ? Color.green : color;
                    GUILayout.BeginVertical("box");
                    {
                        GUI.color = color;
                        GUILayout.BeginHorizontal();
                        {
                            var      texture  = itemList.items[i].iconTexture;
                            var      name     = " ID " + itemList.items[i].id.ToString("00") + "\n - " + itemList.items[i].name + "\n - " + itemList.items[i].type.ToString();
                            var      content  = new GUIContent(name, texture, currentItemDrawer != null && currentItemDrawer.item == itemList.items[i] ? "Click to Close" : "Click to Open");
                            GUIStyle boxStyle = new GUIStyle(GUI.skin.box);
                            GUI.skin.box.alignment = TextAnchor.UpperLeft;
                            GUI.skin.box.fontStyle = FontStyle.Italic;
                            GUI.skin.box.fontSize  = 11;

                            if (GUILayout.Button(content, "label", GUILayout.Height(60), GUILayout.MinWidth(60)))
                            {
                                if (OnSelectItem != null)
                                {
                                    OnSelectItem.Invoke(i);
                                    OnSelectItem = null;
                                    this.Close();
                                }
                                else
                                {
                                    GUI.FocusControl("clearFocus");
                                    scroolView.y = 1 + count * 60;
                                    GetItemDrawer(i);
                                }
                            }

                            if (OnSelectItem == null)
                            {
                                EditorGUIUtility.AddCursorRect(GUILayoutUtility.GetLastRect(), MouseCursor.Link);

                                GUI.skin.box = boxStyle;
                                var duplicateImage = Resources.Load("duplicate") as Texture;
                                if (GUILayout.Button(new GUIContent("", duplicateImage, "Duplicate Item"), GUILayout.MaxWidth(45), GUILayout.Height(45)))
                                {
                                    if (EditorUtility.DisplayDialog("Duplicate the " + itemList.items[i].name,
                                                                    "Are you sure you want to duplicate this item? ", "Duplicate", "Cancel"))
                                    {
                                        DuplicateItem(itemList.items[i]);
                                        GUILayout.EndHorizontal();
                                        Repaint();
                                        break;
                                    }
                                }
                                if (GUILayout.Button(new GUIContent("x", "Delete Item"), GUILayout.MaxWidth(20), GUILayout.Height(45)))
                                {
                                    if (EditorUtility.DisplayDialog("Delete the " + itemList.items[i].name,
                                                                    "Are you sure you want to delete this item? ", "Delete", "Cancel"))
                                    {
                                        var item = itemList.items[i];
                                        itemList.items.RemoveAt(i);
                                        DestroyImmediate(item, true);
                                        OrderByID(ref itemList.items);
                                        AssetDatabase.SaveAssets();
                                        serializedObject.ApplyModifiedProperties();
                                        EditorUtility.SetDirty(itemList);
                                        GUILayout.EndHorizontal();
                                        Repaint();
                                        break;
                                    }
                                }
                            }
                        }
                        GUILayout.EndHorizontal();

                        GUI.color = color;
                        if (currentItemDrawer != null && currentItemDrawer.item == itemList.items[i] && itemList.items.Contains(currentItemDrawer.item))
                        {
                            currentItemDrawer.DrawItem(ref itemList.items, false);
                        }
                    }
                    GUILayout.EndVertical();
                    count++;
                }
            }
            GUILayout.EndScrollView();

            GUILayout.EndVertical();
            if (GUI.changed || serializedObject.ApplyModifiedProperties())
            {
                EditorUtility.SetDirty(itemList);
            }
        }
示例#19
0
 /// <summary>
 /// Event called when the item is unquipped
 /// </summary>
 /// <param name="item">target item</param>
 public virtual void OnUnequip(vItem item)
 {
     onUnequip.Invoke(item);
 }
示例#20
0
        private void DrawAddItem()
        {
            GUILayout.BeginVertical("box");

            if (addItem != null)
            {
                addItemScroolView = EditorGUILayout.BeginScrollView(addItemScroolView, false, false);
                if (addItemDrawer == null || addItemDrawer.item == null || addItemDrawer.item != addItem)
                {
                    addItemDrawer = new vItemDrawer(addItem);
                }
                bool isValid = true;
                if (addItemDrawer != null)
                {
                    GUILayout.Box("Create Item Window");
                    addItemDrawer.DrawItem(ref itemList.items, false, true);
                }

                if (string.IsNullOrEmpty(addItem.name))
                {
                    isValid = false;
                    EditorGUILayout.HelpBox("This item name cant be null or empty,please type a name", MessageType.Error);
                }

                if (itemList.items.FindAll(item => item.name.Equals(addItemDrawer.item.name)).Count > 0)
                {
                    isValid = false;
                    EditorGUILayout.HelpBox("This item name already exists", MessageType.Error);
                }
                EditorGUILayout.EndScrollView();
                GUILayout.BeginHorizontal("box", GUILayout.ExpandWidth(false));

                if (isValid && GUILayout.Button("Create"))
                {
                    AssetDatabase.AddObjectToAsset(addItem, AssetDatabase.GetAssetPath(itemList));
                    addItem.hideFlags = HideFlags.HideInHierarchy;
                    addItem.id        = GetUniqueID();
                    itemList.items.Add(addItem);
                    OrderByID();
                    addItem       = null;
                    inAddItem     = false;
                    addItemDrawer = null;
                    serializedObject.ApplyModifiedProperties();
                    EditorUtility.SetDirty(itemList);
                    AssetDatabase.SaveAssets();
                }

                if (GUILayout.Button("Cancel"))
                {
                    addItem       = null;
                    inAddItem     = false;
                    addItemDrawer = null;
                    serializedObject.ApplyModifiedProperties();
                    EditorUtility.SetDirty(itemList);
                }
                GUILayout.EndHorizontal();
            }
            else
            {
                EditorGUILayout.HelpBox("Error", MessageType.Error);
            }

            GUILayout.EndVertical();
        }
示例#21
0
        public void OnGUI()
        {
            if (skin)
            {
                GUI.skin = skin;
            }
            var _color = GUI.color;

            if (OnSelectItem != null)
            {
                GUI.color = Color.red;
            }
            GUILayout.BeginVertical("Item List", "window");
            GUI.color = _color;
            GUILayout.Label(m_Logo, GUILayout.MaxHeight(25));

            GUILayout.BeginVertical("box");

            GUI.enabled = !Application.isPlaying;
            itemList    = EditorGUILayout.ObjectField("ItemListData", itemList, typeof(vItemListData), false) as vItemListData;

            if (serializedObject == null && itemList != null)
            {
                serializedObject = new SerializedObject(itemList);
            }
            else if (itemList == null)
            {
                GUILayout.EndVertical();
                return;
            }

            serializedObject.Update();
            if (OnSelectItem == null)
            {
                if (!inAddItem && GUILayout.Button("Create New Item"))
                {
                    addItem      = ScriptableObject.CreateInstance <vItem>();
                    addItem.name = "New Item";

                    currentItemDrawer = null;
                    inAddItem         = true;
                }
                if (inAddItem)
                {
                    DrawAddItem();
                }
                if (GUILayout.Button("Open ItemEnums Editor"))
                {
                    vItemEnumsWindow.CreateWindow();
                }
            }

            GUILayout.Space(10);
            GUILayout.EndVertical();

            GUILayout.Box(itemList.items.Count.ToString("00") + " Items");
            scroolView = GUILayout.BeginScrollView(scroolView, GUILayout.ExpandWidth(true));
            for (int i = 0; i < itemList.items.Count; i++)
            {
                if (itemList.items[i] != null)
                {
                    Color color = GUI.color;
                    GUI.color = currentItemDrawer != null && currentItemDrawer.item == itemList.items[i] ? Color.green : color;
                    GUILayout.BeginVertical("box");
                    {
                        GUI.color = color;
                        GUILayout.BeginHorizontal();
                        {
                            var      texture  = itemList.items[i].iconTexture;
                            var      name     = " ID " + itemList.items[i].id.ToString("00") + "\n - " + itemList.items[i].name + "\n - " + itemList.items[i].type.ToString();
                            var      content  = new GUIContent(name, texture, currentItemDrawer != null && currentItemDrawer.item == itemList.items[i] ? "Click to Close" : "Click to Open");
                            GUIStyle boxStyle = new GUIStyle(GUI.skin.box);
                            GUI.skin.box.alignment = TextAnchor.UpperLeft;
                            GUI.skin.box.fontStyle = FontStyle.Italic;
                            GUI.skin.box.fontSize  = 11;

                            if (GUILayout.Button(content, "box", GUILayout.Height(50), GUILayout.MinWidth(50)))
                            {
                                if (OnSelectItem != null)
                                {
                                    OnSelectItem.Invoke(i);
                                    OnSelectItem = null;
                                    this.Close();
                                }
                                else
                                {
                                    GUI.FocusControl("clearFocus");
                                    scroolView.y      = 1 + i * 60;
                                    currentItemDrawer = currentItemDrawer != null ? currentItemDrawer.item == itemList.items[i] ? null : new vItemDrawer(itemList.items[i]) : new vItemDrawer(itemList.items[i]);
                                }
                            }

                            if (OnSelectItem == null)
                            {
                                EditorGUIUtility.AddCursorRect(GUILayoutUtility.GetLastRect(), MouseCursor.Link);

                                GUI.skin.box = boxStyle;
                                var duplicateImage = Resources.Load("duplicate") as Texture;
                                if (GUILayout.Button(new GUIContent("", duplicateImage, "Duplicate Item"), GUILayout.MaxWidth(45), GUILayout.Height(45)))
                                {
                                    if (EditorUtility.DisplayDialog("Duplicate the " + itemList.items[i].name,
                                                                    "Are you sure you want to duplicate this item? ", "Duplicate", "Cancel"))
                                    {
                                        DuplicateItem(itemList.items[i]);
                                        GUILayout.EndHorizontal();
                                        Repaint();
                                        break;
                                    }
                                }
                                if (GUILayout.Button(new GUIContent("x", "Delete Item"), GUILayout.MaxWidth(20), GUILayout.Height(45)))
                                {
                                    if (EditorUtility.DisplayDialog("Delete the " + itemList.items[i].name,
                                                                    "Are you sure you want to delete this item? ", "Delete", "Cancel"))
                                    {
                                        var item = itemList.items[i];
                                        itemList.items.RemoveAt(i);
                                        DestroyImmediate(item, true);
                                        OrderByID();
                                        AssetDatabase.SaveAssets();
                                        serializedObject.ApplyModifiedProperties();
                                        EditorUtility.SetDirty(itemList);
                                        GUILayout.EndHorizontal();
                                        Repaint();
                                        break;
                                    }
                                }
                            }
                        }
                        GUILayout.EndHorizontal();

                        GUI.color = color;
                        if (currentItemDrawer != null && currentItemDrawer.item == itemList.items[i] && itemList.items.Contains(currentItemDrawer.item))
                        {
                            currentItemDrawer.DrawItem(ref itemList.items, false);
                        }
                    }
                    GUILayout.EndVertical();
                }
            }
            GUILayout.EndScrollView();

            GUILayout.EndVertical();
            if (GUI.changed || serializedObject.ApplyModifiedProperties())
            {
                EditorUtility.SetDirty(itemList);
            }
        }
示例#22
0
 public void UnequipItem(vEquipArea equipArea, vItem item)
 {
     onUnequipItem.Invoke(equipArea, item);
     ChangeEquipmentDisplay(equipArea, item);
 }
 public virtual bool FilterItems(vItem item)
 {
     return((filter.Count == 0 || filter.Contains(item.type)) && (string.IsNullOrEmpty(search) || item.name.ToLower().Contains(search.ToLower())));
 }
示例#24
0
 internal void OnUseItem(vItem item)
 {
     onUseItem.Invoke(item);
     CheckEquipmentChanges();
 }
示例#25
0
 internal void OnDropItem(vItem item, int amount)
 {
     onDropItem.Invoke(item, amount);
     CheckEquipmentChanges();
 }
示例#26
0
 internal void OnUseItemImmediate(vItem item)
 {
     onUseItem.Invoke(item);
 }
示例#27
0
 internal void OnUseItem(vItem item)
 {
     onUseItem.Invoke(item);
 }
示例#28
0
 public vItemDrawer(vItem item)
 {
     this.item     = item;
     defaultEditor = Editor.CreateEditor(this.item);
 }
 public void OnUnequip(vItem item)
 {
     isEquiped = false;
 }
示例#30
0
 /// <summary>
 /// Check if Item is in Area
 /// </summary>
 /// <param name="item">item to check</param>
 /// <returns></returns>
 public bool ContainsItem(vItem item)
 {
     return(ValidSlots.Find(slot => slot.item == item) != null);
 }