protected virtual void ShowItemDatabasePicker()
        {
            EditorGUILayout.LabelField("Found the following databases in your project folder:", EditorStyles.largeLabel);

            var dbs = AssetDatabase.FindAssets("t:" + typeof(InventoryItemDatabase).Name);

            foreach (var db in dbs)
            {
                EditorGUILayout.BeginHorizontal();

                if (InventoryEditorUtil.GetItemDatabase(true, false) != null && AssetDatabase.GUIDToAssetPath(db) == AssetDatabase.GetAssetPath(InventoryEditorUtil.GetItemDatabase(true, false)))
                {
                    GUI.color = Color.green;
                }

                EditorGUILayout.LabelField(AssetDatabase.GUIDToAssetPath(db), InventoryEditorStyles.labelStyle);
                if (GUILayout.Button("Select", GUILayout.Width(100)))
                {
                    InventoryEditorUtil.selectedDatabase = (InventoryItemDatabase)AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath(db), typeof(InventoryItemDatabase));
                    OnEnable(); // Re-do editors
                }

                GUI.color = Color.white;
                EditorGUILayout.EndHorizontal();
            }

            if (dbs.Length == 0)
            {
                EditorGUILayout.LabelField("No Item databases found, first create one in your assets folder.");
            }
        }
 public void Focus()
 {
     if (InventoryEditorUtil.GetInventoryManager() != null)
     {
         InventoryEditorUtil.selectedLangDatabase = InventoryEditorUtil.GetInventoryManager().lang;
     }
 }
        protected override IList <InventoryItemBase> FindObjects(bool searchProjectFolder)
        {
            IList <InventoryItemBase> objects = new List <InventoryItemBase>(1024);

            if (InventoryEditorUtil.GetItemDatabase(true, false) != null)
            {
                objects = InventoryEditorUtil.GetItemDatabase(true, false).items.ToArray();
            }

            return(objects);
        }
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            EditorGUI.BeginProperty(position, label, property);

            // TODO, create a custom editor
            //EditorGUI.PropertyField(position, property, label);
            var pos = position;

            pos.width = EditorGUIUtility.labelWidth;
            EditorGUI.PrefixLabel(pos, label);

            pos.x    += pos.width;
            pos.width = position.width - EditorGUIUtility.labelWidth;

            if (property.objectReferenceValue == null)
            {
                GUI.color = Color.yellow;
            }

            pos.width -= 30;
            if (GUI.Button(pos, property.objectReferenceValue != null ? property.objectReferenceValue.name : "(No item selected)", EditorStyles.objectField))
            {
                var picker = EditorWindow.GetWindow <InventoryItemPicker>(true);
                picker.Show(InventoryEditorUtil.GetItemDatabase(true, false));

                picker.OnPickObject += (item) =>
                {
                    property.objectReferenceValue = item;
                    property.serializedObject.ApplyModifiedProperties();
                    GUI.changed = true;
                };
            }

            var p = pos;

            p.width = 30;
            p.x    += pos.width + 8; // 8 for margin
            if (GUI.Toggle(p, true, "", "VisibilityToggle") == false)
            {
                Selection.activeObject = property.objectReferenceValue;
                //EditorGUIUtility.PingObject(property.objectReferenceValue);
            }


            GUI.color = Color.white;

            EditorGUI.EndProperty();
        }
        public void OnEnable()
        {
            equipTypes = serializedObject.FindProperty("_equipTypes");

            list = new ReorderableList(serializedObject, equipTypes, true, true, true, true);
            list.drawHeaderCallback  += rect => EditorGUI.LabelField(rect, "Which types can be placed in this field?");
            list.drawElementCallback += (rect, index, active, focused) =>
            {
                rect.height = 16;
                rect.y     += 3;

                var i = equipTypes.GetArrayElementAtIndex(index);
                i.intValue = EditorGUI.Popup(rect, i.intValue, InventoryEditorUtil.GetEquipTypesStrings(true));
                //EditorGUI.PropertyField(rect, equipTypes.GetArrayElementAtIndex(index));
                //EditorGUILayout.Popup(e.intValue, InventoryEditorUtil.equipTypesStrings);
            };
        }
        protected override void DrawObjectButton(InventoryItemBase item)
        {
            if (sceneDatabase != null)
            {
                var prevColor = GUI.color;
                GUI.color = InventoryEditorUtil.GetItemDatabase(true, false).itemRaritys[item._rarity].color;
                if (GUILayout.Button(InventoryEditorUtil.GetItemDatabase(true, false).itemRaritys[item._rarity].name, "ButtonLeft", GUILayout.Width(80)))
                {
                    searchQuery = InventoryEditorUtil.GetItemDatabase(true, false).itemRaritys[item._rarity].name;
                    Repaint();
                }

                GUI.color = prevColor;
            }

            if (GUILayout.Button("#" + item.ID + " " + item.name, "ButtonRight"))
            {
                NotifyPickedObject(item);
            }
        }
Пример #7
0
        protected override void DrawDetail(InventoryItemBase item, int index)
        {
            InventoryEditorUtil.ErrorIfEmpty(EditorPrefs.GetString("InventorySystem_ItemPrefabPath") == string.Empty, "Inventory item prefab folder is not set, items cannot be saved! Please go to settings and define the Inventory item prefab folder.");
            if (EditorPrefs.GetString("InventorySystem_ItemPrefabPath") == string.Empty)
            {
                canCreateItems = false;
                return;
            }
            canCreateItems = true;

            GUILayout.Label("Use the inspector if you want to add custom components.", InventoryEditorStyles.titleStyle);
            EditorGUILayout.Space();
            EditorGUILayout.Space();

            itemEditorInspector.OnInspectorGUI();

            string newName = "Item_" + (string.IsNullOrEmpty(item.name) ? string.Empty : item.name.ToLower().Replace(" ", "_")) + "_#" + item.ID + "_" + InventoryEditorUtil.selectedDatabase.name + "_PFB";

            if (AssetDatabase.GetAssetPath(item).EndsWith(newName + ".prefab") == false)
            {
                AssetDatabase.RenameAsset(AssetDatabase.GetAssetPath(item), newName);
            }
        }
        public virtual void Draw()
        {
            EditorGUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace(); // Center horizontally
            EditorGUILayout.BeginVertical(InventoryEditorStyles.boxStyle, GUILayout.MaxWidth(1000));
            statsScrollPos = EditorGUILayout.BeginScrollView(statsScrollPos);


            #region Types picker

            EditorGUILayout.BeginVertical();

            EditorGUILayout.LabelField("Step 1: Pick the item types that you want to scan for character stats.", InventoryEditorStyles.titleStyle);
            EditorGUILayout.LabelField("Note: You only have to pick the top level classes.", InventoryEditorStyles.labelStyle);
            EditorGUILayout.LabelField("If EquippableInventoryItem extends from InventoryItemBase, you don't need to pick base. The system handles inheritance.", InventoryEditorStyles.labelStyle);


            EditorGUILayout.BeginVertical(InventoryEditorStyles.reorderableListStyle);
            typeList.DoLayoutList();
            EditorGUILayout.EndVertical();

            EditorGUILayout.EndVertical();

            #endregion

            EditorGUILayout.LabelField("Step 2: Scan the types for stats.", InventoryEditorStyles.titleStyle);
            if (GUILayout.Button("Scan types"))
            {
                var oldList     = new List <InventoryEquipStat>(InventoryEditorUtil.selectedDatabase.equipStats);
                var displayList = new List <InventoryEquipStat>(64);
                foreach (var type in InventoryEditorUtil.selectedDatabase.equipStatTypes)
                {
                    var fields = new List <FieldInfo>();
                    InventoryEditorUtil.GetAllFieldsInherited(System.Type.GetType(type, true), fields);
                    foreach (var field in fields)
                    {
                        var attr = field.GetCustomAttributes(typeof(InventoryStatAttribute), true);
                        if (attr.Length > 0)
                        {
                            var m = (InventoryStatAttribute)attr[0];

                            var old = oldList.FindAll(o => o.fieldInfoNameVisual == field.ReflectedType.Name + "." + field.Name);
                            if (old.Count == 0)
                            {
                                displayList.Add(new InventoryEquipStat()
                                {
                                    name = m.name, typeName = type, fieldInfoName = field.Name, fieldInfoNameVisual = field.ReflectedType.Name + "." + field.Name, show = false, category = "Default", formatter = InventoryEditorUtil.GetSettingsManager() != null ? InventoryEditorUtil.GetSettingsManager().defaultCharacterStatFormatter : null
                                });
                            }
                            else
                            {
                                // Item exists more than once.
                                var already = displayList.Find(o => o.fieldInfoNameVisual == field.ReflectedType.Name + "." + field.Name);
                                if (already == null)
                                {
                                    displayList.Add(old[0]);
                                }
                            }
                        }
                    }
                }

                InventoryEditorUtil.selectedDatabase.equipStats = displayList.ToArray();
                resultList.list = InventoryEditorUtil.selectedDatabase.equipStats; // Update list view
            }
            EditorGUILayout.Space();
            EditorGUILayout.Space();
            EditorGUILayout.Space();

            EditorGUILayout.LabelField("Step 3: Choose what you want to display.", InventoryEditorStyles.titleStyle);

            EditorGUILayout.BeginVertical(InventoryEditorStyles.reorderableListStyle);
            resultList.DoLayoutList();
            EditorGUILayout.EndVertical();

            EditorGUILayout.EndScrollView();
            EditorGUILayout.EndVertical();
            GUILayout.FlexibleSpace();
            EditorGUILayout.EndHorizontal();
        }
Пример #9
0
        protected override void OnCustomInspectorGUI(params CustomOverrideProperty[] extraOverride)
        {
            base.OnCustomInspectorGUI(extraOverride);

            serializedObject.Update();

            // Draws remaining items
            EditorGUILayout.BeginVertical();
            DrawPropertiesExcluding(serializer, new string[]
            {
                "m_Script",
                "craftingCategoryID",
            });

            //InventoryEditorUtil.GetItemDatabase(true, false);
            craftingCategoryID.intValue = EditorGUILayout.Popup("Crafting category", craftingCategoryID.intValue, InventoryEditorUtil.GetCraftingCategoriesStrings(true));

            EditorGUILayout.EndVertical();

            serializedObject.ApplyModifiedProperties();
        }
Пример #10
0
        protected override void OnCustomInspectorGUI(params CustomOverrideProperty[] extraOverride)
        {
            base.OnCustomInspectorGUI(extraOverride);

            serializedObject.Update();
            overrides = extraOverride;

            if (InventoryEditorUtil.selectedDatabase == null)
            {
                InventoryEditorUtil.GetItemDatabase(false, true);
            }

            if (InventoryEditorUtil.selectedDatabase == null)
            {
                EditorGUILayout.HelpBox("No item database set, can't modify item!", MessageType.Error);
                return;
            }

            if (buyPrice.intValue < sellPrice.intValue)
            {
                EditorGUILayout.HelpBox("Buy price is lower than the sell price, are you sure?", MessageType.Warning);
            }

            // Can't go below 0
            if (cooldownTime.floatValue < 0.0f)
            {
                cooldownTime.floatValue = 0.0f;
            }

            // Just a safety precaution
            if (rarity.intValue >= InventoryEditorUtil.raritiesStrings.Length)
            {
                rarity.intValue = 0;
            }

            // Just a safety precaution
            if (category.intValue >= InventoryEditorUtil.itemCategoriesStrings.Length)
            {
                category.intValue = 0;
            }



            if (InventoryEditorUtil.GetItemDatabase(true, false).items.FirstOrDefault(o => AssetDatabase.GetAssetPath(o) == AssetDatabase.GetAssetPath(target)) == null)
            {
                EditorGUILayout.HelpBox("Note that the item you're editing is not in this scene's database " + InventoryEditorUtil.selectedDatabase.name, MessageType.Warning);


                //GUI.color = Color.yellow;
                //if (GUILayout.Button("Add to database"))
                //{
                //    var l = new List<InventoryItemBase>(InventoryEditorUtil.GetItemDatabase().items);
                //    l.Add((InventoryItemBase)target);
                //    InventoryEditorUtil.GetItemDatabase().items = l.ToArray();
                //}
                //GUI.color = Color.white;
            }

            var excludeList = new List <string>()
            {
                "m_Script",
                "_id",
                "_name",
                "_description",
                "_properties",
                "_category",
                "_useCategoryCooldown",
                "_icon",
                "_weight",
                "_requiredLevel",
                "_rarity",
                "_buyPrice",
                "_sellPrice",
                "_isDroppable",
                "_isSellable",
                "_isStorable",
                "_maxStackSize",
                "_cooldownTime"
            };

            GUILayout.Label("Default", InventoryEditorStyles.titleStyle);
            EditorGUILayout.BeginVertical(InventoryEditorStyles.boxStyle);
            if (FindOverride("_id") != null)
            {
                GUI.enabled = false;
            }

            EditorGUILayout.LabelField("ID: ", id.intValue.ToString());
            GUI.enabled = true;

            if (FindOverride("_name") != null)
            {
                GUI.enabled = false;
            }

            EditorGUILayout.PropertyField(itemName);

            GUI.enabled = true;

            if (FindOverride("_description") != null)
            {
                GUI.enabled = false;
            }

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Description", GUILayout.Width(EditorGUIUtility.labelWidth - 5));
            EditorGUILayout.BeginVertical();
            EditorGUILayout.HelpBox("Note, that you can use rich text like <b>asd</b> to write bold text and <i>Potato</i> to write italic text.", MessageType.Info);
            description.stringValue = EditorGUILayout.TextArea(description.stringValue, InventoryEditorStyles.richTextArea);
            EditorGUILayout.EndVertical();
            EditorGUILayout.EndHorizontal();


            GUI.enabled = true;

            EditorGUILayout.PropertyField(icon);

            EditorGUILayout.EndVertical();


            // Draws remaining items
            GUILayout.Label("Item specific", InventoryEditorStyles.titleStyle);
            EditorGUILayout.BeginVertical(InventoryEditorStyles.boxStyle);

            foreach (var item in extraOverride)
            {
                if (item.action != null)
                {
                    item.action();
                }

                excludeList.Add(item.serializedName);
            }

            DrawPropertiesExcluding(serializedObject, excludeList.ToArray());
            EditorGUILayout.EndVertical();

            #region Properties

            GUILayout.Label("Item properties", InventoryEditorStyles.titleStyle);
            GUILayout.Label("You can create properties in the Item editor / Item property editor");

            EditorGUILayout.BeginVertical(InventoryEditorStyles.reorderableListStyle);
            propertiesList.DoLayoutList();
            EditorGUILayout.EndVertical();

            #endregion


            GUILayout.Label("Behavior", InventoryEditorStyles.titleStyle);
            EditorGUILayout.BeginVertical(InventoryEditorStyles.boxStyle);

            GUILayout.Label("Category", InventoryEditorStyles.titleStyle);
            if (InventoryEditorUtil.raritiesColors.Length > 0)
            {
                GUI.color = InventoryEditorUtil.raritiesColors[rarity.intValue];
            }

            rarity.intValue = EditorGUILayout.Popup("Rarity", rarity.intValue, InventoryEditorUtil.raritiesStrings);
            GUI.color       = Color.white;

            category.intValue = EditorGUILayout.Popup("Category", category.intValue, InventoryEditorUtil.itemCategoriesStrings);

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.PropertyField(useCategoryCooldown);
            if (useCategoryCooldown.boolValue)
            {
                EditorGUILayout.LabelField(string.Format("({0} seconds)", InventoryEditorUtil.selectedDatabase.itemCategories[category == null ? 0 : category.intValue].cooldownTime));
            }

            EditorGUILayout.EndHorizontal();
            if (useCategoryCooldown.boolValue == false)
            {
                EditorGUILayout.PropertyField(cooldownTime);
            }


            GUILayout.Label("Buying & Selling", InventoryEditorStyles.titleStyle);
            EditorGUILayout.PropertyField(buyPrice);
            EditorGUILayout.PropertyField(sellPrice);

            GUILayout.Label("Restrictions", InventoryEditorStyles.titleStyle);
            EditorGUILayout.PropertyField(isDroppable);
            EditorGUILayout.PropertyField(isSellable);
            EditorGUILayout.PropertyField(isStorable);
            EditorGUILayout.PropertyField(maxStackSize);
            EditorGUILayout.PropertyField(weight);
            EditorGUILayout.PropertyField(requiredLevel);


            //GUILayout.Label("Audio & Visuals", InventoryEditorStyles.titleStyle);
            //EditorGUILayout.PropertyField(icon);


            //EditorGUILayout.EndVertical();

            EditorGUILayout.EndVertical();


            serializedObject.ApplyModifiedProperties();
        }
Пример #11
0
        public override void OnEnable()
        {
            base.OnEnable();

            item = (ItemCollectionBase)target;
            //serializer = new SerializedObject(target);
            serializer = serializedObject;

            collectionName    = serializer.FindProperty("collectionName");
            restrictByWeight  = serializer.FindProperty("restrictByWeight");
            restrictMaxWeight = serializer.FindProperty("restrictMaxWeight");
            itemButtonPrefab  = serializer.FindProperty("itemButtonPrefab");

            items                     = serializer.FindProperty("_items");
            useReferences             = serializer.FindProperty("useReferences");
            canDropFromCollection     = serializer.FindProperty("canDropFromCollection");
            canUseFromCollection      = serializer.FindProperty("canUseFromCollection");
            canDragInCollection       = serializer.FindProperty("canDragInCollection");
            canPutItemsInCollection   = serializer.FindProperty("canPutItemsInCollection");
            canStackItemsInCollection = serializer.FindProperty("canStackItemsInCollection");
            manuallyDefineCollection  = serializer.FindProperty("manuallyDefineCollection");
            container                 = serializer.FindProperty("container");
            onlyAllowTypes            = serializer.FindProperty("_onlyAllowTypes");

            itemManager = Editor.FindObjectOfType <ItemManager>();
            if (itemManager == null)
            {
                Debug.LogError("No item manager found in scene, cannot edit item.");
            }


            manualItemsList = new ReorderableList(serializer, items, true, true, true, true);
            manualItemsList.drawHeaderCallback += rect =>
            {
                EditorGUI.LabelField(rect, "Select items");
            };
            manualItemsList.drawElementCallback += (rect, index, active, focused) =>
            {
                rect.height = 16;
                rect.y     += 2;

                EditorGUI.PropertyField(rect, items.GetArrayElementAtIndex(index));
            };

            onlyAllowTypesList = new ReorderableList(serializer, onlyAllowTypes, false, true, true, true);
            onlyAllowTypesList.drawHeaderCallback += rect =>
            {
                EditorGUI.LabelField(rect, "Restrict by type, leave empty to allow all types");
            };
            onlyAllowTypesList.drawElementCallback += (rect, index, active, focused) =>
            {
                rect.height = 16;
                rect.y     += 2;

                var r = rect;
                r.width -= 60;

                EditorGUI.LabelField(r, (item.onlyAllowTypes[index] != null) ? item.onlyAllowTypes[index].FullName : "(NOT SET)");

                var r2 = rect;
                r2.width  = 60;
                r2.height = 14;
                r2.x     += r.width;
                if (GUI.Button(r2, "Set"))
                {
                    var typePicker = InventoryItemTypePicker.Get();
                    typePicker.Show(InventoryEditorUtil.GetItemDatabase(true, false));
                    typePicker.OnPickObject += type =>
                    {
                        item._onlyAllowTypes[index] = type.AssemblyQualifiedName;
                        GUI.changed = true; // To save..
                        EditorUtility.SetDirty(target);
                        serializer.ApplyModifiedProperties();
                        Repaint();
                    };
                }
            };
        }
        public void Draw()
        {
            EditorGUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace(); // Center horizontally
            scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition, InventoryEditorStyles.boxStyle, GUILayout.MaxWidth(1000));

            if (InventoryEditorUtil.GetSettingsManager() == null)
            {
                EditorGUILayout.LabelField("Settings are scene depended and require the Inventory managers.");
                EditorGUILayout.EndScrollView();
                GUILayout.FlexibleSpace();
                EditorGUILayout.EndHorizontal();
                return;
            }

            var prevWidth = EditorGUIUtility.labelWidth;

            EditorGUIUtility.labelWidth = 250;
            if (editor == null)
            {
                editor = Editor.CreateEditor(InventoryEditorUtil.GetSettingsManager());
            }



            #region Path selector

            EditorGUILayout.LabelField("Items are saved as prefabs in a folder, this allows you to add components to objects and completely manage them.", InventoryEditorStyles.labelStyle);
            if (EditorPrefs.GetString("InventorySystem_ItemPrefabPath") == string.Empty)
            {
                GUI.color = Color.red;
            }

            EditorGUILayout.BeginHorizontal(InventoryEditorStyles.boxStyle);

            EditorGUILayout.LabelField("Inventory Item prefab folder: " + EditorPrefs.GetString("InventorySystem_ItemPrefabPath"));
            if (GUILayout.Button("Set path", GUILayout.Width(100)))
            {
                string path = EditorUtility.SaveFolderPanel("Choose a folder to save your item prefabs", "", "");


                EditorPrefs.SetString("InventorySystem_ItemPrefabPath", "Assets" + path.Replace(Application.dataPath, ""));
            }
            EditorGUILayout.EndHorizontal();

            GUI.color = Color.white;

            EditorGUILayout.Space();
            EditorGUILayout.Space();

            #endregion


            editor.DrawDefaultInspector();


            EditorGUILayout.EndScrollView();
            GUILayout.FlexibleSpace();
            EditorGUILayout.EndHorizontal();


            EditorGUIUtility.labelWidth = prevWidth;


            if (GUI.changed)
            {
                EditorUtility.SetDirty(InventoryEditorUtil.selectedLangDatabase); // To make sure it gets saved.
            }
        }
 protected override bool MatchesSearch(InventoryItemBase obj, string search)
 {
     return(obj.name.ToLower().Contains(search) || obj.description.ToLower().Contains(search) ||
            obj.ID.ToString().Contains(search) || obj.GetType().Name.ToLower().Contains(search) ||
            (InventoryEditorUtil.GetItemDatabase(true, false) != null && InventoryEditorUtil.GetItemDatabase(true, false).itemRaritys[obj._rarity].name.ToLower().Contains(search)));
 }
        public override void Show(IList <InventoryItemBase> objectsToPickFrom)
        {
            base.Show(objectsToPickFrom);

            sceneDatabase = InventoryEditorUtil.GetItemDatabase(true, false);
        }