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 );
}
}
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!
Your answer
Follow this Question
Related Questions
Custom Inspector Script Resetting Information 0 Answers
Target field of a MonoBehaviour attribute ? 1 Answer
Lazy Inspector customisation 0 Answers
How do I get a List or array in a custom inspector? 1 Answer
Custom inspector array issues for loop 0 Answers