using UnityEngine;

namespace Guru.UI
{
    public class GuruContext: Context
    {
        private static GuruContext _instance;
        public static GuruContext Instance
        {
            get
            {
                if (_instance == null)
                    _instance = Create<GuruContext>();
                
                return _instance;
            }
        }
        private GuruResManager _resMgr;
        private GuruUIController _uiCtrl;

        /// <summary>
        /// 初始化调用
        /// </summary>
        protected override void OnCreated()
        {
            _resMgr = GuruResManager.Create(this); // 资源控制器
            _uiCtrl = GuruUIController.Create(this); // UI 控制器
        }
        
        protected override void OnStart()
        {
            AutoOrientation();
        }

        /// <summary>
        /// 设置旋转
        /// </summary>
        /// <param name="orientation"></param>
        public void SetOrientation(ScreenOrientation orientation = ScreenOrientation.Portrait)
        {
            _uiCtrl.SetOrientation(orientation);
        }
        
        /// <summary>
        /// 自动调整方向
        /// </summary>
        private void AutoOrientation()
        {
            // 旋转方向
            var o = Screen.width > Screen.height ? ScreenOrientation.Landscape : ScreenOrientation.Portrait;
            SetOrientation(o);
        }
        
        

        















    }
}