95 lines
2.9 KiB
C#
95 lines
2.9 KiB
C#
using UnityEngine;
|
||
|
||
namespace Zion.ERP.Inventory
|
||
{
|
||
/// <summary>
|
||
/// API配置ScriptableObject,用于在Unity编辑器中配置API接口
|
||
/// </summary>
|
||
[CreateAssetMenu(fileName = "ApiConfig", menuName = "配置/API接口配置")]
|
||
public class ApiConfig : ScriptableObject
|
||
{
|
||
/// <summary>
|
||
/// API配置数据
|
||
/// </summary>
|
||
public ApiConfigData ConfigData = new ApiConfigData();
|
||
|
||
/// <summary>
|
||
/// 配置文件路径(用于运行时加载)
|
||
/// </summary>
|
||
[Header("配置文件路径")]
|
||
public string JsonConfigPath = "DataConfig/api_config.json";
|
||
|
||
/// <summary>
|
||
/// 是否使用JSON配置文件(运行时)
|
||
/// </summary>
|
||
[Header("运行时配置")]
|
||
public bool UseJsonConfig = true;
|
||
|
||
/// <summary>
|
||
/// 是否启用配置热重载
|
||
/// </summary>
|
||
public bool EnableHotReload = false;
|
||
|
||
/// <summary>
|
||
/// 热重载检查间隔(秒)
|
||
/// </summary>
|
||
public float HotReloadInterval = 30f;
|
||
|
||
/// <summary>
|
||
/// 获取当前环境的基础URL
|
||
/// </summary>
|
||
/// <returns>基础URL</returns>
|
||
public string GetCurrentBaseUrl()
|
||
{
|
||
var envConfig = ConfigData.GetCurrentEnvironmentConfig();
|
||
return envConfig?.BaseUrl ?? "";
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取API接口URL
|
||
/// </summary>
|
||
/// <param name="endpointName">接口名称</param>
|
||
/// <param name="dynamicParams">动态参数</param>
|
||
/// <returns>完整的URL</returns>
|
||
public string GetApiUrl(string endpointName, System.Collections.Generic.Dictionary<string, string> dynamicParams = null)
|
||
{
|
||
var endpoint = ConfigData.GetEndpoint(endpointName);
|
||
if (endpoint == null)
|
||
{
|
||
Debug.LogError($"未找到API接口配置:{endpointName}");
|
||
return "";
|
||
}
|
||
|
||
var baseUrl = GetCurrentBaseUrl();
|
||
return endpoint.GetFullUrl(baseUrl, dynamicParams);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取API接口配置
|
||
/// </summary>
|
||
/// <param name="endpointName">接口名称</param>
|
||
/// <returns>API接口配置</returns>
|
||
public ApiEndpoint GetEndpoint(string endpointName)
|
||
{
|
||
return ConfigData.GetEndpoint(endpointName);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 验证配置
|
||
/// </summary>
|
||
/// <returns>验证结果</returns>
|
||
public bool Validate()
|
||
{
|
||
return ConfigData.Validate();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 创建默认配置(已废弃,请使用JSON配置文件)
|
||
/// </summary>
|
||
public void CreateDefaultConfig()
|
||
{
|
||
Debug.LogWarning("CreateDefaultConfig方法已废弃,请使用JSON配置文件进行配置");
|
||
ConfigData = new ApiConfigData();
|
||
}
|
||
}
|
||
} |