- Home /
open a editor window in javascript
hi i would like to know how to open an editor window in javaScript/UnityScript, I've made a couple components in csharp but what ever i try i can't seem to get the window to open in java.
and yes my script is in the editor folder and here is what i was looking at but doesn't seem to work
// JavaScript example:
class MyWindow extends EditorWindow {
var myString = "Hello World";
var groupEnabled = false;
var myBool = true;
var myFloat = 1.23;
// Add menu named "My Window" to the Window menu
@MenuItem ("Window/My Window")
static function Init () {
// Get existing open window or if none, make a new one:
var window = ScriptableObject.CreateInstance.<MyWindow>();
}
function OnGUI () {
GUILayout.Label ("Base Settings", EditorStyles.boldLabel);
myString = EditorGUILayout.TextField ("Text Field", myString);
groupEnabled = EditorGUILayout.BeginToggleGroup ("Optional Settings", groupEnabled);
myBool = EditorGUILayout.Toggle ("Toggle", myBool);
myFloat = EditorGUILayout.Slider ("Slider", myFloat, -3, 3);
EditorGUILayout.EndToggleGroup ();
}
}
Unity does not use Java. Also it's better to post web links, not links to files on your computer.
whoops i didn't realise i just copy and pasted the link from safari, ill change it
Please note that this example is broken, you'll need to modify the script with the following example http://docs.unity3d.com/Documentation/ScriptReference/EditorWindow.GetWindow.html
Answer by flamy · Jul 30, 2012 at 07:25 PM
// Add menu named "My Window" to the Window menu
@MenuItem ("Window/My Window")
static function Init () {
// Get existing open window or if none, make a new one:
var window : MyWindow = ScriptableObject.CreateInstance.<MyWindow>();
window.Show();
}
did you try calling the function show?? the window wont be shown in js unless this is called. but in c# it will be automatically shown on using GetWindow function. IDK for some reason they didnt give it clearly in the editor window example for js.
got it thanks, so i have to state to show the window, i thought the create instance would of done this, thanks i will test it out and hopefully get it working
sweet works now, they should update their reference to say this annoying for learners like me
even i suffered for like 4 or 5 hours previously... but got tht somehow by luck!! :P
Well the problem is they did update the docs ;) The Unityscript example is new and wrong / or not complete. The C# example still uses EditorWindow.GetWindow which searches for the first instance of that type or, if there is none, it created an instance and automatically shows the window.
CreateInstance just creates an instance of a ScriptableObject or EditorWindow (which is derived from ScriptableObject). If there is already an instance, CreateInstance will create another one. You have to show the window manually. This allows you to show the EditorWindow with a different style ( ShowUtility, ShowPopup, ShowAuxWindow, Show)
Ahh ok i think i might have to get some books on coding especially for unity, the internet just pulls up all sorts of wrong information, but then how are you supposed to google something if you dont know what the thing your looking for is called.
Cheers for explaning it
Your answer
![](https://koobas.hobune.stream/wayback/20220613074926im_/https://answers.unity.com/themes/thub/images/avi.jpg)