61 lines
1.4 KiB
C#
61 lines
1.4 KiB
C#
using AdamSync;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using UnityEngine;
|
|
using UnityEngine.Networking;
|
|
using static InterfaceManager;
|
|
|
|
/// <summary>
|
|
/// 初始化接口IP 端口
|
|
/// </summary>
|
|
public class AddConfing : MonoBehaviour
|
|
{
|
|
private static string ipSetting = "IPPort.txt";
|
|
|
|
|
|
private void Awake()
|
|
{
|
|
string[] datas = ContectServer.ReadFromLocal("IPPort.txt").Split(':');
|
|
//Debug.Log(IP);
|
|
//Debug.Log(Port);
|
|
//Debug.Log(Url_Action);
|
|
IP = datas[0];
|
|
Port = datas[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 获取配置文件
|
|
/// </summary>
|
|
/// <param name="_settings"></param>
|
|
/// <param name="callback"></param>
|
|
/// <returns></returns>
|
|
public static IEnumerator GetSetting(string _settings, Action<string> callback)
|
|
{
|
|
string _url = Path.Combine(Application.streamingAssetsPath, _settings);
|
|
UnityWebRequest www = UnityWebRequest.Get(_url);
|
|
yield return www.SendWebRequest();
|
|
if (www.isNetworkError || www.isHttpError)
|
|
{
|
|
callback(null);
|
|
Debug.Log("网络请求失败了");
|
|
}
|
|
else
|
|
{
|
|
if (!string.IsNullOrEmpty(www.downloadHandler.text))
|
|
{
|
|
callback(www.downloadHandler.text);
|
|
}
|
|
else
|
|
{
|
|
callback(null);
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|