Itās a great idea to use an interface.
In order to use the interface to its actual potential, so that it doesnāt matter if the implementation is a ScriptableObject or Component, requires to expose the IAudioClipScriptableObject interface to the Inspector, rather than the type that implements that interface.
How do you make Unity 2019.4 serialize an interface? Using the SerializeReference attribute does expose it, but there is no UI:
public interface IAudioClipScriptableObject { }
public class NewBehaviourScript : MonoBehaviour
{
[SerializeReference]
public IAudioClipScriptableObject audioThingy;
Unity does show the field āaudioThingyā in the Inspector, but it doesnāt allow me to pick anything. Do I need to implement a custom property drawer for it?
I would like Unity to display a āSelection windowā for ScriptableObjects that implement IAudioClipScriptableObject, as well as Prefabs that have components that implement the IAudioClipScriptableObject. How would I do this?
Exposing the ScriptableObject that actually implements the interface, rather than using interface, unfortunately defeats the purpose to use an interface in the first place in my opinion.
Because then itās again bound to a specific type, in this case the āabstract ScriptableObjectā. Means if I implement the IAudioClipScriptableObject in a Component instead of a ScriptableObject, I would need to expose the component to the Inspector. So we would end up with different types and the user needs to understand when and where to use what. Thatās not ideal in my opinion.
public class NewBehaviourScript : MonoBehaviour
{
public AudioClipScriptableObject audioSO;
Thatās true. It reveals another weakness of the Unity editor that Unity Technologies should solve. The Open Projects initiative is a great opportunity for us to show Unity staff where the tech lacks. This is another prime example where functionality is missing.
Can you provide examples of those different components that implement the IAudioClipScriptableObject interface? What is the AudioSourceType for?