• 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 /
  • Help Room /
avatar image
Question by thewaterz · Jun 19, 2016 at 12:42 PM · inspectorguilayoutpropertydrawercustom inspectorcustom class

How do you update a property's int value based on two (or more) other properties in the Inspector?

Hi! It's my first time posting here so please do bear with me!

I created a Property Drawer that makes it easy to choose the type of enemy I want to spawn for that wave, as well as the number of enemies for that type. Currently, there are two property drawers - one for the first line called RandomDrawer, and the other called EnemyDrawer.

 [CustomPropertyDrawer(typeof(FirstLayer))]
     class RandomDrawer : PropertyDrawer {
         
         public override void OnGUI (Rect position, SerializedProperty property, GUIContent label) {
             
             var rectPos = position;
             var randomOptions = property.FindPropertyRelative("RandOpt");
             var enemyNumber = property.FindPropertyRelative("EnemyNumber");
             var id = property.FindPropertyRelative("ID");
             
             rectPos.width -= 190;
             EditorGUI.PropertyField (rectPos, randomOptions, new GUIContent() { text = "Sequence" });
             
             
             rectPos.x = rectPos.width - 10; 
             rectPos.width = position.width - rectPos.width - 10; 
             EditorGUI.PropertyField (rectPos, enemyNumber, new GUIContent() { text = "Enemy Count" });
         
     }
     
     [CustomPropertyDrawer(typeof(EnemyType))]
     class EnemyDrawer : PropertyDrawer {
 
         public override void OnGUI (Rect position, SerializedProperty property, GUIContent label) {
 
             var rectPos = position;
             var type = property.FindPropertyRelative("Type");
             var number = property.FindPropertyRelative("Number");
 
             rectPos.width -= 190;
             EditorGUI.PropertyField (rectPos, type , new GUIContent() { text = "Type / Number" });
 
 
             rectPos.x = rectPos.width - 10; 
             rectPos.width = position.width - rectPos.width - 10; 
             EditorGUI.PropertyField (rectPos, number , GUIContent.none );
          }
     }


alt text

However, I do not know how I should reference them to Enemy Count which is supposed to be the sum of the number of types of enemies.

So, how do I make sure Enemy Count should be 5 if worm is 2 and mecha worm is 3 without having to change it in runtime OR manually key it? And if possible, make it read-only?

[EXTRA QUESTION]

I have a Wave List and an Enemy List, of custom classes. Enemy List is a list of class EnemyType that contains an enum and an int. I also made a custom Editor that allows me to add Waves to the wave list by pressing a button "Add Wave". The thing is, I want to also make a button in the property drawer that adds a new to the Enemy List. How do I make sure that THAT GUI Button only adds a new to that particular wave, and not Wave 2's Enemy List? (Please do ask me for codes as I'm not sure what to give and I'm not sure how to explain this as well!) THANK YOU!

screen-shot-2016-06-19-at-11645-am.png (29.1 kB)
Comment

People who like this

0 Show 0
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

0 Replies

  • Sort: 

Unity Answers is in Read-Only mode

Unity Answers content will be migrated to a new Community platform and we are aiming to launch a public beta on June 13. Please note, Unity Answers is now in read-only so we can prepare for the final data migration.

For more information and updates, please read our full announcement thread in the Unity Forum.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How to force redraw custom inspector that created in CreateInspectorGUI() method?,How to force redraw custom Inspector that use CreateInspectorGUI() ? 0 Answers

How to get spacing between inspector property labels and fields? 0 Answers

Custom Inspector Script Resetting Information 0 Answers

Target field of a MonoBehaviour attribute ? 1 Answer

Lazy Inspector customisation 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