using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Android;
using Rokid.MRC;

namespace Rokid.MRC
{
    public enum ARCalibrationMode
    {
        FaceTrack,
        SelfCalibration,
    }

    public class MRCDriver : UnitySingleton<MRCDriver>
    {
        public bool UseGlobalRenderCamera;

        [HideInInspector]
        public bool ShowAnchorUI = false;
        [HideInInspector]
        public bool ShowCompositeUI = true;

        public bool ShowClientAnchor = true;

        [HideInInspector]
        public Transform SelfCalibrationPhone;

        public override void Awake()
        {
            base.Awake();

            Init();
        }

        void Init()
        {
            LocalizationMgr.Instance.SetLanguage(Application.systemLanguage);
            SDKManager.Instance.Init();

            UIManager.Instance.Init();
            if(!UIManager.Instance.HideUISystem)
            {
                UIManager.Instance.OpenPanel(UIType.Connection);
            }

            //用于编辑器下，直接打开MRCRoot场景，导致无摄像机的情况
            if(Camera.main == null)
            {
                GameObject obj = new GameObject("MainCamera");
                obj.tag = "MainCamera";
                Camera camera = obj.AddComponent<Camera>();
            }
        }

        private void Update()
        {
            //获取位置权限
            if(!Permission.HasUserAuthorizedPermission(Permission.FineLocation))
            {
                Permission.RequestUserPermission(Permission.FineLocation);
            }

            if(!Permission.HasUserAuthorizedPermission(Permission.Microphone))
            {
                Permission.RequestUserPermission(Permission.Microphone);
            }
        }

        //当跳出设置Wifi后，重新刷新本机IP地址
        public void OnApplicationPause(bool pause)
        {
            if(!pause)
            {
                MessageCenter.SendMessage(GlobalDefine.RefreshConnectPanel, null);
            }
            else
            {
                TransmissionClient.Release();
            }
        }
    }
}
