MonoBehaviour pseudo-singleton with C# generics

Hello,

The Singletons with coroutines? question offers a singleton implementation compatible with MonoBehaviour:

public class EasySingleton {
  private static EasySingleton instance = null;
  public static EasySingleton Instance { get { return instance; } }

  void Awake() {
    instance = this;
  }
}

I’d like to make this class generic to be able to declare a singleton class, something along the lines of:

public class EasySingleton<T> : MonoBehaviour {
  private static T instance = default(T);
  public static T Instance { get { return instance; } }

  void Awake() {
    instance = this;
  }
}

public class OnlyOne : EasySingleton<OnlyOne>
{
}

But I’m stuck with the fact that ‘this’ can’t be cast to T in the Awake() method.
What’s the proper way to achieve what I need?

Thank you!

http://unifycommunity.com/wiki/index.php?title=Singleton#Generic_Based_Singleton_for_MonoBehaviours