- Home /
Renaming Inspector 2D Array Element 0 , Element 1
Hi This is the inspector
As you can see the answer in the forum doesn't work if there is an array inside an array of class Code [System.Serializable] public class DragonsClass {
[NamedArrayAttribute(new string[] { "Neutral", "Happy", "Sad" })]
public string[] Annswer0;
[NamedArrayAttribute(new string[] { "Neutral", "Happy", "Sad" })]
public string[] Annswer1;
}
public DragonsClass[] DragonsInLevel;
Thank you
Answer by Bunny83 · Dec 03, 2018 at 05:08 AM
First of all that forum thread is a discussion and it has been pointed out several times that in the specific case that was mentioned it's actually a bad idea to use an array if the array should contain a fix amount of elements. You only want to use an array if you have a variable element count in which case hardcoded element names are just wrong.
The property drawer that JohnnyA has posted is a very simple implementation and yes, it does not support nested arrays since it reads the current element index from the property path and he simply grabs the first index it encounters. This could be improved but as already mentioned it's the wrong approach.
Also, as it has been mentioned in the thread you've linked, Unity does automatically rename the element names if the element represents a class / struct and has a string variable as first element. The element will take the content of that first string variable. That way you can create an actual dynamical array / list.
Thank you but I wanted to use the array because its foldable and easy to deal with specially when you are going to loop through it a lot of times and its true i know how many elements i will use in my array but i don't know how many arrays of it i will use
When using a custom serializable class you can also fold and reuse the class in several places.
[Serializable]
public class AnswerSet
{
public string Neutral;
public string Happy;
public string Sad;
}
[Serializable]
public class Question
{
public string title;
public AnswerSet answers.
}
[Serializable]
public class Questions
{
public Question[] items.
}
Here you can create as many questions as you like. The "answers" can be folded inside each question. The name of each "item" element will be the title given in each question.