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