I'm writing a custom editor window that is a file browser much like the standard Project window. The functionality is getting close, but I'm having some trouble with the look and feel.
Here's a side by side comparison of the standard Project window and my custom window.
Note that my folder icons are a little smaller, and fuzzy, compared with the standard ones. I got the folder icon using:
Also, I haven't figured out a good way to colour the background for selected items. In the image shown, I'm using custom GUIStyles cloned from EditorStyles.foldout (for the folders) and EditorStyles.label (for the files). I set the GUIStyleState.background to EditorGUIUtility.whiteTexture for all the render states in each style, but I get inconsistent results on the foldouts, which only sometimes use the white background. Also, I want the background to extend all across the window, as in the standard Project window.
I also tried each of the following, but none of them seemed to have any effect?
I also haven't yet implemented the selection logic. Seems like I need to use GUI control ID's to figure out what's been clicked, but the docs are pretty sketchy, so tips here would be appreciated too.
So I kept plugging away at it and managed to solve most of the issues. Here's my custom window again, alongside the standard Project window:
To get the icons to show the right size I had to cheat a little and use System.Reflection to call the internal method EditorGUIUtility.SetIconSize(new Vector2(16f, 16f));
For the coloured selection background I'm using a GUIStyle on a BeginHorizontal that spans the full window width, with style.normal.background = EditorGUIUtility.whiteTexture, and tinted by GUI.backgroundColor. (I could also have created a 1x1 coloured texture and avoided the use of GUI.backgroundColor.)
To get the selection highlight to turn grey when the window loses focus I choose a different colour in OnFocus and OnLostFocus.
To get text colour to white, I'm using custom GUIStyles with style.normal.textColor -- this worked for the file items, which I'm drawing as labels. For the folders, drawn using EditorGUILayout.Foldout, I'm also setting active/focused/hover/onNormal/onActive/onFocused/onHover.textColor. There seems to be some funky stuff going on in the Foldout rendering, but that pretty much did the trick.
For both the file and folder styles I had to set top and bottom margin and padding to 0, and also add a content offset of (0, -2) to the folders.
For selection logic, no GUI control ID's were needed -- I just test Event.current.mousePosition against the rectangle returned by EditorGUILayout.BeginHorizontal. I implemented click-select and ctrl-click multi-select, but haven't bothered with shift-multiselect.
Phew, glad that's done!
answered Feb 09 '11 at 12:36 AM