Quick Custom Inspector Question

Hi, all! I was wondering how the syntax would go if I wanted to make a field that let me edit 2 variables on the same line that say “Min” before the first field and “Max” before the second field, allowing me to edit 2 variables.

Exactly like the way a Vector3Field exposes 3 fields in one line that say ‘X’, ‘Y’, and ‘Z’ before them, I’d like to make one that says ‘min’ and ‘max’ with only two fields.

Can this be done? Thanks!- YA

you can create a custom class, then declare an instance of your class:

class Range{
var min : float;
var max : float;
}

var myRange : Range = new Range();

(javascript)

EDIT: add this script to an object and select the object. Now in the inspector, you can see the new var “myRange”:

[4929-sample+script.jpg|4929]

Now, to access the values of myRange via script, you could say myRange.min or myRange.max… for example:

myRange.min = 2.5;

SECOND EDIT:

Here is what you mean:

// Create a Horizontal set of two float fields

class testEditor extends EditorWindow {

    @MenuItem("Examples/testEditor")
    static function Init() {
        var window = GetWindow(testEditor);
        window.Show();
    }
    
    function OnGUI() {
        var r : Rect = EditorGUILayout.BeginHorizontal ();
            EditorGUILayout.FloatField (1.0);
             EditorGUILayout.FloatField (2.0);    
        EditorGUILayout.EndHorizontal ();
    }
}

alt text

Hope this helps :slight_smile:

FINAL EDIT:

played around a bit more, here’s how to add the labels…

// Create a Horizontal set of float fields

class testEditor extends EditorWindow {

    @MenuItem("Examples/testEditor")
    static function Init() {
        var window = GetWindow(testEditor);
        window.Show();
    }
    
    function OnGUI() {
        var r : Rect = EditorGUILayout.BeginHorizontal ();
        EditorGUILayout.LabelField("min",GUILayout.Width(30));
            EditorGUILayout.FloatField (1.0);
                EditorGUILayout.LabelField("max",GUILayout.Width(30));
             EditorGUILayout.FloatField (2.0);    
        EditorGUILayout.EndHorizontal ();
    }
}

4932-samplefloateditor.jpg