using System;
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using System.Collections.Generic;
using LitJson;
//SendMessageOptions#
//SendMessageOptions.RequireReceiver //如果没有找到相应函数，会报错(默认是这个状态)
//SendMessageOptions.DontRequireReceiver //即使没有找到相应函数，也不会报错，自动忽略
//在这个游戏物体上的所有MonoBehaviour上调用名称为methodName的方法。
//接收消息的方法可以通过不要参数的方法来选择忽略参数。当选项被设置为SendMessageOptions.RequireReceiver时，如果消息没有被任何一个组件处理，则会打印一个错误。

public class FarmControl : MonoBehaviour, GameListenerHelper.IFarmListener
{
    //云朵加速
    public GameObject cloudSpeedImgBtn;
    public GameObject cloudSpeedAnim;
    public GameObject cloudAnimObj;
    public GameObject[] landObjList;
    //引导
    //public GameObject guideHandImg;
    //public GameObject guideHandBgImg;
    //public GameObject guideDuihuaImg;
    //public GameObject redPackListObj;
    //public Text yindaotext;
    public Text cloudTimeTv;
    //public GameObject ruoyindao;
    //Android
    private bool isBackGround = false;
    private AndroidJavaObject mainActivity;
    public GameObject floatpuzzle;
    private void Awake()
    {
        AndroidJavaClass jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
        mainActivity = jc.GetStatic<AndroidJavaObject>("currentActivity");
    }

    private int onClickLandId;
    //最后一次点击的position
    public int setOnclickLandId
    {
        //get { return onClickLandId; }
        set { onClickLandId = value; }
    }
    private void Start()
    {
        getGuide();
        //guideHandImg.SetActive(false);
        //guideHandBgImg.SetActive(false);
        //获取土地列表
        getLandList();
        cloudTimeTv.text = "减" + LandListDataControl.GetIns().getCloudTime() + "分钟";
    }

    private void getGuide()
    {
        try
        {
            if (mainActivity != null)
            {
                mainActivity.Call("getGuide", new GameListenerHelper.ICallBackListener(this));
            }
        }
        catch (Exception e)
        {
            Debug.Log("getGuide ERROR" + e.Message);
        }
    }

    //获取土地列表
    public void getLandList()
    {
        GameObject.Find("TitleView").GetComponent<TitleControl>().getHomeInfo();
        //try
        //{
        //    if (!isBackGround)
        //    {
        //        mainActivity.Call("getListLand", new GameListenerHelper.ICallBackListener(this));
        //        //刷新土地的时候，也刷新title
        //        GameObject.Find("TitleView").GetComponent<TitleControl>().getHomeInfo();
        //    }
        //}
        //catch (Exception e)
        //{
        //    Debug.Log("getListLand ERROR" + e.Message);
        //    //string result9 = "{\"landList\":[{\"countDownSecond\":49,\"id\":1,\"name\":\"白菜\",\"ownNum\":0,\"profit\":6,\"second\":60,\"seedNum\":0,\"seedPrice\":5,\"status\":3,\"unlockPrice\":30},{\"countDownSecond\":110,\"id\":2,\"name\":\"番茄\",\"ownNum\":0,\"profit\":14,\"second\":120,\"seedNum\":0,\"seedPrice\":10,\"status\":2,\"unlockPrice\":50},{\"countDownSecond\":106,\"id\":3,\"name\":\"南瓜\",\"ownNum\":0,\"profit\":30,\"second\":300,\"seedNum\":0,\"seedPrice\":20,\"status\":2,\"unlockPrice\":100},{\"countDownSecond\":596,\"id\":4,\"name\":\"萝卜\",\"ownNum\":0,\"profit\":60,\"second\":600,\"seedNum\":0,\"seedPrice\":40,\"status\":2,\"unlockPrice\":200},{\"countDownSecond\":1799,\"id\":5,\"name\":\"玉米\",\"ownNum\":0,\"profit\":110,\"second\":1800,\"seedNum\":0,\"seedPrice\":80,\"status\":2,\"unlockPrice\":300},{\"countDownSecond\":0,\"id\":6,\"name\":\"茄子\",\"ownNum\":0,\"profit\":200,\"second\":3600,\"seedNum\":0,\"seedPrice\":160,\"status\":4,\"unlockPrice\":500},{\"countDownSecond\":0,\"id\":7,\"name\":\"西瓜\",\"ownNum\":0,\"profit\":380,\"second\":7200,\"seedNum\":0,\"seedPrice\":320,\"status\":0,\"unlockPrice\":1000},{\"countDownSecond\":0,\"id\":8,\"name\":\"葡萄\",\"ownNum\":0,\"profit\":712,\"second\":14400,\"seedNum\":0,\"seedPrice\":640,\"status\":0,\"unlockPrice\":2500},{\"countDownSecond\":0,\"id\":9,\"name\":\"草莓\",\"ownNum\":0,\"profit\":1352,\"second\":21600,\"seedNum\":0,\"seedPrice\":1280,\"status\":0,\"unlockPrice\":5000}]}";
        //    //JsonReader fr = new JsonReader(resu2);
        //    //LandListEntity bean = JsonMapper.ToObject<LandListEntity>(fr);
        //    //LandListEntity bean = JsonUtility.FromJson<LandListEntity>(result9);
        //    //onInitFarmResult(bean.landList);
        //}
    }

    //云朵加速弹窗点击
    public void onClickCloudSpeed()
    {
        if (GameClickControl.GetGameClick().gameClick)
        {
            try
            {
                GameObject.Find("GameManager").GetComponent<UnityToAndroid>().onEventUtil("click_cloud_speed_up_video_btn", "云朵加速视频点击");
                mainActivity.Call("getCloudSpeed", new GameListenerHelper.ICallBackListener(this));
            }
            catch (Exception e)
            {
                Debug.Log("getCloudSpeed ERROR" + e.Message);
                //onSpeedUpSuccess(null);
            }
        }

    }
    //private int tempSeedId = 0;
    //解锁地块/种植种子/收获果实
    public void onClickUnlockLand(int id, int type)
    {
        Debug.Log("解锁地块/种植种子/收获果实 id" + id + "type" + type);
        if (GameClickControl.GetGameClick().gameClick)
        {
            //tempSeedId = id;
            if (type == 4)
            {
                onClickAcceleratedWater(id);
            }
            else
            {
                try
                {
                    mainActivity.Call("getUnlockLand", new GameListenerHelper.ICallBackListener(this), id, type);
                }
                catch (Exception e)
                {
                    Debug.Log("getUnlockLand ERROR" + e.Message);
                    //StatusEntity s = JsonUtility.FromJson<StatusEntity>("{\"awardCash\":0,\"cloudSecond\":0,\"id\":1,\"needCoin\":6,\"num\":0,\"status\":1,\"type\":3,\"videoNum\":0}");
                    //onUnLockLandSuccess(s);
                    //GameObject.Find("dialog").GetComponent<DialogControl>().showSeedNotEnough(2, 3, 4);
                    //transform.root.BroadcastMessage("showGetGoods", s, SendMessageOptions.DontRequireReceiver);
                }
            }
        }
    }
    //使用加速剂
    private void onClickAcceleratedWater(int id)
    {
        if (GameClickControl.GetGameClick().gameClick)
        {
            try
            {
                mainActivity.Call("getUseAccelerators", new GameListenerHelper.ICallBackListener(this), id);
            }
            catch (Exception e)
            {
                Debug.Log("getUseAccelerators ERROR" + e.Message);
                //GameObject.Find("dialog").GetComponent<DialogControl>().showUseSpeedWater(2);
                //transform.root.BroadcastMessage("showLandWater", tempSeedId, SendMessageOptions.DontRequireReceiver);
            }
        }

    }
    //使用加速剂
    public void onClickUseAcceleratedWater()
    {
        if (GameClickControl.GetGameClick().gameClick)
        {
            //使用加速剂
            //onClickAcceleratedWater(tempSeedId);
            GameObject.Find("dialog").GetComponent<DialogControl>().closeUseSpeedWater();
        }
    }


    //金币购买种子
    public void onBuySeed()
    {
        //关闭种子不足弹窗
        GameObject.Find("dialog").GetComponent<DialogControl>().closeSeedNotEnough();
        try
        {
            if (onClickLandId >= 0)
            {
                //LandEntity land = LandListDataControl.GetIns().getLandListDataPos(onClickLandId);
                LandDataControl mLandData = landObjList[onClickLandId].GetComponent<LandDataControl>();

                if (CoinNumControl.GetIns().getMyCoin < mLandData.getMyLandEntity.seedPrice)
                {
                    Debug.Log("购买种子 金币不足");//金币不足
                    GameObject.Find("dialog").GetComponent<DialogControl>().showCoinNotEnough();
                }
                else
                {
                    if (mLandData.buySeed(onClickLandId))
                    {
                        //设置生虫
                        int time = mLandData.setCreatWormTime();

                        //同步服务端
                        try
                        {
                            mainActivity.Call("getBuySeed", onClickLandId + 1, time);
                        }
                        catch (Exception e)
                        {
                            Debug.Log("getBuySeed ERROR" + e.Message);
                        }
                        //购买种子成功 本地
                        Debug.Log("购买种子 正常 刷新");
                        CoinNumControl.GetIns().payMyCoin(mLandData.getMyLandEntity.seedPrice);
                        mLandData.updateMyLand();
                        //GetComponent<LandListEvent>().updateLandList(4, onClickLandId);
                        
                    }
                    //GameObject.Find("TitleView").GetComponent<TitleControl>().getHomeInfo();
                }
                //mainActivity.Call("getBuySeed", new GameListenerHelper.ICallBackListener(this), onClickLandId + 1);
            }
        }
        catch (Exception e)
        {
            Debug.Log("getBuySeed ERROR" + e.Message);
        }
    }
    //看视频领取种子
    public void onVideoSeedReceive()
    {
        if (GameClickControl.GetGameClick().gameClick)
        {
            //关闭弹窗
            GameObject.Find("dialog").GetComponent<DialogControl>().closeSeedNotEnough();
            GameObject.Find("GameManager").GetComponent<UnityToAndroid>().onEventUtil("click_Insufficient_seeds_video_btn", "免费领取种子视频");
            if (CoinNumControl.GetIns().getSubSeedVideoNum <= 0)
            {
                GameObject.FindGameObjectWithTag("toast").GetComponent<ToastManager>().CreatToast("视频次数已用完，明天再来吧~");
            }
            else
            {
                if (onClickLandId >= 0)
                {
                    LandDataControl mLandData = landObjList[onClickLandId].GetComponent<LandDataControl>();
                    //设置生虫
                    int time = mLandData.setCreatWormTime();
                    try
                    {
                        //mainActivity.Call("getVideoSeedReceive", new GameListenerHelper.ICallBackListener(this), onClickLandId+1);
                        mainActivity.Call("getVideoSeedReceiveNew", onClickLandId + 1, time);
                    }
                    catch (Exception e)
                    {
                        Debug.Log("getVideoSeedReceive ERROR" + e.Message);
                        //onVideoSeedResult(null);
                        //onVideoSeedReceiveSuccess(onClickLandId+"");
                    }
                }
            }
        }
    }
    //看视频领取种子成功
    public void onVideoSeedReceiveSuccess(string onClickId)
    {
        //看一次种子不足视频 减少一次
        CoinNumControl.GetIns().lookSeedsVideoNUm();
        int position = int.Parse(onClickId);
        LandDataControl mLandData = landObjList[position].GetComponent<LandDataControl>();
        if (mLandData.buySeed(onClickLandId))
        {   //购买种子成功
            Debug.Log("看视频获取种子成功 刷新");
            //CoinNumControl.GetIns().payMyCoin(land.seedPrice);
            mLandData.updateMyLand();
            GetComponent<LandListEvent>().updateLandList(4, onClickLandId,0);
        }
    }


    //看视频领取加速剂
    public void onVideoAcceleratorReceive()
    {
        if (GameClickControl.GetGameClick().gameClick)
        {
            //关闭弹窗
            GameObject.Find("dialog").GetComponent<DialogControl>().closeGetJiasu();
            GameObject.Find("GameManager").GetComponent<UnityToAndroid>().onEventUtil("click_free_get_accelerometer_video_btn", "免费领取加速剂视频");
            if (CoinNumControl.GetIns().getSubAcceleratorsVideoNum <= 0)
            {
                GameObject.FindGameObjectWithTag("toast").GetComponent<ToastManager>().CreatToast("视频次数已用完，明天再来吧~");
            }
            else
            {
                try
                {
                    mainActivity.Call("getVideoAcceleratorsReceive", new GameListenerHelper.ICallBackListener(this), onClickLandId + 1);
                }
                catch (Exception e)
                {
                    Debug.Log("getVideoAcceleratorsReceive ERROR" + e.Message);
                    //StatusEntity s = new StatusEntity();
                    //s.id = onClickLandId + 1;
                    //s.acceleratorsNum = 2;
                    //onVideoAcceleratorsResult(s);
                }
            }

        }
    }

    //解锁菜地更新下一块地
    public void updateNextLand(int position)
    {
        Debug.Log("解锁下一块地" + position);
        if (position < 8 && landObjList[position] != null)
        {
            LandDataControl mLand = landObjList[position + 1].GetComponent<LandDataControl>();
            if (mLand.getMyLandEntity.status == 0)//未解锁
            {
                Debug.Log("解锁下一块地成功");
                mLand.getMyLandEntity.status = 4;//未解锁变为待解锁
                mLand.updateMyLand();
            }
        }
    }


    private void Update()
    {
      
    }
    public GameObject landParent;
    public GameObject landItem;
    private string[] landName = { "白菜", "番茄", "南瓜", "萝卜", "玉米", "茄子", "西瓜", "葡萄", "草莓" };
    public void onInitFarmResult(LandEntity[] landList)
    {
        Debug.Log("onInitFarmResult" + landList.Length);
        //if (landList != null)
        //{

        //    if (landList.Length > 0)
        //    {

        //        if (PlayerPrefs.GetInt("isFirstPlant") == 0)
        //        {
        //            if (landList[0].status == 1)
        //            {
        //                yindaotext.text = "种下一棵菜，\n可兑换现金";
        //            }
        //            if (landList[0].status == 2)
        //            {
        //                yindaotext.text = "使用加速剂，可缩短成熟时间";
        //            }
        //            if (landList[0].status == 3)
        //            {
        //                yindaotext.text = "收获一颗菜，可直接兑换现金";
        //            }
        //        }
        //    }

        //    for (int i = 0; i < landList.Length; i++)
        //    {
        //        transform.BroadcastMessage("updateLand", landList[i], SendMessageOptions.DontRequireReceiver);
        //    }
        //}
    }

    public void onSpeedUpSuccess(StatusEntity status)
    {
        Debug.Log("onCloudSpeedSuccess6");
        //云朵加速弹窗 剩余次数传值
        //GameObject.Find("dialog").GetComponent<DialogControl>().CloudSpeedNum = status.num;
        Debug.Log("onCloudSpeedSuccess7");
        //关闭弹窗
        GameObject.Find("dialog").GetComponent<DialogControl>().closeCloudSpeedDialog();
        Debug.Log("onCloudSpeedSuccess8");
        //开启云朵加速倒计时
        //GameObject.Find("TitleView").GetComponent<TitleControl>().onCloudSecondResult(status.cloudSecond);
        Debug.Log("onCloudSpeedSuccess9");
        //开始浇水动画
        if (flyCloudControl != null)
        {
            Debug.Log("onCloudSpeedSuccess10");
            StopCoroutine(flyCloudControl);
        }
        Debug.Log("onCloudSpeedSuccess11");
        flyCloudControl = StartCoroutine(showCloudSpeedAnimation());
    }
    //提供给Android 调用 播放云朵加速动画
    public void showCloudSpeedAnim()
    {
        StartCoroutine(showCloudSpeedAnimation());
    }

    //解锁地块传1 种植种子传2 收获果实传3
    public void onUnLockLandSuccess(StatusEntity bean)
    {

        //金币不足
        if (bean.status == 2)
        {
            Debug.Log("解锁 金币不足");
            GameObject.Find("dialog").GetComponent<DialogControl>().showCoinNotEnough();
        }
        //种子不足
        if (bean.status == 3)
        {
            Debug.Log("解锁 种子不足");
            GameObject.Find("dialog").GetComponent<DialogControl>().showSeedNotEnough(bean.id, bean.needCoin, bean.videoNum);
        }
        //正常
        if (bean.status == 1)
        {
            Debug.Log("解锁 正常" + bean.type);
            switch (bean.type)
            {
                case 1:
                    GameObject.Find("dialog").GetComponent<DialogControl>().showJieSuoDiKuai(bean.id);
                    //GameObject.Find("GameManager").GetComponent<UnityToAndroid>().onEventUtil("show_unLock_farm_id_" + bean.id, "解锁地块id_" + bean.id);
                    getLandList();//再次请求土地列表，刷新土地数据
                    break;
                case 2:
                    getLandList();//再次请求土地列表，刷新土地数据
                    break;
                case 3:
                    //if (PlayerPrefs.GetInt("isFirstPlant", 0) == 0)
                    //{
                    //    PlayerPrefs.SetInt("isFirstPlant", 1);
                    //    GameObject.Find("GameManager").GetComponent<UnityToAndroid>().guideOverPlayPlyBox();
                    //    ruoyindao.SetActive(true);
                    //}
                    //if (guideHandImg.activeSelf != false || guideHandBgImg.activeSelf != false)
                    //{
                    //    guideHandImg.SetActive(false);
                    //    guideHandBgImg.SetActive(false);
                    //}
                    //transform.root.BroadcastMessage("showGetGoods", bean, SendMessageOptions.DontRequireReceiver);
                    break;
            }
        }

    }
    //加速剂成功
    public void onUseAcceleratorSuccess(StatusEntity bean)
    {
        //加速剂不足
        if (bean.status == 0)
        {
            Debug.Log("加速剂 不足");
            GameObject.Find("dialog").GetComponent<DialogControl>().showGetJiasu(bean.awardNum, bean.num);
        }
        //正常
        if (bean.status == 1)
        {
            Debug.Log("解锁 正常");
            //GameObject.Find("dialog").GetComponent<DialogControl>().showUseSpeedWater();
            //展示加速剂加速动画
            //transform.root.BroadcastMessage("showLandWater", tempSeedId, SendMessageOptions.DontRequireReceiver);
        }
        //GameObject.Find("TitleView").GetComponent<TitleControl>().getHomeInfo();
        //getLandList();//再次请求土地列表，刷新土地数据
    }
    //购买种子
    public void onBuySeedResult(StatusEntity bean)
    {
        //金币不足
        if (bean.status == 0)
        {
            Debug.Log("购买种子 金币不足");
            GameObject.Find("dialog").GetComponent<DialogControl>().showCoinNotEnough();
        }
        //正常
        if (bean.status == 1)
        {
            Debug.Log("购买种子 正常 刷新title");
            GameObject.Find("TitleView").GetComponent<TitleControl>().getHomeInfo();
        }
        getLandList();//再次请求土地列表，刷新土地数据
    }

    public void onVideoSeedResult(StatusEntity status)
    {
        //GameObject.Find("TitleView")?.GetComponent<TitleControl>().getHomeInfo();
        getLandList();//看视频获取种子成功 直接种植 刷新土地列表
    }

    public void onVideoAcceleratorsResult(StatusEntity status)
    {
        //看视频成功 减少一次机会
        //CoinNumControl.GetIns().lookAcceleratorsVideoNum();
        Debug.Log("看视频获取加速剂成功");
        //GameObject.Find("TitleView")?.GetComponent<TitleControl>().getHomeInfo();
        //transform.root.BroadcastMessage("showLandWater", tempSeedId, SendMessageOptions.DontRequireReceiver);
        if (status.id > 0)
        {
            LandDataControl mLandData = landObjList[status.id - 1].GetComponent<LandDataControl>();
            Fruit_Time time = mLandData.GetComponentInChildren<Fruit_Time>();
            time.onVideoBottle();
        }
        CoinNumControl.GetIns().getMyWaterBottle = status.acceleratorsNum;//获得的加速剂
    }

    public void onError(string message)
    {
        if (message == "LandError")
        {
            transform.BroadcastMessage("updateError", SendMessageOptions.DontRequireReceiver);
        }
        Debug.Log("Farm Error" + message);
        //关闭弹窗
        GameObject.Find("dialog").GetComponent<DialogControl>().closeCloudSpeedDialog();
        //getLandList();//再次请求土地列表，刷新土地数据
    }


    //云朵加速浇水动画
    private Coroutine flyCloudControl;
    private GameObject flyCloud;
    private IEnumerator showCloudSpeedAnimation()
    {
        yield return null;
        cloudAnimObj.SetActive(true);
        //Debug.Log("onCloudSpeedSuccess12");
        //GameClickControl.GetGameClick().gameClick = false;
        //if (flyCloud != null)
        //{
        //    Debug.Log("onCloudSpeedSuccess13");
        //    Destroy(flyCloud);
        //}
        //Debug.Log("onCloudSpeedSuccess14");
        //GameObject.Find("Music_Background").GetComponent<MusicPlayerControl>().playColudWaterAudio();
        //Debug.Log("onCloudSpeedSuccess15");
        //flyCloud = Instantiate(cloudSpeedAnim, cloudSpeedImgBtn.transform.position, Quaternion.identity);
        //Debug.Log("onCloudSpeedSuccess16");
        //flyCloud.transform.SetParent(cloudSpeedImgBtn.transform);
        //Debug.Log("onCloudSpeedSuccess17");
        yield return new WaitForSeconds(2f);
        Debug.Log("onCloudSpeedSuccess18");
        //Destroy(flyCloud);
        //Debug.Log("onCloudSpeedSuccess19");
        transform.root.BroadcastMessage("showCloudSpeedFlyTime", SendMessageOptions.DontRequireReceiver);
        Debug.Log("onCloudSpeedSuccess20");
        //GameClickControl.GetGameClick().gameClick = true;
        //加速成功
        getLandList();//再次请求土地列表，刷新土地数据
    }

    private void OnApplicationPause(bool focus)
    {
        isBackGround = focus;
        if (focus)
        {
            Debug.Log("进入后台");
        }
        else
        {
            getLandList();
            updateSycnLandList();
            Debug.Log("进入前台");
        }
    }

    private void updateSycnLandList()
    {
        try
        {
            mainActivity.Call("getListLandNew", 2);
        }
        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}]}";
            //string json = "{\"landList\":[{\"id\":1,\"name\":\"白菜\",\"unlockPrice\":0,\"seedPrice\":5,\"profit\":7,\"second\":60,\"countDownSecond\":0,\"status\":1,\"seedNum\":0,\"cloudSecond\":10,\"acceleratorsSecond\":10,\"guideStatus\":1,\"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\":840},{\"start\":91,\"countdown\":960},{\"start\":96,\"countdown\":1200},{\"start\":141,\"countdown\":1800},{\"start\":146,\"countdown\":2400}],\"fruitNum\":21,\"acceleratorsNum\":1},{\"id\":2,\"name\":\"番茄\",\"unlockPrice\":5,\"seedPrice\":10,\"profit\":15,\"second\":120,\"countDownSecond\":0,\"status\":1,\"seedNum\":0,\"cloudSecond\":10,\"acceleratorsSecond\":10,\"guideStatus\":1,\"growList\":[{\"start\":1,\"countdown\":120},{\"start\":31,\"countdown\":240},{\"start\":41,\"countdown\":360},{\"start\":46,\"countdown\":480},{\"start\":51,\"countdown\":600},{\"start\":71,\"countdown\":720},{\"start\":81,\"countdown\":900},{\"start\":91,\"countdown\":1080},{\"start\":96,\"countdown\":1200},{\"start\":141,\"countdown\":2400},{\"start\":146,\"countdown\":3600}],\"fruitNum\":13,\"acceleratorsNum\":1},{\"id\":3,\"name\":\"南瓜\",\"unlockPrice\":10,\"seedPrice\":20,\"profit\":32,\"second\":240,\"countDownSecond\":0,\"status\":1,\"seedNum\":0,\"cloudSecond\":10,\"acceleratorsSecond\":10,\"guideStatus\":1,\"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\":1500},{\"start\":141,\"countdown\":1800},{\"start\":146,\"countdown\":2400}],\"fruitNum\":12,\"acceleratorsNum\":1},{\"id\":4,\"name\":\"萝卜\",\"unlockPrice\":50,\"seedPrice\":30,\"profit\":51,\"second\":480,\"countDownSecond\":0,\"status\":1,\"seedNum\":0,\"cloudSecond\":10,\"acceleratorsSecond\":10,\"guideStatus\":1,\"growList\":[{\"start\":1,\"countdown\":480},{\"start\":31,\"countdown\":480},{\"start\":41,\"countdown\":600},{\"start\":46,\"countdown\":600},{\"start\":51,\"countdown\":600},{\"start\":71,\"countdown\":900},{\"start\":81,\"countdown\":1200},{\"start\":91,\"countdown\":1500},{\"start\":96,\"countdown\":1500},{\"start\":141,\"countdown\":1800},{\"start\":146,\"countdown\":2400}],\"fruitNum\":12,\"acceleratorsNum\":1},{\"id\":5,\"name\":\"玉米\",\"unlockPrice\":100,\"seedPrice\":50,\"profit\":90,\"second\":600,\"countDownSecond\":0,\"status\":1,\"seedNum\":0,\"cloudSecond\":10,\"acceleratorsSecond\":10,\"guideStatus\":1,\"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\":2400},{\"start\":91,\"countdown\":3000},{\"start\":96,\"countdown\":4500},{\"start\":141,\"countdown\":4500},{\"start\":146,\"countdown\":4500}],\"fruitNum\":8,\"acceleratorsNum\":1},{\"id\":6,\"name\":\"茄子\",\"unlockPrice\":200,\"seedPrice\":80,\"profit\":144,\"second\":720,\"countDownSecond\":0,\"status\":1,\"seedNum\":0,\"cloudSecond\":10,\"acceleratorsSecond\":10,\"guideStatus\":1,\"growList\":[{\"start\":1,\"countdown\":720},{\"start\":31,\"countdown\":900},{\"start\":41,\"countdown\":1200},{\"start\":46,\"countdown\":1500},{\"start\":51,\"countdown\":1800},{\"start\":71,\"countdown\":2100},{\"start\":81,\"countdown\":2700},{\"start\":91,\"countdown\":3600},{\"start\":96,\"countdown\":5400},{\"start\":141,\"countdown\":5400},{\"start\":146,\"countdown\":5400}],\"fruitNum\":6,\"acceleratorsNum\":1},{\"id\":7,\"name\":\"西瓜\",\"unlockPrice\":300,\"seedPrice\":100,\"profit\":180,\"second\":900,\"countDownSecond\":575,\"status\":2,\"seedNum\":0,\"cloudSecond\":10,\"acceleratorsSecond\":10,\"guideStatus\":1,\"growList\":[{\"start\":1,\"countdown\":900},{\"start\":31,\"countdown\":1200},{\"start\":41,\"countdown\":1500},{\"start\":46,\"countdown\":1800},{\"start\":51,\"countdown\":2100},{\"start\":71,\"countdown\":2400},{\"start\":81,\"countdown\":3000},{\"start\":91,\"countdown\":3600},{\"start\":96,\"countdown\":7200},{\"start\":141,\"countdown\":7200},{\"start\":146,\"countdown\":7200}],\"fruitNum\":5,\"acceleratorsNum\":1},{\"id\":8,\"name\":\"葡萄\",\"unlockPrice\":500,\"seedPrice\":200,\"profit\":360,\"second\":1200,\"countDownSecond\":0,\"status\":1,\"seedNum\":0,\"cloudSecond\":10,\"acceleratorsSecond\":10,\"guideStatus\":1,\"growList\":[{\"start\":1,\"countdown\":1200},{\"start\":31,\"countdown\":1500},{\"start\":41,\"countdown\":1800},{\"start\":46,\"countdown\":2100},{\"start\":51,\"countdown\":2400},{\"start\":71,\"countdown\":2700},{\"start\":81,\"countdown\":3600},{\"start\":91,\"countdown\":4500},{\"start\":96,\"countdown\":7200},{\"start\":141,\"countdown\":7200},{\"start\":146,\"countdown\":7200}],\"fruitNum\":2,\"acceleratorsNum\":1},{\"id\":9,\"name\":\"草莓\",\"unlockPrice\":1000,\"seedPrice\":300,\"profit\":540,\"second\":1500,\"countDownSecond\":0,\"status\":1,\"seedNum\":0,\"cloudSecond\":10,\"acceleratorsSecond\":10,\"guideStatus\":1,\"growList\":[{\"start\":1,\"countdown\":1500},{\"start\":31,\"countdown\":1800},{\"start\":41,\"countdown\":2100},{\"start\":46,\"countdown\":2400},{\"start\":51,\"countdown\":2700},{\"start\":71,\"countdown\":3600},{\"start\":81,\"countdown\":4500},{\"start\":91,\"countdown\":5400},{\"start\":96,\"countdown\":7200},{\"start\":141,\"countdown\":7200},{\"start\":146,\"countdown\":7200}],\"fruitNum\":6,\"acceleratorsNum\":1}]}";
            //sycnLandListSuccess(json);
        }
    }
    //同步后台数据
    public void sycnLandListSuccess(string json)
    {
        if (LandListDataControl.GetIns().saveLandListJson(json))
        {
            StartCoroutine(sycnLandList());
        }
    }
    //执行同步后台数据
    private IEnumerator sycnLandList()
    {
        yield return null;
        transform.BroadcastMessage("updateMyLandData",true, SendMessageOptions.DontRequireReceiver);
    }

    //设置碎片动画
    public void getPuzzleCode(int position)
    {
        Debug.Log("播放获得碎片");
        StartCoroutine(playGetPuzzleAnim());
        //if (position >= 0 && position <= 8)
        //{
        //    LandAnimationControl mLandDataAnim = landObjList[position].GetComponentInChildren<LandAnimationControl>();
        //    StartCoroutine(playGetPuzzleAnim(mLandDataAnim));
        //}
    }
    //执行同步碎片动画
    private IEnumerator playGetPuzzleAnim()
    {
        yield return null;
        Debug.Log("调用播放获得碎片");
        floatpuzzle.SetActive(true);
       // landAnim.showPuzzle();
    }



    public void onGuideSuccess(GuideEntity guide)
    {
        PlayerPrefs.SetInt("isFirstPlant", guide.status);
        if (guide.status == 1)
        {
            GameObject.Find("GameManager").GetComponent<UnityToAndroid>().guideOverPlayPlyBox();
        }
    }
    //public void closeRuoYindao()
    //{
    //    //ruoyindao.SetActive(false);
    //}
}
