Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 TreasureMap · Aug 17, 2015 at 08:19 AM · guiprefabinspectorcustomdefault

How do you get the default inspector to draw for Prefabs ?

I am extending the inspector for prefabs so that I can include custom functionality. I want to draw the regular inspector gui, in addition to my own custom gui.

However, I cannot seem to get the default inspector for Prefabs (Project Window) to draw properly. Neither DrawDefaultInspector() nor base.OnInspectorGUI() seem to work in this case.

Question: In the case of wanting to extend an existing inspector (GameObject / Prefab), how do you get the original inspector to draw ?

Reference Code:

 [CanEditMultipleObjects, CustomEditor (typeof(GameObject))]
 public class PrefabEditor : Editor {
 
     public override void OnInspectorGUI(){
         //draw regular inspector gui
         DrawDefaultInspector(); //THIS ISN'T WORKING AS EXPECTED
 
             //Pseudo Code
             bool isPrefab = CheckIfPrefab(target);
             if(isPrefab == false)
                  return;
         
            //Add custom gui....
        }
 }

alt text

alt text

prefabinspector-normal.png (19.6 kB)
prefabinspector-result.png (22.5 kB)
Comment
Add comment · Show 2
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 nu-assets · Aug 17, 2015 at 08:48 AM 0
Share

Do you really want to have a custom editor for all GameObject instances? If yes, what is your final goal?

avatar image TreasureMap · Aug 20, 2015 at 03:45 AM 0
Share

What I want to do is customize the inspector for prefabs.

Because a prefab is a general game object, I have to do an additional check. The OnInspectorGUI logic would look like:

1.In the case that the game object is not a prefab, draw the default inspector and exit the gui function.

2.In the event that it is a prefab, draw the default inspector and additional gui for extended functionality.

1 isn't working because the default gui is not drawing as expected.

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by borro56 · Sep 08, 2015 at 10:09 PM

base.OnInspectorGUI() is what you`re looking

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 Bunny83 · Sep 09, 2015 at 12:07 AM 0
Share

That's pretty pointless ^^. OnInspectorGUI inside the Editor class is defined like this:

 public virtual void OnInspectorGUI()
 {
     this.DrawDefaultInspector();
 }

So it just calls "DrawDefaultInspector" which actually has a bad name. It should be called "DrawDefault$$anonymous$$onoBehaviourInspector" or DrawSerializedFieldsInspector because all it does is draw property GUI for each serialized value that the object has, just like a $$anonymous$$onoBehaviour script is shown.

avatar image
0

Answer by Bunny83 · Sep 09, 2015 at 12:03 AM

You actually can't extend an existing editor. Unity (or actually the InspectorWindow class) will pick one editor per object in the inspector. If you implement a custom inspector for a built-in component / object it will replace the original one.

There is a class inside the UnityEditor assembly that is called "GameObjectInspector" which implements the GUI you see at the very top of the inspector window when you select a gameobject. That class is marked as internal, so you can't derive your own class from it. You really should not replace any of the built-in editors. You might want to implement a custom inspector for a specialized script which you attach to the prefab.

If you want every prefab to have an instance of that script you can implement an AssetPostProcessor which adds your script to each prefab. Already existing prefabs need to be reimported in that case. The script could be empty. You just use it to add your custom GUI.

You might want to downlad ILSpy and take a look at the UnityEditor.dll. It helps to understand how the editor actually works.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Using different custom inspectorscripts 1 Answer

How to set a default prefab on a C# script? 1 Answer

Custom GUI Elements in Inspector 0 Answers

How to know if something is selected in Hierarchy or in project. 5 Answers

Simple text in inspector components? 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