Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by spacepilot · Dec 17, 2011 at 01:58 AM · guieditorclass

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

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
1

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.

Comment
Add comment · Show 12 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image spacepilot · Dec 17, 2011 at 02:46 AM 0
Share

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.

avatar image syclamoth · Dec 17, 2011 at 02:49 AM 0
Share

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.

avatar image spacepilot · Dec 17, 2011 at 02:56 AM 0
Share

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.

avatar image syclamoth · Dec 17, 2011 at 03:01 AM 0
Share

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)

avatar image spacepilot · Dec 17, 2011 at 03:08 AM 0
Share

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.

Show more comments
avatar image
0

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?

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges