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 EvanTreborn · Jan 13, 2013 at 07:53 PM · arrayinspectoreditorguilayoutcustom class

[solved] How to edit an array of custom classes in the Inspector

This is for C# !

How to edit an array of custom classes in the Inspector which was inherited from a base class?

I have a class BuildCondition : UnityEngine.Object which holds two enums (ability and potency) eg. ("buildUnits","heavy")

To check whether an unit is build able by another I want to compare the set of BuildConditions the builder meets with the set of BuildConditions the subject requires.

So in the base class Unit : MonoBehaviour there is an array of required BuildConditions.

UnitTypes eg. class UnitHarvester inherit Unit and add their own attributes eg. harvestingSpeed

So I would like to edit all Attributes trough the inspector so I can set those values for each unitType prefab easily. I have tried adding a Editor for Unit but the unitTypes stick with the array Interface which does not allow to edit the field values. So I wrote Editors for the unitTypes as well and inherit those from the base class's Editor. Like: public override void OnInspectorGUI() { base.OnInspectorGUI(); //doing the all the child Attributes } That UI works.. but it changes the values of every UnitType at once. So there is no individual memory for different objects. And the storage behaviour is .. weird.

Or am I missing the simple method of just telling the inspector to go for the Standard-Array-UI then displaying each field as the two enums it is.

Code examples: (public Attributes just for simplicity)

 //BuildCondition
 [System.Serializable]
 public class BuildCondition : UnityEngine.Object {
   public enum Abilities { buildUnits, techSupport, scienceSupport,.. }
   public Abilities ability { get; set; }
   public enum Potencies { light, middle, heavy, super }
   public Potencies potency { get; set; }
 }
 
 //unit base class
 public class Unit : MonoBehaviour {
   public BuildCondition[] buildConditions;
 
   public bool isBuildable (BuildCondition[] meetConditions) {..}
 ..
 }
 
 //eg. script class to be added as component
 public class UnitHarvester : Unit {
   public float harvestingSpeed;
 ..
 }
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
0

Answer by whydoidoit · Jan 13, 2013 at 08:04 PM

Unless you write a custom editor then you need to make the attributes of your class fields and not 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 whydoidoit · Jan 13, 2013 at 08:05 PM 0
Share

Also you need to specify subclasses as Serializable

avatar image
0

Answer by EvanTreborn · Jan 13, 2013 at 09:54 PM

After two days of frustration and suffering it suddenly works.. without custom editor.. just after watching a film and having some distance.. maybe the reload of unity did it but it works now!.. I have no clue why it did not before though.

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 konsnos · Jun 26, 2014 at 12:52 PM 0
Share

Class BuildCondition should not inherit from Object. Remove that and it'll work.

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

10 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

Related Questions

Set Level inquiry/data from the inspector 1 Answer

How to change array orders in the inspector 1 Answer

Custom Window array inside custom class 1 Answer

populate array values automatically in inspector 2 Answers

GUI, Inspector has no control for Arrays? 3 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