Search Unity

How To Create An Editor Window In Javascript

Discussion in 'Scripting' started by Leonard-Walker, Jul 7, 2015.

  1. Leonard-Walker

    Leonard-Walker

    Joined:
    Oct 31, 2012
    Posts:
    14
    How do I create Editor Window in Javascript to Edit different Items of the script and be able to do so on different game objects.

    test.js
    Code (JavaScript):
    1. #pragma strict
    2. var name : int =1;
    3. function Start () {
    4.  
    5. }
    6.  
    7. function Update () {
    8.  
    9. }
    And Then In The Editor Folder Folder I Have TestWindow.js
    Code (JavaScript):
    1.  
    2. class Test extends EditorWindow {
    3.    
    4.     function OnGUI() {
    5.         EditorGUILayout.LabelField("Modify Name Value");
    6.         EditorGUILayout.IntField("Update # Names:", name);
    7.  
    8.         if(GUILayout.Button("Close"))
    9.         {
    10.             this.Close();
    11.         }  
    12.            
    13.        
    14.        
    15.     }
    16.    
    17.     function OnInspectorUpdate() {
    18.         Repaint();
    19.     }
    20.  
    21.     @MenuItem("Example/Randomize Children In Selection")
    22.     static function Init ()
    23.     {
    24.         // Get existing open window or if none, make a new one:      
    25.         var window = ScriptableObject.CreateInstance.<Test>();
    26.         window.Show();
    27.     }
    28. }
    29.  
    I get this error with the editor script
    Editor Window.PNG
     
  2. Jana1108

    Jana1108

    Joined:
    Jun 27, 2015
    Posts:
    215
    What version of Unity are you using? I could be wrong but I think GUI doesn't exist in versions later than 4.6.
     
    Last edited: Jul 7, 2015
    Leonard-Walker likes this.
  3. Leonard-Walker

    Leonard-Walker

    Joined:
    Oct 31, 2012
    Posts:
    14
    Unity 5.1 and GUI Does Exist, Currently using it now with other elements in my project..
     
  4. Jana1108

    Jana1108

    Joined:
    Jun 27, 2015
    Posts:
    215
    Oh ok, well I'm using Unity 5 but can't seem to find GUI in that...
     
  5. Leonard-Walker

    Leonard-Walker

    Joined:
    Oct 31, 2012
    Posts:
    14
    Jana1108 How are you building editor windows?
     
  6. Jana1108

    Jana1108

    Joined:
    Jun 27, 2015
    Posts:
    215
    My game doesn't involve editor windows. It's an android app which I am hoping to release this week! I think it has a lot of potential to make the charts :D If you want I could really do with the help and if the game does become successful I could possibly reward you? At the moment I'm struggling with getting the score onto the game over scene from the game scene and displaying sucessfully. Inbox me and we can discuss further.
     
  7. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Name is a string that is defined by the EditorWindow class. IntField is expecting an int. Give it an int as the second argument instead.
     
  8. Leonard-Walker

    Leonard-Walker

    Joined:
    Oct 31, 2012
    Posts:
    14
    BoredMormon, can you provide an example on how to correct my issue?