Is there any way to display a forward slash character on a GenericMenu item?
Including a forward slash, as shown in the following call, automatically creates a submenu, but I’d actually like to display the character instead.
menu.AddItem(new GUIContent(“Foo/Bar”), false, func, userData)
I’d like the menu item to actually read “Foo/Bar”. Is this possible?
I see this is a bit old, but thought I would post in case anyone else was looking for a solution with the actual slash. I was able to use “Foo\u2044Bar” to solve the problem. I’m using a Windows PC. It sounds like a similar approach was used here on MacOS.
I solved this problem using
\u2215 instead of slash (i.e. its Unicode code)
I just sent feedback requesting the ability to specify the submenu delimiter, which would allow us to simply include normal slashes in the menu items.
For your consideration:
Also, if you’re replacing “/” with a division or fraction slash, wrapping the character in narrow spaces helps.
- “\u200A\u2215\u200B” – “Game ∕Quest”
- “\u200A\u2215\u200A” – “Game ∕ Quest”
The first uses the HAIR SPACE (\u200A) to the left and the ZERO WIDTH SPACE (\u200B) to the right.
The second uses the HAIR SPACE at both sides.
When viewed in Unity using the standard GUI font and font size used by EditorGUI.Popup and other controls, the first results in a string of the same pixel-width as if the “/” wasn’t replaced, but the second provides an extra pixel of padding between the DIVISION SLASH and the trailing HAIR SPACE. It also looks a bit better in the GenericMenu popup. I’m sticking with the second pattern for now.
You can see the various Unicode space characters here: https://www.cs.tut.fi/~jkorpela/chars/spaces.html