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 chillersanim · Jul 08, 2013 at 12:42 PM · editorinspector

How can I override the default inspector editor with my own?

Hello everybody.
I try to create a custom editor, which should replace the old one (from unity). My target is to allow the programmer to define the design of the editor just with attributes at the properties in the script.

For that I want to override the default inspector editor, so that my new one is always used.

My question:
How can I achieve that my editor is used for default?
I don't want to use:

 [CustomEditor(typeof(MyClass))]

Because then I would need to create a copy of this editor script for each script...

Greetings
Chillersanim

Comment
Add comment · Show 1
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 dorpeleg · Jul 08, 2013 at 12:46 PM 0
Share

I don't think its possible without using

[CustomEditor(typeof($$anonymous$$yClass))]

3 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by TonyLi · Jul 08, 2013 at 01:52 PM

If all of your scripts derive from the same base class, you can put the code in a custom inspector for the base class. Then each subclass can just inherit this.

For example, say you have these scripts:

 public class NPC : MonoBehaviour {
     public string title;
 }
 
 public class Friend : NPC {
 }

 public class Neutral: NPC {
 }

 public class Enemy : NPC {
     public bool aggressive;
 }

Then you could have these custom inspector classes:

 [CustomEditor(typeof(NPC))] 
 public class NPCEditor : Editor {
 
     public override void OnInspectorGUI() {
         title = EditorGUILayout.TextField("Title", title);
     }
 
 }
 
 [CustomEditor(typeof(Friend))]
 public class FriendEditor : NPCEditor {}
 
 [CustomEditor(typeof(Neutral))]
 public class NeutralEditor : NPCEditor {}
 
 [CustomEditor(typeof(Enemy))]
 public class EnemyEditor : NPCEditor {
 
     public override void OnInspectorGUI() {
         base.OnInspectorGUI();
         // Add another property to inspector:
         aggressive = EditorGUILayout.Toggle("Aggressive", aggressive);
     }
 
 }
Comment
Add comment · Show 3 · 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 chillersanim · Jul 08, 2013 at 04:09 PM 0
Share

Ah you gave me a idea. I could directly use [CustomEditor(typeof($$anonymous$$onoBehaviour))] or wouldn't that work?

I want to make an editor which reads all properties and draws them automaticaly depending on the attributes of them. So that you could define the design inside the script.

avatar image TonyLi · Jul 08, 2013 at 05:28 PM 1
Share

If you're talking about replacing the default editor for all $$anonymous$$onoBehaviours, I would recommend @JohnnySunshine's Property Drawers answer ins$$anonymous$$d. It requires Unity 4, but it allows the programmer to specify custom handling on a property-by-property basis.

avatar image chillersanim · Jul 08, 2013 at 07:37 PM 0
Share

Well, it is a good idea, but with that, I cannot implement grouping, limiting and that sort of stuf. At least not as far as I understood. I will make some tests and after that, I'm gona tell you how it worked. Until then I cannot say which answer I should accept...

avatar image
4

Answer by Cameron_SM · Jan 24, 2015 at 01:48 PM

Not sure if this feature existed when this question was asked, but the CustomEditor attribute also takes a second boolean paramater to allow your editor to be applied to child classes too.

If you wanted to add something to every editor you could in fact use:

 [CustomEditor(typeof(MonoBehaviour), true)]

http://docs.unity3d.com/ScriptReference/CustomEditor-ctor.html

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
avatar image
1

Answer by JohnnySunshine · Jul 08, 2013 at 02:31 PM

You might actually be interested in Property Drawers. They help to customize the inspector window based on attributes on your public properties.

Comment
Add comment · Show 1 · 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 chillersanim · Jul 08, 2013 at 04:11 PM 0
Share

Great hint. I will surely use them, they look really mighty. Thanks.

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

20 People are following this question.

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

Related Questions

Draw specific Object Inspector into Rect 1 Answer

Way to graphically visualize a Vector2 or Vector3 in inspector? 2 Answers

Customizing Inspector variables. 2 Answers

How to set a shared material in inspector? 0 Answers

How do I get the default scene GUI for a CustomEditor for RectTransform? 1 Answer


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