artie
1
Ok, I know the trick of having a public string as the first element of a class that can change the name of the Element.
I’m wondering if I can change the whole thing without having to do that. I’m guessing a custom inspector like here: How can I recreate the Array Inspector element for a custom Inspector GUI? - Unity Answers
But what I’d like to have is something like:
Enemy 1
Enemy 2
Enemy 3
etc. instead of Element, have that come up automatically.
@artie
Just had that propblem)
Custom function for arrays in Editor or PropertyDrawer instead of EditorGuiLayout.PropertyField();
public void ShowArrayProperty(SerializedProperty list)
{
EditorGUILayout.PropertyField(list);
EditorGUI.indentLevel += 1;
for (int i = 0; i < list.arraySize; i++)
{
EditorGUILayout.PropertyField(list.GetArrayElementAtIndex(i),
new GUIContent ("Bla" + (i+1).ToString()));
}
EditorGUI.indentLevel -= 1;
}
So you have:
Bla 1
Bla 2
Bla 3
Hope it would help someone
jnt
6
#if UNITY_EDITOR
public string Name;
#endif
I’ll go one-up on you @COAForce
In my opinion this is the simplest and best way. Means you don’t have any unwanted serialized data hanging around in your build.
In a PropertyDrawer you can do this by changing the GUIContent label like so:
label.text = “test”;
Add this at the start:
public string name;
For those who are having this problem.
This is my solution
public class PropertyWindow : EditorWindow
{
private void ArrayGUI(SerializedProperty property, string itemType, ref bool visible)
{
visible = EditorGUILayout.Foldout(visible, property.name);
if (visible)
{
EditorGUI.indentLevel++;
SerializedProperty arraySizeProp = property.FindPropertyRelative("Array.size");
EditorGUILayout.PropertyField(arraySizeProp);
for (int i = 0; i < arraySizeProp.intValue; i++)
{
EditorGUILayout.PropertyField(property.GetArrayElementAtIndex(i), new GUIContent(itemType + i.ToString()), true);
}
EditorGUI.indentLevel--;
}
}
}
How to use
private void OnGUI()
{
ArrayGUI(property, "Name", ref listVisibilityAttack);
}
Hope this helps!.
You could also write it lthis way, in case you wanted the name to match a different variable.
public struct Enemy
{
public string name;
public string surname;
public string description;
string Name { get { return surname; } }
}