- Home /
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
Answer by syclamoth · Dec 17, 2011 at 02:25 AM
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.
Is that really neccessary? Is there no way to keep everything in the same script? I don't wanna apply it to any object. I just wanna extend the inspector with some buttons. When I'm bored of it - I just wanna move the script out of the /Editor-folder to deactivate it.
How do you mean 'extend the inspector with some buttons'? Do you mean on a specific component (because that's what custom editors are for), or a custom window with its own functionality? These are two different things, and are done in quite different ways. Unfortunately, because of the way Unity manages compile order, you can't put all of that in the same file. But that's not really a big deal- you should be splitting up your files wherever you can anyway.
Basically, yes- it is really necessary. Can you go into a little detail about exactly what you want to do? I could probably help you.
When clicking on an object, the inspector shall show a foldout. In this foldout there shall be some elements (e.g. inputs, labels and buttons). When using them, the script shall do some calculations I use often (e.g. "inch to cm"). I think it's not a good idea to split up files. This actually should be avoided wherever possible to keep things simple.
See- a funny thing. I'd have said that you should try to split files up, for the exact same reason you say to keep them in one place! I find that scrolling through a 2000-line file for the one little bit of functionality that isn't working properly is much more frustrating than just clicking on the file named 'BitThatIsntWorking.cs' and getting on with the work...
Anyway, you probably want to make a custom window which modifies the currently selected object. (not a custom inspector)
I hate computer-messies, turning harddisks into dump. If I should ever write a 2000-line-script, it's final version would contain only 1000 lines and would have no errors at all. I don't want a custom window. I wanna extend the inspector with some buttons.
Example: Whenever clicking on an object the inspector always shows the Transform-foldout. Below my own foldout could be visible.
Regarding to your answer: Isn't there some standard-script I can refere to as "Type" in @CustomEditor()? $$anonymous$$aybe the same as some other Inspector-Foldout is referring to.
Answer by spacepilot · Dec 17, 2011 at 12:50 PM
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?
Your answer
Follow this Question
Related Questions
On Editor GUI, How can I draw a 9 sliced image 1 Answer
A node in a childnode? 1 Answer
Custom classes deleted on build/debug 2 Answers
UnityEditor.AnimatedValues? 0 Answers
Adding a permament AnimationClip 0 Answers