- Home /
How to make a custom class that is serializable and works in a custom editor gui array which imitates the real inspector array?
Hello everyone!
I've began ramming my head into the nearest wall because of this custom editor gui interface I'm writing. I have made an array as described by steinbitglis in this thread.
My own implementation(Not the complete code, but what's used, from // --- Array for items and down it's inside the OnGUI function):
// Used for array of combinable items
public List<Vector2> combinableItems = new List<Vector2>();
private SerializedObject m_Object;
private SerializedProperty m_Property;
public void OnEnable()
{
m_Object = new SerializedObject(this);
}
// --- Array for items
m_Object.Update();
m_Property = m_Object.FindProperty("combinableItems");
while (true)
{
Rect newRect = GUILayoutUtility.GetRect(0f, 16f);
bool showChildren = EditorGUI.PropertyField(newRect, m_Property);
EditorGUILayout.Space();
if (m_Property.NextVisible(showChildren)){}
else
{break;}
}
// --- --- Apply the property, handle undo
m_Object.ApplyModifiedProperties();
I want to have each element in the array to have two values, two strings. I was thinking "hey! A vector2 can be used here!" but then I found out that only certain characters can be entered into the input area. Is there some way to make a class which would work with this kind of imitated array? Just as the vector2 does, but having strings as values instead?
I have no clue how to do this as I'm not very good with this whole serializedObject/Properties/Custom Editor Array business. Thanks alot for just reading this, and even more thanks if anyone can help. :) H
Have a good day/night!