- Home /
How do you give a custom name to a editor window?
How do you give a custom name to a editor window? Written in C#
// Add menu named "My Window" to the Window menu
[MenuItem ("Custom Name Here")]
static void Init () {
// Get existing open window or if none, make a new one:
MyWindow window = (MyWindow)EditorWindow.GetWindow (typeof (MyWindow));
}
Comment
Best Answer
Answer by Jamora · Mar 04, 2014 at 09:59 PM
You set the title using the title property.
Thanks for the quick supply. I'm not familiar with the Editor Window program$$anonymous$$g. Could you supply an example? Unity doesn't supply one other than EditorWindow.title
// Add menu named "$$anonymous$$y Window" to the Window menu
[$$anonymous$$enuItem ("Custom Name Here")]
static void Init () {
// Get existing open window or if none, make a new one:
$$anonymous$$yWindow window = ($$anonymous$$yWindow)EditorWindow.GetWindow (typeof ($$anonymous$$yWindow));
window.title = "Custom Title"; // <---
}
Thanks, but I'm encountering the same problem I had previously.
Ignoring menu item Custom Title because it is in no submenu!
How do I add a title without a submenu?
I found an example and this aloud me to do what I wanted.
Thanks for the help though.
// C# example:
using UnityEditor;
using UnityEngine;
public class $$anonymous$$enuTest : $$anonymous$$onoBehaviour {
// Add a menu item named "Do Something" to $$anonymous$$y$$anonymous$$enu in the menu bar.
[$$anonymous$$enuItem ("$$anonymous$$y$$anonymous$$enu/Do Something")]
static void DoSomething () {
Debug.Log ("Doing Something...");
}
// Validated menu item.
// Add a menu item named "Log Selected Transform Name" to $$anonymous$$y$$anonymous$$enu in the menu bar.
// We use a second function to validate the menu item
// so it will only be enabled if we have a transform selected.
[$$anonymous$$enuItem ("$$anonymous$$y$$anonymous$$enu/Log Selected Transform Name")]
static void LogSelectedTransformName ()
{
Debug.Log ("Selected Transform is on " + Selection.activeTransform.gameObject.name + ".");
}
// Validate the menu item defined by the function above.
// The menu item will be disabled if this function returns false.
[$$anonymous$$enuItem ("$$anonymous$$y$$anonymous$$enu/Log Selected Transform Name", true)]
static bool ValidateLogSelectedTransformName () {
// Return false if no transform is selected.
return Selection.activeTransform != null;
}
// Add a menu item named "Do Something with a Shortcut $$anonymous$$ey" to $$anonymous$$y$$anonymous$$enu in the menu bar
// and give it a shortcut (ctrl-g on Windows, cmd-g on OS X).
[$$anonymous$$enuItem ("$$anonymous$$y$$anonymous$$enu/Do Something with a Shortcut $$anonymous$$ey %g")]
static void DoSomethingWithAShortcut$$anonymous$$ey () {
Debug.Log ("Doing something with a Shortcut $$anonymous$$ey...");
}
// Add a menu item called "Double $$anonymous$$ass" to a Rigidbody's context menu.
[$$anonymous$$enuItem ("CONTEXT/Rigidbody/Double $$anonymous$$ass")]
static void Double$$anonymous$$ass ($$anonymous$$enuCommand command) {
Rigidbody body = (Rigidbody)command.context;
body.mass = body.mass * 2;
Debug.Log ("Doubled Rigidbody's $$anonymous$$ass to " + body.mass + " from Context $$anonymous$$enu.");
}
}