Well I’m trying to get three arrays to display “linked” to each other.
The only thing is that the labels wont display text, but if I hover my mouse over them they do display a tooltip so they are there I guess.
Expectations:
Picture of the property as it should be displayed in the editor. Text drawn with a graphics editor.
Reality:
Picture of the property as it should be displayed in the editor, the labels display no text, but are stil present, for they do display a tooltip when the mouse hovers above them.
Without Property Drawers:
The three arrays displayed separately, for they have no property drawers. “Information” is abbreviated ‘Ex’ in the property drawers example (for a trivial reason), while “Durations” is changed to ‘Time’.
And here is my current code:
// The class that stores the three arrays
public class MeshFrames : PropertyAttribute {
public static readonly int INITIAL_SIZE = 3;
[Tooltip("Mesh that will be displayed that frame.")]
public Mesh[] values;
[Tooltip("Duration in Relative Units of that particular frame.")]
public uint[] durations;
[Tooltip("An extra value linked to that frame.")]
public float[] information;
public MeshFrames() {
values = new Mesh[INITIAL_SIZE];
for (int i = 0; i < INITIAL_SIZE; i++) { values[i] = null; }
durations = new uint[INITIAL_SIZE];
for (int i = 0; i < INITIAL_SIZE; i++) { durations[i] = 1; }
information = new float[INITIAL_SIZE];
for (int i = 0; i < INITIAL_SIZE; i++) { information[i] = 0; }
}
}
// The Property Drawer
[CustomPropertyDrawer(typeof(MeshFrames))]
public class SpriteFramesDrawer : PropertyDrawer {
// Draw the property inside the given rect
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) {
// Obtaining the values from sprite arrays
SerializedProperty arrayProp = property.FindPropertyRelative("values");
SerializedProperty duratProp = property.FindPropertyRelative("durations");
SerializedProperty inforProp = property.FindPropertyRelative("information");
// This will display an Inspector Field for each array item
for (int i = 0; i < arrayProp.arraySize; i++) {
/// Getting this item's individual values
SerializedProperty value = arrayProp.GetArrayElementAtIndex(i);
SerializedProperty durat = duratProp.GetArrayElementAtIndex(i);
SerializedProperty infor = inforProp.GetArrayElementAtIndex(i);
/// Creating appropiate rects
var valueRect = new Rect(position.x , position.y + (16 * i), position.width - 130 , 15);
var durationRect = new Rect(position.x + position.width - 130 , position.y + (16 * i), 80 , 15);
var informationRect = new Rect(position.x + position.width - 45 , position.y + (16 * i), 45 , 15);
/// Applying Rects
GUIContent sampleGUIContent = new GUIContent();
// The label of the mesh value is just its index.
sampleGUIContent.text = i + ": ";
EditorGUIUtility.labelWidth = 40;
EditorGUI.PropertyField(valueRect, value, sampleGUIContent);
// The label of the duration value is "Time: "
sampleGUIContent.text = "Time: ";
EditorGUIUtility.labelWidth = 40;
EditorGUI.PropertyField(durationRect, durat, sampleGUIContent);
// The label of the information value is "Ex: "
sampleGUIContent.text = "Ex: ";
EditorGUIUtility.labelWidth = 25;
EditorGUI.PropertyField(informationRect, infor, sampleGUIContent);
}
}
public override float GetPropertyHeight (SerializedProperty property, GUIContent label) {
// The base height
int baseHeight = 8;
// Obtaining the length of the arrays (assuming they all have the same size)
SerializedProperty arrayProp = property.FindPropertyRelative("values");
// Calculating added height based on array sizes
int addedHeight = arrayProp.arraySize * 16;
// Returning the height of the property
return baseHeight + addedHeight;
}
}
And well, I tried restarting the editor, changing label sizes width numbers (Maybe it was too small?) but it just doesnt show. Any ideas on what to try?