using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;

public class ReadLoginInfo : MonoBehaviour
{
    public MainSelect mainselect;
    /// <summary>
    /// 获取登入时间
    /// </summary>
    public string time;
    private void Awake()
    {
        Init();
    }

    private void Init()
    {
        DontDestroyOnLoad(this.gameObject);
        time = DateTime.Now.ToString();
        PlayerPrefs.SetString("time", time);
        LoadInfo();
    }

    void Start()
    {
      
    }
    /// <summary>
    /// 通过判断跳转场景
    /// </summary>
    private void LoadInfo()
    {
        string str;
        string path = Application.streamingAssetsPath + @"\info.ini";
        if (File.Exists(path))
        {
            str = File.ReadAllText(path);
            string[] data = str.Split(new char[] { ';' });
            //DateTime dateTime = DateTime.Parse(data[0]);
            //TimeSpan timeSpan = DateTime.Now - dateTime;
            //if (dateTime.Second > 60)
            //{
            //    Debug.Log("请求超时");
            //}
            //else
            //{
            string[] data2 = data[1].Split(new char[] { ',' });
            Debug.Log(data2[0]);
            if (data2[0]=="0")
            {
                PlayerPrefs.SetString("Name", data2[3]);
                mainselect.practicebutton.onClick.Invoke();
                Debug.Log("进入了");
            }
            else if (data2[0]=="1")
            {
                Debug.Log(data2[3]);
                PlayerPrefs.SetString ("Name", data2[3]);
                mainselect.examinationbutton.onClick.Invoke();
                Debug.Log("跳转");
            }
            else if (data2[0] == "2")
            {
                Debug.Log(data2[3]);
                PlayerPrefs.SetString("Name", data2[3]);
                mainselect.Powersupplytest.onClick.Invoke();
                Debug.Log("跳转");
            }
            else if(data2[0] == "3")
            {
                Debug.Log(data2[3]);
                PlayerPrefs.SetString("Name", data2[3]);
                mainselect.Electricityfeetest.onClick.Invoke();
                Debug.Log("跳转");
            }
        }
    }

    void Update()
    {

    }
}