namespace WS
{
    ///<summary>
    ///单例组件
    ///继承该组件后只能挂在Game.Scene上
    ///</summary>
    public class SingleComponent<T> : WSComponent where T : WSComponent, new()
    {
        private static T instance;
        public static T Instance
        {
            get
            {
                if (instance == null)
                {
                    instance = Game.Scene.GetComponent<T>();
                    if (instance == null)
                    {
                        instance = Game.Scene.AddComponent<T>();
                    }
                }
                return instance;
            }
        }

        public override void Dispose()
        {
            base.Dispose();
            instance = null;
        }
    }
}