using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class Splash : MonoBehaviour
{
    private void Start()
    {
        StartCoroutine(loadScene());
        AppConfig.Instance.InitProgect(true);

        Login();
        //HttpTool.Instance._Post("app/v1/auth/tourist-login","", null, new Action<EmptyBean>((result) =>
        //{

        //}), new Action<string, string>((code, msg) =>
        //{
        //    Debug.unityLogger.Log("游客登录 " + code + " msg " + msg);
        //}));

        //HttpTool.Instance._Get("app/v1/watermelon/info", null, new Action<EmptyBean>((result) =>
        //{

        //}), new Action<string, string>((code, msg) =>
        //{
        //    Debug.unityLogger.Log("首页信息 " + code + " msg " + msg);
        //}));
    }



    private void Login()
    {
        if (AppConfig.Instance.getToken().Equals(""))
        {
            //游客登录
            WxLoginUtil.Instance.DeviceLogin(new Action<bool>((LoginResult) =>
            {
                if (LoginResult)
                {
                    IsJump = true;
                }
            }));
           
        }
        else
        {
            IsJump = true;
        }
    }

    private static bool IsJump = false;

    private AsyncOperation async = null;
    //进度条的数值
    private float progressValue;

    private IEnumerator loadScene()
    {
        //异步加载下一个场景
        async = SceneManager.LoadSceneAsync(1);
        async.allowSceneActivation = false;
        while (!async.isDone)
        {
            if (async.progress < 0.9f)
                progressValue = async.progress;
            else
                progressValue = 1.0f;

            //LoadingProgress.fillAmount = progressValue;
            if (progressValue >= 0.9)
            {
                async.allowSceneActivation = IsJump;
            }

            yield return null;
        }
    }
}
