NLDClient-yudde/ProjectNLD/Assets/Code/Scripts/GameWrapper/AppConfigDownload.cs

60 lines
1.5 KiB
C#
Raw Normal View History

2024-03-14 15:56:56 +08:00
using UnityEngine;
using UnityEngine.Networking;
2024-09-10 16:38:03 +08:00
using PhxhSDK.AOT.PreConfig;
using Cysharp.Threading.Tasks;
2025-06-17 15:39:11 +08:00
using System;
2024-03-14 15:56:56 +08:00
namespace Gameplay.Net
{
2024-09-10 16:38:03 +08:00
public interface ACDownloadHanlder
2024-03-14 15:56:56 +08:00
{
2024-09-10 16:38:03 +08:00
string URL { get; }
void OnRequestFinished(UnityWebRequest request);
2024-03-14 15:56:56 +08:00
}
2024-09-10 16:38:03 +08:00
public class AppConfigDownload : MonoBehaviour
2024-03-14 15:56:56 +08:00
{
2024-09-10 16:38:03 +08:00
enum LocalStatus
{
None = 0,
Start,
Wait,
Done,
}
2024-03-14 15:56:56 +08:00
2024-09-10 16:38:03 +08:00
ACDownloadHanlder m_handler;
LocalStatus Status;
public void Init(ACDownloadHanlder handler)
2024-03-14 15:56:56 +08:00
{
2024-09-10 16:38:03 +08:00
m_handler = handler;
Status = LocalStatus.Start;
2024-03-14 15:56:56 +08:00
}
2024-09-10 16:38:03 +08:00
void Update()
2024-03-14 15:56:56 +08:00
{
2024-09-10 16:38:03 +08:00
if (Status == LocalStatus.Start)
{
GetRequest().Forget();
Status = LocalStatus.Wait;
}
else if (Status == LocalStatus.Done)
{
Destroy(gameObject);
}
2024-03-14 15:56:56 +08:00
}
2024-09-10 16:38:03 +08:00
async UniTask GetRequest()
2024-03-14 15:56:56 +08:00
{
2024-10-28 16:26:20 +08:00
DebugUtil.Log("Start GetRequest:" + m_handler.URL);
2025-06-17 15:39:11 +08:00
(string AppConfigUrl, string AccessKeyId, string Signature, string Expires) = await PreConfig.instance.GetAppConfigUrl();
using UnityWebRequest webRequest = UnityWebRequest.Get(AppConfigUrl);
2024-03-14 15:56:56 +08:00
// Request and wait for the desired page.
2024-09-10 16:38:03 +08:00
await webRequest.SendWebRequest();
2024-03-14 15:56:56 +08:00
m_handler.OnRequestFinished(webRequest);
Status = LocalStatus.Done;
}
}
}