Singleton.cs 516 B

12345678910111213141516171819202122232425
  1. using UnityEngine;
  2. using System.Collections;
  3. namespace RootMotion {
  4. /// <summary>
  5. /// The base abstract Singleton class.
  6. /// </summary>
  7. public abstract class Singleton<T>: MonoBehaviour where T: Singleton<T> {
  8. private static T sInstance = null;
  9. public static T instance {
  10. get {
  11. return sInstance;
  12. }
  13. }
  14. protected virtual void Awake() {
  15. if (sInstance != null) Debug.LogError(name + "error: already initialized", this);
  16. sInstance = (T)this;
  17. }
  18. }
  19. }