using System; namespace Core.Utilities { /// /// Abstract base for serializable interface wrapper objects /// public abstract class SerializableInterface { /// /// Unity component that gets serialized that is of our interface type /// public UnityEngine.Object unityObjectReference; } /// /// A generic solution to allow the serialization of interfaces in Unity game objects /// /// Any interface implementing ISerializableInterface [Serializable] public class SerializableInterface : SerializableInterface where T: ISerializableInterface { T m_InterfaceReference; /// /// Retrieves the interface from the unity component and caches it /// public T GetInterface() { if (m_InterfaceReference == null && unityObjectReference != null) { m_InterfaceReference = (T)(ISerializableInterface)unityObjectReference; } return m_InterfaceReference; } } /// /// Base interface from which all serializable interfaces must derive /// public interface ISerializableInterface { } }