using System.IO;
using UnityEngine;
using UnityEngine.Events;

public class NetManager : BaseManager<NetManager>
{
    private NetManager() { }

    /// <summary>
    /// 网络访问的token
    /// </summary>
    public string token;

    public string url;

    /// <summary>
    /// 获取本地配置文件
    /// </summary>
    /// <param name="action"></param>
    public void GetConfig(UnityAction<bool> action) 
    {
        string path = Application.streamingAssetsPath + "/Config/Config.txt";
        Debug.Log(path);
        if (File.Exists(path))
        {
            Debug.Log(File.ReadAllText(path));
            url = File.ReadAllText(path);
            action?.Invoke(true);
        }
        else
        {
            Debug.Log("没有对应的文件");
            action?.Invoke(false);
            //UIManager.Instance.ShowPanel<UI_MessagePanel>(E_UI_Layer.System, (panel) =>
            //{
            //    panel.Init("没有读取到正确的Ip地址文件,请检查项目StreamingAssets文件夹下Config文件是否正常配置地址端口后再试!", E_MessageType.Error, Const.E_QuitApp);
            //});
        }

    }

    public void SaveInfo(string info) 
    {
        string path = Application.streamingAssetsPath + "/Config/info.txt";
        Debug.Log(path);
        File.WriteAllText(path, info);
    }
        

}
