Custom Inspector for Custom Class that does not extend Monobehavior in .js

Say if I had a custom class that doesn’t extend Monobehavior called “Test.js”:
#pragma strict

class Test
{
	var min: float = 0;
	var max: float = 1;
	var current: float = .5;	
}

and I make an instance of in a script called “ShowTest.js” that does:

#pragma strict
var testVar: Test;

and I make an instance of in a script called “OtherShowTest.js” that does:

#pragma strict
var testVar: Test;

and I have a Editor script for the class that’s in the Editor Folder called “TestEditor.js”:

#pragma strict
@CustomEditor(Test)
@CanEditMultipleObjects
class TestEditor extends Editor 
{
    var minProp : SerializedProperty;
    var maxProp : SerializedProperty;
    var currentProp : SerializedProperty;

    function OnEnable () {
        // Setup the SerializedProperties
        minProp = serializedObject.FindProperty ("min");
        maxProp = serializedObject.FindProperty ("max");
        currentProp = serializedObject.FindProperty ("current");
    }

    function OnInspectorGUI() {
        // Update the serializedProperty - always do this in the beginning of OnInspectorGUI.
        serializedObject.Update ();

        // Show the custom GUI controls

        EditorGUILayout.Slider (currentProp, minProp.floatValue, maxProp.floatValue, new GUIContent ("Current"));
        // Only show the damage progress bar if all the objects have the same damage value:
        if (!currentProp.hasMultipleDifferentValues || !maxProp.hasMultipleDifferentValues || !minProp.hasMultipleDifferentValues)
            ProgressBar (currentProp.floatValue / maxProp.floatValue, "Value");

        serializedObject.ApplyModifiedProperties ();
    }

    // Custom GUILayout progress bar.
    function ProgressBar (value : float, label : String) {
        // Get a rect for the progress bar using the same margins as a textfield:
        var rect : Rect = GUILayoutUtility.GetRect (18, 18, "TextField");
        EditorGUI.ProgressBar (rect, value, label);
        EditorGUILayout.Space ();
    }
}

Is there a way that I can make the custom editor information of “TestEditor.js” show up in an instance of the Test class in “ShowTest.js” and “OtherShowTest.js”?

This isn’t possible because your custom class isn’t serialized on it’s own. When another class has a serialized variable of your custom class, this instance get serialized within the containing class.

So you can’t have an inspector for such a class. The data need always be saved within a true asset in the project, so either in a component (Monobehaviour) in a scene or a prefab, or as ScriptableObject which can be saved as seperate asset.

So the options are:

  • Create a utility function / class which handles just the inspector GUI for your custom class and reuse this untility class in every custom inspector where you need it (in the ShowTest-inspector and in the OtherShowTest inspector).
  • derive your custom class from ScriptableObject (keep in mind that filename == classname) and save it as own asset. Now only a reference to this asset will be stored in your ShowTest instance. Keep in mind when you need multiple instances you have to store multiple assets.

Unity 4 now has a solution to this issue. Figured it out: It’s answered here Property Drawer