Is there a way to mark certain types with attributes, such that, when compiled, automatically generates extra classes based on it?
To clarify, I have a bunch of System.Objects that I would like to interact with using the GameObject Inspector as normal Unity Objects, but I would rather not need to create a new Wrapper class each time it's I want to expose it.
An example of what I currently do:
[Systen.Serializable]
public abstract class SystemType
{
<code here for System.Object type>
}
public class GenericWrapper<T> : MonoBehaviour where T : SystemType
{
// Exposed for serialziation/inspection
public T wrapped;
}
public class DerivedType : SystemType
{
<derived code here>
}
public class DerivedWrapper : GenericWrapper<DerivedType>
{
}
In this paradigm, I have to create a wrapper class each time I make a new derived type, and it looks very bad.
What I would rather do is similar, but with this change instead:
[Wrap]
public class DerivedType : SystemType
{
<derived code here>
}
Which would mark DerivedType to have DerivedWrapper automatically generated by the compiler, and is generally a lot faster, cleaner and easier to do.
Is this possible? and if it is, does it work nicely with Unity's serialization system?
I know of Vexe's framework which allows for easier serialization of these types, but that's mainly for serialization of object graphs within Unity objects, what I need is a Unity object graph that supports polymorphism and abstract classes.
Post Details
- Posted
- 9 years ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/Unity3D/com...