I\'m trying to create a class hierarchy such that I can have:
SpecificScreenController < ScreenController < Singleton
So far I have these set up as:
The problem here is one of covariance. You're assuming that if SpecificScreenController
inherits from MonoBehaviour
then ScreenController<SpecificScreenController>
also inherits from ScreenController<MonoBehaviour>
. It doesn't. You can't do this cast.
As there seem to be no really clean solutions to this issue I ended up removing Singleton from my class hierarchy and copy-pasted non-generic versions of the singleton property get/instantiate code into each of the classes that I wanted to be singletons.
public abstract class ScreenController : MonoBehaviour
{
}
public class SpecificScreenController : ScreenController
{
private static SpecificScreenController _instance;
public static SpecificScreenController Instance{ get{... return _instance;}
}