• 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 casimps1 · Apr 18, 2012 at 05:06 AM · inspectorcustom-inspectorgenericsdefaultcustom-editor

Custom Inspectors for generics and tweaking default inspectors

So, here's basically the gist of what I'm trying to do. I'm trying to change the way List<T> is displayed in the Inspector view. Currently, List<T> expands to show Size and then Element 0, Element 1, etc. Then, if you expand one of the Elements, it shows the default inspector for whatever type T is.

Now, let's use a trivial/arbitrary example and say that I wanted to change those headers to say "Item 0" instead of "Element 0" whenever I inspected a List<T>. Could I easily do that as a Custom Inspector? If so, how?

It seems to me like there are two potential problems here:

1) Associating a Unity inspector with a generic type.

[CustomEditor(typeof(List<T>))]?

Maybe, t$$anonymous$$s just magically works. I'm not at a place where I can try it and all the examples I've found use non-generic types.

2) Displaying a partial default inspector.

So, assuming that I could get past the first part and associate an Inspector with a generic, then in the OnInspectorGUI I would want to create a line saying "Item 0" and then display the default T inspector when that line is expanded. I only want to make one Inspector class, so being able to draw the default inspector for any arbitrary type is a necessity.

Is any of t$$anonymous$$s possible?

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by RC-1290 · Apr 24, 2012 at 09:51 AM

You can use the CustomEditor for a component, not for for an arbitrary type. The code you write in the inspector then decides the way the data of that component is displayed. So if you want to combine existing behavior with new behavior, you have to mix it yourself.

Would t$$anonymous$$s work for you?

 using UnityEngine;
 using System.Collections;
 using UnityEditor;
 
 [CustomEditor(typeof(Cake))]
 
 public class CakeInspector : Editor {
     
     public override void OnInspectorGUI ()
     {
         Cake c  = target as Cake;
         
         System.Type t = c.ThatGenericList.GetType();
         if (t == typeof(SpecificType)){
             // Custom Inspector code here    
         }
         else {
             base.OnInspectorGUI();// DEFAULT GUI
         }
     }
 }
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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

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

Inspector top not working properly 0 Answers

How do I change inspector values of other game objects using a custom Editor Window 0 Answers

How do I change inspector values of other game objects using a custom Editor Window 0 Answers

Inspector: custom property with custom type use default editor 3 Answers

Generic CustomEditor 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