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 jakejolli · Apr 28, 2015 at 02:33 PM · c#editorcustomization

View and Edit Properties of List items in inspector

I have a class called Menu. Menu has a List of MenuItems, each of which simply has two string variables: title and content.

I want to be able to define MenuItems right in the inspector while viewing an instance of Menu.

Right now I see this:

alt text

How can I make it so that I can expand each MenuItem in the list so that I can see its properties in the inspector, effectively creating new instances with the properties that I specify at runtime?

I'm thinking that I need to extend the editor to do this, but I am unfamiliar with editor scripting.

How would I go about implementing something like this?

capture.png (8.1 kB)
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 Bunny83 · Apr 28, 2015 at 02:37 PM 0
Share

What's the baseclass of $$anonymous$$enuItem? Can you include the class in your question?

ps: be careful with the term "properties" as there is something called property which is something different from a field / variable.

1 Reply

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

Answer by Bunny83 · Apr 28, 2015 at 02:43 PM

The screenshot looks a bit weird. Usually only classes that represent a serializable reference are viewed like this. So i guess you have derived your MenuItem class from ScriptableObject or MonoBehaviour. Either way both aren't suitable in this case.

You should simply declare it as an ordinary class without base class and put the Serializable attribute on it:

 // C#
 [System.Serializable]
 public class MenuItem
 {
     // Your content
 }

edit
Note: This way Unity doesn't support inheritance for the MenuItem class. In other words if you derive another class from MenuItem, technically you could store an instance in that array / List, but that's not supported by Unity. Unity serializes such classes based on the element type of the collection (array / List). So every item in the array / List has to be a MenuItem instance.

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 jakejolli · Apr 28, 2015 at 03:04 PM 0
Share

Works. Thanks!

avatar image kwitee · Oct 23, 2017 at 02:07 PM 0
Share

Is there a way to do this with inheritance? I need a list of different object defined by an abstract class.

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

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

Related Questions

Distribute terrain in zones 3 Answers

Custom Editor applies changes to every instance of the component/class its for, how do I fix this to modify the target instance component only? 0 Answers

Initialising List array for use in a custom Editor 1 Answer

Multiple Cars not working 1 Answer

How do I wait until after AssetDatabase creates an assets before carrying out another function ? 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