示例#1
0
        // Preferences DrawListItem for ReorderableList
        protected static void PreferencesDrawListItem(ReorderableList <ShelfLayer> list, ShelfLayer item)
        {
            EditorGUILayout.BeginHorizontal(GUI.skin.box);
            {
                // Stop editing an items name if enter or return is pressed
                if (editItemName == item &&
                    Event.current.type == EventType.KeyDown &&
                    (Event.current.keyCode == KeyCode.Return ||
                     Event.current.keyCode == KeyCode.KeypadEnter))
                {
                    editItemName = null;
                    Event.current.Use();
                }

                // Layer name
                if (editItemName != item)
                {
                    GUILayout.Label(item.name, GUILayout.ExpandWidth(true));
                }
                else
                {
                    var newName = GUILayout.TextField(item.name, GUILayout.ExpandWidth(true));
                    if (newName != item.name)
                    {
                        Undo.RecordObject(Data, "Rename Shelf Layer Name");
                        item.name = newName;
                        EditorUtility.SetDirty(Data);
                    }
                }

                // Rename button
                var content = new GUIContent("...", "Rename Layer");
                if (GUILayout.Button(content, "label", GUILayout.Width(15)))
                {
                    if (editItemName == item)
                    {
                        editItemName = null;
                    }
                    else
                    {
                        editItemName = item;
                    }
                }

                // Delete button
                content = new GUIContent("x", "Delete Layer");
                var delete = GUILayout.Button(content, "label", GUILayout.Width(10));

                if (delete && item.objects != null && item.objects.Count > 0)
                {
                    delete = EditorUtility.DisplayDialog(
                        "Shelf",
                        "Are you shure you want to delete '" + item.name + "'?",
                        "Delete", "Cancel"
                        );
                }

                if (delete)
                {
                    list.RemoveItem(item);
                }
            }
            EditorGUILayout.EndHorizontal();
        }
示例#2
0
 // Preferences ListItemName for ReorderableList
 protected static string PreferencesListItemName(ReorderableList <ShelfLayer> list, ShelfLayer item)
 {
     return(item.name);
 }