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.");
            }
        }
        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();
        }
        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);
            }
        }
Esempio n. 5
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();
        }
Esempio n. 6
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();
                    };
                }
            };
        }
 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);
        }