Skip to content
Jeppe Zapp edited this page May 25, 2014 · 3 revisions

Custom inspectors in OpenEd are fairly similar to the native Unity ones, but with a few differences. They need to be a subclass of OEComponentInspector

public class MyClassInspector extends OEComponentInspector {
   override function get type () : System.Type { return typeof ( MyClass ); }

   override function Inspector () {
      // Set fixed width of inspector
      width = 300;

      var myClass : MyClass = target.GetComponent.< MyClass > ();

      myClass.myBool = Toggle ( "My bool", myClass.myBool );
      myClass.myFloat = Slider ( "My float", myClass.myFloat1, 0, 10 );
      myClass.myObject = ObjectField ( "My object", myClass.myObject, typeof ( GameObject ), OEObjectField.Target.Scene ) as GameObject;

      // Disable the next fields if condition is true
      BeginDisabled ( myClass.myObject == null );

      // Changes the layout offset by 20 pixels to the right
      Offset ( 0, 20 );

      myClass.myColor = ColorField ( "My color", myClass.myColor );
   
      EndDisabled ();
   }
}

You can set a fixed width of the inspector, you can enable or disable fields in groups, and you do not have to prefix every single field with UnityEditorGUIInspectorLayoutExtentionFabulousness.

Documentation

Clone this wiki locally