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

public class LoadIngGame : MonoBehaviour
{
    public Image loading_index;
    void Start()
    {
        AndroidJavaClass jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
        AndroidJavaObject mainActivity = jc.GetStatic<AndroidJavaObject>("currentActivity");
        try
        {
            Debug.Log("调用loading");
            mainActivity.Call("getListLandNew", 1);
        }
        catch
        {
            string json = "{\"landList\":[{\"id\":1,\"name\":\"白菜\",\"unlockPrice\":0,\"seedPrice\":5,\"profit\":7,\"second\":60,\"countDownSecond\":0,\"status\":3,\"seedNum\":0,\"cloudSecond\":10,\"acceleratorsSecond\":5,\"guideStatus\":0,\"growList\":[{\"start\":1,\"countdown\":60},{\"start\":31,\"countdown\":120},{\"start\":41,\"countdown\":300},{\"start\":46,\"countdown\":480},{\"start\":51,\"countdown\":600},{\"start\":71,\"countdown\":720},{\"start\":81,\"countdown\":900},{\"start\":91,\"countdown\":1200},{\"start\":96,\"countdown\":1800}],\"fruitNum\":45,\"acceleratorsNum\":0},{\"id\":2,\"name\":\"番茄\",\"unlockPrice\":5,\"seedPrice\":10,\"profit\":15,\"second\":120,\"countDownSecond\":0,\"status\":1,\"seedNum\":0,\"cloudSecond\":10,\"acceleratorsSecond\":5,\"guideStatus\":0,\"growList\":[{\"start\":1,\"countdown\":120},{\"start\":31,\"countdown\":240},{\"start\":41,\"countdown\":360},{\"start\":46,\"countdown\":480},{\"start\":51,\"countdown\":600},{\"start\":71,\"countdown\":900},{\"start\":81,\"countdown\":1200},{\"start\":91,\"countdown\":1200},{\"start\":96,\"countdown\":1800}],\"fruitNum\":47,\"acceleratorsNum\":0},{\"id\":3,\"name\":\"南瓜\",\"unlockPrice\":10,\"seedPrice\":20,\"profit\":32,\"second\":240,\"countDownSecond\":0,\"status\":1,\"seedNum\":0,\"cloudSecond\":10,\"acceleratorsSecond\":5,\"guideStatus\":0,\"growList\":[{\"start\":1,\"countdown\":240},{\"start\":31,\"countdown\":360},{\"start\":41,\"countdown\":480},{\"start\":46,\"countdown\":600},{\"start\":51,\"countdown\":600},{\"start\":71,\"countdown\":720},{\"start\":81,\"countdown\":900},{\"start\":91,\"countdown\":1200},{\"start\":96,\"countdown\":1800}],\"fruitNum\":38,\"acceleratorsNum\":0},{\"id\":4,\"name\":\"萝卜\",\"unlockPrice\":50,\"seedPrice\":30,\"profit\":51,\"second\":480,\"countDownSecond\":0,\"status\":3,\"seedNum\":0,\"cloudSecond\":10,\"acceleratorsSecond\":5,\"guideStatus\":0,\"growList\":[{\"start\":1,\"countdown\":480},{\"start\":31,\"countdown\":480},{\"start\":41,\"countdown\":600},{\"start\":46,\"countdown\":600},{\"start\":51,\"countdown\":720},{\"start\":71,\"countdown\":900},{\"start\":81,\"countdown\":1200},{\"start\":91,\"countdown\":1500},{\"start\":96,\"countdown\":1800}],\"fruitNum\":34,\"acceleratorsNum\":0},{\"id\":5,\"name\":\"玉米\",\"unlockPrice\":100,\"seedPrice\":50,\"profit\":90,\"second\":600,\"countDownSecond\":0,\"status\":3,\"seedNum\":0,\"cloudSecond\":10,\"acceleratorsSecond\":5,\"guideStatus\":0,\"growList\":[{\"start\":1,\"countdown\":600},{\"start\":31,\"countdown\":720},{\"start\":41,\"countdown\":900},{\"start\":46,\"countdown\":1200},{\"start\":51,\"countdown\":1500},{\"start\":71,\"countdown\":1800},{\"start\":81,\"countdown\":2700},{\"start\":91,\"countdown\":3600},{\"start\":96,\"countdown\":7200}],\"fruitNum\":38,\"acceleratorsNum\":0},{\"id\":6,\"name\":\"茄子\",\"unlockPrice\":200,\"seedPrice\":80,\"profit\":144,\"second\":720,\"countDownSecond\":0,\"status\":3,\"seedNum\":0,\"cloudSecond\":10,\"acceleratorsSecond\":5,\"guideStatus\":0,\"growList\":[{\"start\":1,\"countdown\":720},{\"start\":31,\"countdown\":900},{\"start\":41,\"countdown\":1200},{\"start\":46,\"countdown\":1500},{\"start\":51,\"countdown\":1800},{\"start\":71,\"countdown\":2400},{\"start\":81,\"countdown\":3600},{\"start\":91,\"countdown\":7200},{\"start\":96,\"countdown\":10800}],\"fruitNum\":32,\"acceleratorsNum\":0},{\"id\":7,\"name\":\"西瓜\",\"unlockPrice\":300,\"seedPrice\":100,\"profit\":180,\"second\":900,\"countDownSecond\":0,\"status\":3,\"seedNum\":0,\"cloudSecond\":10,\"acceleratorsSecond\":5,\"guideStatus\":0,\"growList\":[{\"start\":1,\"countdown\":900},{\"start\":31,\"countdown\":1200},{\"start\":41,\"countdown\":1500},{\"start\":46,\"countdown\":1800},{\"start\":51,\"countdown\":2400},{\"start\":71,\"countdown\":3600},{\"start\":81,\"countdown\":5400},{\"start\":91,\"countdown\":7200},{\"start\":96,\"countdown\":10800}],\"fruitNum\":20,\"acceleratorsNum\":0},{\"id\":8,\"name\":\"葡萄\",\"unlockPrice\":500,\"seedPrice\":200,\"profit\":360,\"second\":1200,\"countDownSecond\":0,\"status\":3,\"seedNum\":0,\"cloudSecond\":10,\"acceleratorsSecond\":5,\"guideStatus\":0,\"growList\":[{\"start\":1,\"countdown\":1200},{\"start\":31,\"countdown\":1500},{\"start\":41,\"countdown\":1800},{\"start\":46,\"countdown\":2400},{\"start\":51,\"countdown\":3600},{\"start\":71,\"countdown\":5400},{\"start\":81,\"countdown\":7200},{\"start\":91,\"countdown\":10800},{\"start\":96,\"countdown\":14400}],\"fruitNum\":18,\"acceleratorsNum\":0},{\"id\":9,\"name\":\"草莓\",\"unlockPrice\":1000,\"seedPrice\":300,\"profit\":540,\"second\":1500,\"countDownSecond\":0,\"status\":3,\"seedNum\":0,\"cloudSecond\":10,\"acceleratorsSecond\":5,\"guideStatus\":0,\"growList\":[{\"start\":1,\"countdown\":1500},{\"start\":31,\"countdown\":1800},{\"start\":41,\"countdown\":2400},{\"start\":46,\"countdown\":3600},{\"start\":51,\"countdown\":5400},{\"start\":71,\"countdown\":7200},{\"start\":81,\"countdown\":10800},{\"start\":91,\"countdown\":14400},{\"start\":96,\"countdown\":21600}],\"fruitNum\":16,\"acceleratorsNum\":0}]}";
            loadLandListSuccess(json);
        }


    }

    public void loadLandListSuccess(string json)
    {
        Debug.Log("LoadIng data Json:" + json);
        LandListDataControl.GetIns().saveLandListJson(json);
        StartCoroutine(loadScene());
    }

    public void loadLoadingLandListSuccess(string json)
    {
        Debug.Log("2调用loading");
        Debug.Log("LoadIng data Json:" + json);
        LandListDataControl.GetIns().saveLandListJson(json);
        StartCoroutine(loadScene());
    }




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

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

            loading_index.fillAmount = progressValue;
            if (progressValue >= 0.9)
            {
                async.allowSceneActivation = true;
            }

            yield return null;
        }

    }
}
