I need to serialize the single parameter generic UnityEvent class when nested inside of a Generic C# object
This is the C# object:
[Serializable]
public class AutoProperty<T>
{
[SerializeField]
private T m_Data;
[Serializable]
public class UnityEventGeneric : UnityEvent<T> { }
public UnityEventGeneric onChangeEvent = new UnityEventGeneric();
public T value
{
get { return m_Data; }
set
{
m_Data = value;
if (onChangeEvent != null)
onChangeEvent.Invoke(value);
}
}
}
I already have a wrapper for the different types I intend on using the most:
[Serializable]
public class AutoPropertyString : AutoProperty<string> { }
[Serializable]
public class AutoPropertyInt : AutoProperty<int> { }
[Serializable]
public class AutoPropertyFloat : AutoProperty<float> { }
[Serializable]
public class AutoPropertyVector2 : AutoProperty<Vector2> { }
[Serializable]
public class AutoPropertyVector3 : AutoProperty<Vector3> { }
and these serialize the variable ‘m_Data’ properly. It’s just the event that doesn’t. I assume it has something to do with the fact that it is a generic event inside of a generic class, but I was hoping I could still somehow get this to serialize properly.
Any help is greatly appreciated.