This commit is contained in:
2026-06-02 11:39:30 +08:00
parent 8088a70820
commit a6509ea9ee
3 changed files with 49 additions and 16 deletions

View File

@@ -23,8 +23,29 @@ namespace Stary.Evo
#else
authorization = CustomPlayerPrefs.GetString("Authorization");
#endif
}
private static async UniTask GetCertificateData()
{
var certPath = Path.Combine(Application.streamingAssetsPath, "server.crt");
certificateData = File.ReadAllBytes(certPath);
if (certificateData == null)
{
#if UNITY_ANDROID && !UNITY_EDITOR
// Android平台使用UnityWebRequest读取
var webRequest = UnityWebRequest.Get(certPath);
await webRequest.SendWebRequest();
if (webRequest.result == UnityWebRequest.Result.Success)
{
certificateData = webRequest.downloadHandler.data;
}
#else
// 其他平台使用File读取
if (File.Exists(certPath))
{
certificateData = File.ReadAllBytes(certPath);
}
#endif
}
}
public static async Task<bool> Login(string url, string username, string password)
@@ -222,6 +243,7 @@ namespace Stary.Evo
{
try
{
await GetCertificateData();
using var webRequest = UnityWebRequest.Get(url);
webRequest.downloadHandler = new DownloadHandlerFile(tempPath);
webRequest.certificateHandler = new SelfSignedCertHandler(certificateData);
@@ -282,6 +304,7 @@ namespace Stary.Evo
{
try
{
await GetCertificateData();
var fullUrl = url.TrimEnd('/') + "/" + path.TrimStart('/');
using var webRequest = new UnityWebRequest(fullUrl, UnityWebRequest.kHttpVerbGET);
webRequest.downloadHandler = new DownloadHandlerBuffer();
@@ -517,6 +540,7 @@ namespace Stary.Evo
MainPanel.UsersItem host,
List<MainPanel.UsersItem> participants)
{
await GetCertificateData();
var bytes = File.ReadAllBytes(filePath);
var fileName = Path.GetFileName(filePath);
@@ -544,5 +568,6 @@ namespace Stary.Evo
else
Debug.Log($"上传成功: {request.downloadHandler.text}");
}
}
}