private void displayItems()
        {
            for (int i = 0; i < database.Count; i++)
            {
                QualityBase row = database.Get(i);
                EditorGUILayout.BeginHorizontal();
                GUILayout.Button(row.Icon.texture, GUILayout.Width(24), GUILayout.Height(24));

                EditorGUILayout.ColorField(row.Forecolor, GUILayout.Height(24), GUILayout.Width(50));
                EditorGUILayout.TextField(row.Name, GUILayout.Height(24));


                if (GUILayout.Button("Edit", GUILayout.Width(50), GUILayout.Height(24)))
                {
                    selectedIndex   = i;
                    selectedQuality = database.Get(i);
                    addQuality      = false;
                    editQuality     = true;
                }
                if (GUILayout.Button("Delete", GUILayout.Width(50), GUILayout.Height(24)))
                {
                    if (EditorUtility.DisplayDialog("Confirm Delete", "Are you sure you wish to delete this Quality item? This action cannot be undone!", "Yes, I understand"))
                    {
                        selectedIndex = i;
                        database.Remove(row);
                        addQuality  = false;
                        editQuality = false;
                    }
                }

                Repaint();
                EditorGUILayout.EndHorizontal();
            }
        }
Пример #2
0
        void addNewQuality()
        {
            // name
            if (addQuality || editQuality)
            {
                EditorGUILayout.BeginHorizontal();
                // Sprite
                if (selectedQuality.Icon)
                {
                    selectedQualityTexture = selectedQuality.Icon.texture;
                }
                else
                {
                    selectedQualityTexture = null;
                }

                if (GUILayout.Button(selectedQualityTexture, GUILayout.Width(32), GUILayout.Height(32)))
                {
                    int controllerID = EditorGUIUtility.GetControlID(FocusType.Passive);
                    EditorGUIUtility.ShowObjectPicker <Sprite> (null, false, null, controllerID);
                }

                selectedQuality.Name      = EditorGUILayout.TextField("Name:", selectedQuality.Name);
                selectedQuality.Forecolor = EditorGUILayout.ColorField("Item Label Color", selectedQuality.Forecolor);
                EditorGUILayout.EndHorizontal();

                string cmdName = Event.current.commandName;
                if (cmdName == "ObjectSelectorUpdated")
                {
                    Sprite selectedObject = (Sprite)EditorGUIUtility.GetObjectPickerObject();
                    selectedQuality.Icon = selectedObject;
                    Repaint();
                }

                if (GUILayout.Button("Save"))
                {
                    if (selectedQuality.Name == null)
                    {
                        Debug.LogError("You must provide a name for your new Quality.");
                    }
                    else if (selectedQuality.Icon == null)
                    {
                        Debug.LogError("You must provide a Icon Sprite for your new Quality.");
                    }
                    else if (addQuality)
                    {
                        database.Add(selectedQuality);
                        selectedQuality = new QualityBase();
                        addQuality      = false;
                    }
                    else
                    {
                        database.Replace(selectedIndex, selectedQuality);
                        editQuality = false;
                    }
                }
            }

            if (GUILayout.Button("Add"))
            {
                selectedQuality = new QualityBase();
                addQuality      = true;
            }

            EditorGUILayout.Separator();
        }