Files
plugin-library/Assets/00.BuildOriginality/Runtime/ArtLoadAssetServer.cs
zhangzheng 42161fa127 111
2025-12-16 17:21:46 +08:00

108 lines
3.7 KiB
C#

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Newtonsoft.Json;
using UnityEngine;
namespace Stary.Evo
{
public static class ArtLoadAssetServer
{
public static string ip;
static ArtLoadAssetServer()
{
//初始化读取资源配置表
HotfixMainResDomain hotfixMainResDomain =
Resources.Load<HotfixMainResDomain>("HotfixMainResDomain");
if (hotfixMainResDomain == null)
{
Debug.LogError($"UnityEvo:读取资源配置表失败【HotfixMainResDomain】...表不存在");
}
ip = hotfixMainResDomain.hotfixMainResDomainEntity.ipconfig;
}
/// <summary>
/// 获取服务器全部作用域
/// </summary>
public async static Task<string[]> GetServerDomainAllName()
{
var serverDomainEntities = await GetServerDomainAll();
if (serverDomainEntities == null)
{
Debug.LogError($"UnityEvo:获取服务器全部作用域失败...服务器返回空");
return null;
}
List<string> domains = new List<string>();
for (int i = 0; i < serverDomainEntities.Count; i++)
{
if (serverDomainEntities[i].IsEnable)
{
domains.Add(serverDomainEntities[i].DomainName);
}
}
return domains.ToArray();
}
/// <summary>
/// 获取全部作用域
/// </summary>
public static async Task<List<ResDmainResponse>> GetServerDomainAll()
{
//初始化读取资源配置表
HotfixMainResDomain hotfixMainResDomain =
Resources.Load<HotfixMainResDomain>("HotfixMainResDomain");
if (hotfixMainResDomain == null)
{
Debug.LogError($"UnityEvo:读取资源配置表失败【HotfixMainResDomain】...表不存在");
return null;
}
ip = hotfixMainResDomain.hotfixMainResDomainEntity.ipconfig;
//登录
string loginurl = ip + "/Authentication/login";
await WebRequestSystem.Login(loginurl, hotfixMainResDomain.hotfixMainResDomainEntity.username,
hotfixMainResDomain.hotfixMainResDomainEntity.password);
string url = $"{ip}/ResDomain/GetResDomainAll";
var resDmainRequst = new ResProductRequst()
{
ProductName = Application.identifier,
#if UNITY_EDITOR
Platform = UnityEditor.EditorUserBuildSettings.activeBuildTarget.ToString()
#else
Platform = Application.platform.ToString()
#endif
};
//获取服务器版本
var resDmainMessageEntity =
await WebRequestSystem.Post(url, JsonConvert.SerializeObject(resDmainRequst));
if (resDmainMessageEntity.code == 200)
{
List<ResDmainResponse> resDmainResponse =
JsonConvert.DeserializeObject<List<ResDmainResponse>>(resDmainMessageEntity.data.ToString());
ResDmainResponse mainDmainResponse = default;
for (int i = 0; i < resDmainResponse.Count; i++)
{
if (resDmainResponse[i].DomainName == "Main")
{
mainDmainResponse = resDmainResponse[i];
}
}
if (mainDmainResponse.DomainName == "Main")
{
resDmainResponse.Remove(mainDmainResponse);
}
return resDmainResponse;
}
return null;
}
}
}