using System;
using Cysharp.Threading.Tasks;
using UnityEngine;
///
/// 编辑器测试平台实现(模拟平台行为)
///
public class StandalonePlatform : IPlatformService
{
private SystemInfo _cachedSystemInfo;
public async UniTask InitAsync()
{
Debug.Log("[StandalonePlatform] 初始化编辑器测试平台");
await UniTask.Delay(100); // 模拟初始化延迟
_cachedSystemInfo = CreateMockSystemInfo();
return true;
}
public PlatformType GetPlatformType()
{
return PlatformType.Standalone;
}
public async UniTask LoginAsync()
{
Debug.Log("[StandalonePlatform] 模拟登录成功");
await UniTask.Delay(500); // 模拟网络延迟
return new LoginResult
{
Success = true,
UserId = "test_user_12345",
Nickname = "测试用户",
AvatarUrl = "https://example.com/avatar.jpg",
ErrorMessage = null
};
}
public async UniTask ShareAsync(ShareData shareData)
{
Debug.Log($"[StandalonePlatform] 模拟分享: {shareData.Title}");
await UniTask.Delay(300);
return true;
}
public async UniTask ShowAdAsync(AdType adType)
{
Debug.Log($"[StandalonePlatform] 模拟显示广告: {adType}");
await UniTask.Delay(2000); // 模拟广告播放时间
return new AdResult
{
Success = true,
Completed = true, // 模拟用户看完广告
ErrorMessage = null
};
}
public async UniTask SaveDataAsync(string key, string value)
{
Debug.Log($"[StandalonePlatform] 保存数据: {key} = {value}");
await UniTask.Delay(50);
PlayerPrefs.SetString(key, value);
PlayerPrefs.Save();
return true;
}
public async UniTask LoadDataAsync(string key)
{
Debug.Log($"[StandalonePlatform] 加载数据: {key}");
await UniTask.Delay(50);
return PlayerPrefs.GetString(key, null);
}
public async UniTask DownloadFileAsync(string url, string localPath, Action onProgress = null)
{
Debug.Log($"[StandalonePlatform] 模拟下载文件: {url} -> {localPath}");
// 模拟下载进度
for (int i = 0; i <= 10; i++)
{
await UniTask.Delay(100);
onProgress?.Invoke(i / 10f);
}
return localPath;
}
public SystemInfo GetSystemInfo()
{
return _cachedSystemInfo ?? (_cachedSystemInfo = CreateMockSystemInfo());
}
public void Vibrate(VibrationType vibrationType)
{
Debug.Log($"[StandalonePlatform] 模拟震动: {vibrationType}");
// 编辑器中无法实际震动
}
private SystemInfo CreateMockSystemInfo()
{
return new SystemInfo
{
DeviceModel = UnityEngine.SystemInfo.deviceModel,
SystemVersion = UnityEngine.SystemInfo.operatingSystem,
PlatformVersion = "Standalone 1.0.0",
ScreenWidth = Screen.width,
ScreenHeight = Screen.height,
SafeArea = SafeAreaData.FromRect(Screen.safeArea),
PixelRatio = Screen.dpi / 160f
};
}
}