Example #1
0
        public void PreviousEquipSlot()
        {
            if (equipSlots == null || equipSlots.Count == 0)
            {
                return;
            }
            lastEquipedItem = currentEquipedItem;
            var validEquipSlots = ValidSlots;

            if (indexOfEquipedItem - 1 >= 0)
            {
                indexOfEquipedItem--;
            }
            else
            {
                indexOfEquipedItem = validEquipSlots.Count - 1;
            }

            onEquipItem.Invoke(this, currentEquipedItem);
            onUnequipItem.Invoke(this, lastEquipedItem);
        }
 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);
     }
 }
Example #3
0
        public void NextEquipSlot()
        {
            if (equipSlots == null || equipSlots.Count == 0)
            {
                return;
            }
            lastEquipedItem = currentEquipedItem;
            var validEquipSlots = ValidSlots;

            if (indexOfEquipedItem + 1 < validEquipSlots.Count)
            {
                indexOfEquipedItem++;
            }
            else
            {
                indexOfEquipedItem = 0;
            }

            onEquipItem.Invoke(this, currentEquipedItem);
            onUnequipItem.Invoke(this, lastEquipedItem);
        }
Example #4
0
        public 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.equipDelayTime;
                var type = item.type;
                if (type != vItemType.Consumable)
                {
                    if (!inventory.isOpen && !inEquip)
                    {
                        animator.SetInteger("EquipItemID", equipArea.equipPointName.Contains("Right") ? item.EquipID : -item.EquipID);
                        animator.SetTrigger("EquipItem");
                    }
                    StartCoroutine(UnequipItemRoutine(equipPoint, item));
                }
            }
        }
        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();
            }
        }
 public 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);
         }
     }
 }
Example #7
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);
                }
            }
        }
 /// <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 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;
     }
 }
Example #9
0
        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 Show
                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)
                    {
                        holder.equipDelayTime = equipArea.currentEquipedItem.equipDelayTime;
                        // Unhide Holder and hide Equiped weapon
                        StartCoroutine(EquipRoutine(holder, true, false, (itemManager.inventory != null && itemManager.inventory.isOpen)));
                    }
                }
            }
        }
Example #10
0
 public vItemDrawer(vItem item)
 {
     this.item     = item;
     defaultEditor = Editor.CreateEditor(this.item);
 }
Example #11
0
 public bool ContainsItem(vItem item)
 {
     return(ValidSlots.Find(slot => slot.item == item) != null);
 }
        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 _equipment = equipPoint.equipmentReference.equipedObject.GetComponent <vIEquipment>();
                            if (_equipment != null)
                            {
                                _equipment.OnUnequip(equipPoint.equipmentReference.item);
                            }
                            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.customEquipPoint);
                        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 equipment = equipedObject.GetComponent <vIEquipment>();
                        if (equipment != null)
                        {
                            equipment.OnEquip(item);
                        }
                        equipPoint.onInstantiateEquiment.Invoke(equipedObject);
                    }
                    else if (equipPoint.equipmentReference != null && equipPoint.equipmentReference.equipedObject != null)
                    {
                        var _equipment = equipPoint.equipmentReference.equipedObject.GetComponent <vIEquipment>();
                        if (_equipment != null)
                        {
                            _equipment.OnUnequip(equipPoint.equipmentReference.item);
                        }
                        Destroy(equipPoint.equipmentReference.equipedObject);
                        equipPoint.equipmentReference.item = null;
                    }
                }
                inEquip            = false;
                inventory.canEquip = true;
                if (equipPoint != null)
                {
                    CheckTwoHandItem(equipPoint, item);
                }
            }
        }
        GUIContent GetItemContent(vItem item)
        {
            var texture = item.icon != null ? item.icon.texture : null;

            return(new GUIContent(item.name, texture, item.description));;
        }
Example #14
0
 public void UnequipItem(vEquipArea equipArea, vItem item)
 {
     onUnequipItem.Invoke(equipArea, item);
     ChangeEquipmentDisplay(equipArea, item);
 }
Example #15
0
 internal void OnDropItem(vItem item, int amount)
 {
     onDropItem.Invoke(item, amount);
     CheckEquipmentChanges();
 }
Example #16
0
 internal void OnUseItem(vItem item)
 {
     onUseItem.Invoke(item);
     CheckEquipmentChanges();
 }
 public void OnUseItem(vItem item)
 {
 }
Example #18
0
        public void OnGUI()
        {
            if (skin)
            {
                GUI.skin = skin;
            }

            GUILayout.BeginVertical("Item List", "window");
            GUILayout.Label(m_Logo, GUILayout.MaxHeight(25));
            GUILayout.Space(10);

            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 (!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)))
                    {
                        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]);
                    }
                    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);
            }
        }
Example #19
0
        public void DrawItem()
        {
            if (item == null)
            {
                item = target as vItem;
            }

            serializedObject.Update();

            GUILayout.BeginVertical("box");
            GUILayout.BeginHorizontal("box");
            var name    = " ID " + item.id.ToString("00") + "\n - " + item.name + "\n - " + item.type.ToString();
            var content = new GUIContent(name);

            GUILayout.Label(content, GUILayout.ExpandWidth(true));
            GUILayout.EndHorizontal();
            EditorGUILayout.LabelField("Description");
            EditorGUILayout.PropertyField(serializedObject.FindProperty("description"), new GUIContent(""));
            EditorGUILayout.PropertyField(serializedObject.FindProperty("type"));
            EditorGUILayout.PropertyField(serializedObject.FindProperty("stackable"));
            //item.description = EditorGUILayout.TextArea(item.description);
            //item.type = (vItemType)EditorGUILayout.EnumPopup("Item Type", item.type);
            //item.stackable = EditorGUILayout.Toggle("Stackable", item.stackable);

            if (item.stackable)
            {
                if (item.maxStack <= 0)
                {
                    item.maxStack = 1;
                }
                item.maxStack = EditorGUILayout.IntField("Max Stack", item.maxStack);
            }
            else
            {
                item.maxStack = 1;
            }

            GUILayout.EndVertical();

            GUILayout.BeginVertical("box");
            GUILayout.BeginHorizontal();
            GUILayout.Label("Icon");
            EditorGUILayout.PropertyField(serializedObject.FindProperty("icon"), new GUIContent(""));
            //item.icon = (Sprite)EditorGUILayout.ObjectField(item.icon, typeof(Sprite), false);
            var rect = GUILayoutUtility.GetRect(40, 40);

            if (item.icon != null)
            {
                DrawTextureGUI(rect, item.icon, new Vector2(40, 40));
            }
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            GUILayout.BeginVertical("box");
            GUILayout.Label("Original Object");
            EditorGUILayout.PropertyField(serializedObject.FindProperty("originalObject"), new GUIContent(""));
            //item.originalObject = (GameObject)EditorGUILayout.ObjectField(item.originalObject, typeof(GameObject), false);
            GUILayout.EndVertical();
            GUILayout.BeginVertical("box");
            GUILayout.Label("Drop Object");
            EditorGUILayout.PropertyField(serializedObject.FindProperty("dropObject"), new GUIContent(""));
            // item.dropObject = (GameObject)EditorGUILayout.ObjectField(item.dropObject, typeof(GameObject), false);
            GUILayout.EndVertical();
            GUILayout.EndHorizontal();

            GUILayout.EndVertical();
            DrawAttributes();
            GUILayout.BeginVertical("box");
            GUILayout.Box(new GUIContent("Custom Settings", "This area is used for additional properties\n in vItem Properties in defaultInspector region"));
            DrawPropertiesExcluding(serializedObject, drawPropertiesExcluding);
            GUILayout.EndVertical();
            if (GUI.changed)
            {
                EditorUtility.SetDirty(item);
            }
            serializedObject.ApplyModifiedProperties();
        }