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

Question Is there a way to add costum editor buttons in the middle of the script, not just on top or bottom?

Discussion in 'Scripting' started by Aviation_Simmer, Nov 5, 2022.

  1. Aviation_Simmer

    Aviation_Simmer

    Joined:
    Aug 30, 2021
    Posts:
    110
    Hi! I am working on a custom inspector. It works really great, and works perfectly. Now.. I want to simplify my very long script. for that I need inspector object somewhere in the middle of the script. How can I do that? cheers, Jonas. thanks.
    upload_2022-11-5_21-41-38.png
    Code (CSharp):
    1.         if (!HideAirplaneData)
    2.         {
    3.             EditorGUILayout.LabelField("Aircraft Flight Data", EditorStyles.boldLabel);
    4.             float Throttle = airplane.Throttle;
    5.             EditorGUILayout.LabelField("Throttle", Throttle.ToString());
    6.             float Airspeed = airplane.Airspeed;
    7.             EditorGUILayout.LabelField("Airspeed", Airspeed.ToString());
    8.             float Altitude = airplane.Altitude;
    9.             EditorGUILayout.LabelField("Altitude", Altitude.ToString());
    10.             float VerticalSpeed = airplane.VerticalSpeed;
    11.             EditorGUILayout.LabelField("VerticalSpeed", VerticalSpeed.ToString());
    12.             float PitchAxis = airplane.PitchAxis;
    13.             EditorGUILayout.LabelField("PitchAxis", PitchAxis.ToString());
    14.             float RollAxis = airplane.RollAxis;
    15.             EditorGUILayout.LabelField("RollAxis", RollAxis.ToString());
    16.             float YawAxisHEADING = airplane.YawAxisHEADING;
    17.             EditorGUILayout.LabelField("YawAxisHEADING", YawAxisHEADING.ToString());
    18.             float AngleOfAttack = airplane.AngleOfAttack;
    19.             EditorGUILayout.LabelField("AngleOfAttack", AngleOfAttack.ToString());
    20.             float GForce = airplane.GForce;
    21.             EditorGUILayout.LabelField("GForce", GForce.ToString());        
    22.         }
    23.  
    24.         if (!HideAirplaneData)
    25.         {
    26.            if (GUILayout.Button("Hide Airplane Data")) HideAirplaneData = true;
    27.         }
    28.         else if(GUILayout.Button("Show Airplane Data")) HideAirplaneData = false;
    29.         EditorGUILayout.LabelField("\n");
    30.  
    31.         string[] options = new string[]
    32.         {
    33.             "Option1", "Option2", "Option3",
    34.         };
    35.         selected = EditorGUILayout.Popup(selected, options);
    36.  
    37.         DrawDefaultInspector();  
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,762
    You can either write your own custom inspector (Editor) or you could perhaps decorate it with stuff like this:

    https://github.com/madsbangh/EasyButtons

    Let's you stick buttons hither and thither in your stack.
     
  3. Aviation_Simmer

    Aviation_Simmer

    Joined:
    Aug 30, 2021
    Posts:
    110
    I am writing my own costum inspector. but I only know how to add buttons and other objects on the top of the script or on the bottom. but how can I add costum inspector objects in between of the script?
     
  4. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    5,895
    With a custom inspector you'd need to take over drawing of the whole inspector and draw the elements you need in the order you desire, default fields included.

    That or use one of the many addon tools that make customer inspectors easier to implement.
     
    Bunny83 likes this.