Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Editor Window Menu Buttons

Discussion in 'Scripting' started by Cooper37, Jul 27, 2014.

  1. Cooper37

    Cooper37

    Joined:
    Jul 21, 2012
    Posts:
    383
    Does anyone know how I can make buttons disappear and add a new list of them like a menu in the editor? I rather not use toggle because of the transparency thing. This is what I have in my Editor Script:
    Code (csharp):
    1.  
    2. import System.Collections.Generic;
    3. class MyEditor extends EditorWindow{
    4.     @MenuItem("Window/My Editor %i")
    5.  
    6.     static function Init(){
    7.         var ink :MyEditor = ScriptableObject.CreateInstance.<MyEditor>();
    8.         ink.Show();
    9.     }
    10.     function OnGUI(){
    11.     var mainMenu: boolean = true;
    12.     var conditionsMenu : boolean = false;
    13.     var eventsMenu : boolean = false;
    14.         if(mainMenu){
    15.             if(GUILayout.Button("Conditions...", GUILayout.Width(200), GUILayout.Height(20))){
    16.                 Debug.Log("Conditions menu is open...");
    17.                 conditionsMenu = true;
    18.                 mainMenu = false;
    19.             }
    20.         }
    21.         if(conditionsMenu){
    22.             if(GUILayout.Button("Trigger", GUILayout.Width(200), GUILayout.Height(20))){
    23.                 Debug.Log("Conditions menu is open...");
    24.             }  
    25.             GUILayout.Space(40);
    26.             if(GUILayout.Button("Back", GUILayout.Width(200), GUILayout.Height(20))){
    27.                 conditionsMenu = false;
    28.                 mainMenu = true;
    29.             }      
    30.         }
    31.     }
    32. }
    33.  
     
  2. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,716
    You are aware that your 3 boolean are inside the OnGUI method? Which mean every frame, they are reset to their default values?
     
  3. Cooper37

    Cooper37

    Joined:
    Jul 21, 2012
    Posts:
    383
    I didn't know that the frame is called every second even in the editor, but putting the variables anywhere else gives me an error.
     
  4. hpjohn

    hpjohn

    Joined:
    Aug 14, 2012
    Posts:
    2,190
    Oh really?
     
  5. Cooper37

    Cooper37

    Joined:
    Jul 21, 2012
    Posts:
    383
    What does that mean?
     
  6. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,716
    What error? Where did you put those variable?
     
  7. Cooper37

    Cooper37

    Joined:
    Jul 21, 2012
    Posts:
    383
    It's SOLVED. I just put the variables on the outside of the class. :p
     
  8. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,716
    You mean inside the class, but outside the functions.
     
  9. Cooper37

    Cooper37

    Joined:
    Jul 21, 2012
    Posts:
    383
    No, no, it's outside the class as well. But now I'm faced with a different problem. I'm sort of new to extending the editor, and through hours of research I can't find anything that'll help me access a variable from an editor script to a regular old script:
    OpenEditor.js
    Code (csharp):
    1.  
    2. #pragma strict
    3. @CustomEditor(Mission)
    4. @CanEditMultipleObjects
    5. var autoStart : boolean = false;
    6. class OpenEditor extends Editor{  
    7.     function OnInspectorGUI(){
    8.         if(GUILayout.Button("Open Editor")){
    9.             var ink : MyEditor = EditorWindow.GetWindow(MyEditor, true);
    10.             ink.Show();
    11.             //Debug.Log("Editor is Opened!");
    12.         }
    13.         autoStart = EditorGUILayout.Toggle("Auto Start", autoStart);
    14.     }
    15. }
    16.  
    The button and toggle shows up in the inspector of whatever object I place the Mission.js on, and the button works in edit mode, however I don't know how to access the autoStart toggle from the editor script to the script for play mode.
    Any additional help would be nice! :)
    Mission.js
    Code (csharp):
    1.  
    2. #pragma strict
    3. private var autoStart : boolean;
    4. function OnTriggerEnter(other : Collider){
    5.     if(other.gameObject.tag == "Player"){
    6.         Debug.Log("The Mission has BEGUN!");
    7.     }
    8. }
    9.  
     
  10. hpjohn

    hpjohn

    Joined:
    Aug 14, 2012
    Posts:
    2,190
  11. Cooper37

    Cooper37

    Joined:
    Jul 21, 2012
    Posts:
    383
    I knew target had something to do with it. After a bit more research, I SOLVED it:
    OpenEditor.js
    Code (csharp):
    1.  
    2. var mission : Mission = target;
    3. mission.autoStart = EditorGUILayout.Toggle("Auto Start", mission.autoStart);
    4.  
    Mission.js
    Code (csharp):
    1.  
    2. var autoStart : boolean = false;
    3. function Start(){
    4.     if(autoStart){
    5.         Debug.Log("The Mission has BEGUN!");
    6.     }
    7. }
    8.