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
2
Question by roamcel · Jan 16, 2012 at 09:58 PM · editorclassinheritancecustom

Custom inheritance classes and custom inspectors

Hi all,

my question is easier to understand than it is to explain.

I basically have two classes

 public class myfirstclass : MonoBehaviour {
   public SortedList<int, transform> mylist;
 }
 
 public class mysecondclass : myfirstclass {
   Transform mytransform;
 }

Now, I have a custom editor for myfirstclass:

 [CustomEditor (typeof(myfirstclass))]
 public class myfirstclass: Editor {
     private myfirstclass element;
     
     void Awake () {
            element = (myfirstclass)target;
         }
 
         public override void OnInspectorGUI() {
         EditorGUILayout.LabelField("wdf");       
                 DrawDefaultInspector();
         }
 }

This basically works whenever I drag myfirstclass in any gameobject, but If I assign mysecondclass to a gameobject, the custom editor part is not drawn for it, and it'll just be presented as it would without editor. I am here hoping that we can in some way call a parent class editor class, like for example we do with the "base" keyword in the Awake function.

It'd sound very stupid and ridiculous if we had to completely rewrite an editor class completely disregarding inheritance.

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
4
Best Answer

Answer by .sanders · Jan 21, 2012 at 09:23 PM

Ok I am going to redirect you to basically the same question. I posted an answer there that will work in your case:

http://answers.unity3d.com/questions/51615/do-custom-inspectors-support-inheritance.html

I'll explain in short: your derived class should also have a CustomEditor script, otherwise unity will draw the default inspector. So if you have that and derive that CustomEditor script from your BaseClass's Editor script you can simply call it's OnInspectorGUI() from the OnInspectorGUI() of the derived CustomEditor. Note that will need to explicitly override the OnInspectorGUI(). I don't think it will work otherwise since it's just a sendMessage basically.

hope you can get it solved!

cheers!

Comment
Add comment · Show 2 · 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 roamcel · Jan 22, 2012 at 06:16 AM 0
Share

Awesome. Your OnInspectorGUI call part was the missing link in my chain, thanks a lot.

avatar image 747823 · Mar 29, 2014 at 09:53 PM 0
Share

I know this is old but thanks for the answer. Very effectively explained in a short paragraph.

avatar image
10

Answer by canbeing · Dec 12, 2014 at 07:22 AM

[CustomEditor( typeof( myfirstclass ), true )]

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

How to allow custom classes, to be a variant of sealed unity classes, and allow selecting either, in existing inspectors. 0 Answers

How do you make a custom inspector for a class or instance? 3 Answers

Inspector button for custom class 1 Answer

Editor extension, How do I Serialized nested class? 0 Answers

Create a script that inherits from a class, and than attach multiple inherited classes to unity editor 2 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