Modify inspector

I have trouble with understanding the usage of “@CustomEditor”.

Below is the code I wrote for test-purpose. It’s causing no compile-errors but seems to have no effect. The file is called MenuTest.js and is placed in the Folder My Files/Unity Project/Assets/Editor/

@CustomEditor(MenuTest)

class Automation extends Editor {

 function OnInspectorGUI() {
   EditorGUI.DropShadowLabel(Rect(0, 0, 245, 20), "Automation");
   GUILayout.Label("This is a Label in a Custom Inspector");
   GUILayout.Button ("Hi");
 } //Endfunc OnInspectorGUI
} //End class

The script shall draw a view GUI-Elements in the inspector - no matter which object is selected. I never used classes and things alike and it’s not in the documentation. I don’t know the conventions and even have no idea where to put them in a script.

This is where I took the idea from (example for extending inspector is at bottom of page): GUI-ExtendingEditor

A custom editor draws a custom skin instead of the normal Inspector window for the type specified in @CustomEditor(Type). So, if you have a normal (monobehaviour) script called “MenuTest” in your usual scripts folder (for use as a normal component), and then created this script (with the @CustomEditor(MenuTest) bit at the top) and put it in your editor folder, it would draw whatever you put in OnInspectorGUI in place of the normal Inspector.

This is all explained in the page you linked to, but I would recommend looking through the EditorGUI reference as well (for more examples of how to use things).

I assume what you are doing now is making one script file and naming it ‘MenuTest.js’? The key point here is that you need two scripts- one which is the actual component and is written the same way you usually would, and another which goes in the editor scripts folder and describes the editor window for the first script.

Ok, here is another attempt: The script shall place a foldout at the bottom of the inspector. A text-label shall show the running-time when the foldout is clicked.

class MenuTesting extends Editor {    
   var MyFoldout : boolean = true;      

  @CustomEditor(GameObject)    
  static function Init(){}    

  function OnInspectorGUI() {    
    DrawDefaultInspector ();    
    MyFoldout = EditorGUILayout.Foldout(MyFoldout, "Playing around with GUI");    
    
     if (MyFoldout) {    
   	    EditorGUILayout.LabelField("Time since start: ", EditorApplication.timeSinceStartup.ToString()); 
     } //Endif MyFoldout    
   } //Endfunc OnInspectorGUI          

   function OnInspectorUpdate() {    
      this.Repaint();    
    } //EndFunc   
} //End class 

The compiler gives out an error:

“MissingMethodException: Method not found: ‘UnityEditor.EditorGUI.Label’.”

Any idea why my script is not working?