149 lines
3.1 KiB
C#
149 lines
3.1 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.Networking;
|
|
using UnityEngine.UI;
|
|
using UnityEngine.EventSystems;
|
|
using TMPro;
|
|
using Newtonsoft.Json;
|
|
using System.IO;
|
|
using static Drainage_tip;
|
|
|
|
|
|
[Serializable]
|
|
public class PointInfo
|
|
{
|
|
/// <summary>
|
|
/// 点位名称
|
|
/// </summary>
|
|
public string pointName;
|
|
|
|
/// <summary>
|
|
/// 点位
|
|
/// </summary>
|
|
public Transform point;
|
|
}
|
|
//[Serializable]
|
|
//public class IconInfo
|
|
//{
|
|
// /// <summary>
|
|
// /// 点位名称
|
|
// /// </summary>
|
|
// public string iconsName;
|
|
|
|
// /// <summary>
|
|
// /// 点位
|
|
// /// </summary>
|
|
// public Transform icon;
|
|
//}
|
|
public class Config : MonoBehaviour
|
|
{
|
|
private static Config instance;
|
|
|
|
public static Config Instance => instance;
|
|
|
|
/// <summary>
|
|
/// 场景中主相机
|
|
/// </summary>
|
|
public Transform mainCarema;
|
|
|
|
/// <summary>
|
|
/// 点位
|
|
/// </summary>
|
|
public List<PointInfo> points;
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
//public List<IconInfo> icons;
|
|
/// <summary>
|
|
/// 地点
|
|
/// </summary>
|
|
public GameObject location_tip;
|
|
/// <summary>
|
|
/// 空调
|
|
/// </summary>
|
|
public GameObject cooler_tip;
|
|
/// <summary>
|
|
/// 照明
|
|
/// </summary>
|
|
public GameObject lighting_tip;
|
|
/// <summary>
|
|
/// 排水
|
|
/// </summary>
|
|
public GameObject drainage_tip;
|
|
|
|
public GameObject drainage_Pop;
|
|
public GameObject lighting_Pop;
|
|
|
|
|
|
public GameObject lighting_b1f;
|
|
public GameObject lighting_a1;
|
|
public GameObject lighting_a2;
|
|
public GameObject lighting_a3;
|
|
|
|
/// <summary>
|
|
/// 调取后端路径
|
|
/// </summary>
|
|
public static string configFilePath;
|
|
|
|
/// <summary>
|
|
/// 调取后端接口
|
|
/// </summary>
|
|
public static string config;
|
|
public static string kongtiao;
|
|
public static string IP { get; private set; }
|
|
|
|
|
|
|
|
// 文件名
|
|
public string fileName = "ipConfig.json";
|
|
private void Awake()
|
|
{
|
|
instance = this;
|
|
}
|
|
public string LoginIp { get; private set; }
|
|
private void Start()
|
|
{
|
|
StartCoroutine(LoadFromFile());
|
|
}
|
|
|
|
IEnumerator LoadFromFile()
|
|
{
|
|
string path = System.IO.Path.Combine(Application.streamingAssetsPath, fileName);
|
|
|
|
// 创建请求对象
|
|
UnityWebRequest request = UnityWebRequest.Get(path);
|
|
|
|
// 发送请求并等待完成
|
|
yield return request.SendWebRequest();
|
|
|
|
// 检查请求状态
|
|
if (request.result != UnityWebRequest.Result.Success)
|
|
{
|
|
Debug.Log("Failed to load file: " + request.error);
|
|
}
|
|
else
|
|
{
|
|
// 获取文件内容
|
|
string fileContent = request.downloadHandler.text;
|
|
Debug.Log("File Content: " + fileContent);
|
|
IPConfig config = JsonUtility.FromJson<IPConfig>(fileContent);
|
|
IP = config.loginIp;
|
|
kongtiao = config.kongtiao;
|
|
//Debug.LogError(config.kongtiao);
|
|
Debug.Log(IP);
|
|
}
|
|
}
|
|
|
|
[Serializable]
|
|
public class IPConfig
|
|
{
|
|
public string loginIp;
|
|
public string kongtiao;
|
|
}
|
|
|
|
|
|
}
|