using UnityEngine; using System.Collections; namespace Touka.GameLogic { /// /// 单例类 /// /// public class ToukaSingleton where T : MonoBehaviour { private static T _instance; public static T GetInstance() { if (null == _instance) { _instance = Object.FindObjectOfType(typeof(T)) as T; if (null != _instance) return _instance; GameObject container = new GameObject { name = typeof(T).ToString() }; container.hideFlags = HideFlags.HideInHierarchy; _instance = container.AddComponent(typeof(T)) as T; Object.DontDestroyOnLoad(container); } return _instance; } } public abstract class ToukaSingletonMonoBehaviour : MonoBehaviour where T : MonoBehaviour { public static T Instance { get { return ToukaSingleton.GetInstance(); } } public static T GetInstance() { return ToukaSingleton.GetInstance(); } public virtual void Dispose() { } } }