From 1ab047b5fdd933c38ba0519ec2e83a44512ea8d7 Mon Sep 17 00:00:00 2001
From: yyl <yyl>
Date: 星期四, 26 三月 2026 17:46:11 +0800
Subject: [PATCH] webgl代码合并 1
---
Main/Core/Platform/WeChatPlatform.cs | 440 +++++++++++++++++++++++++++---------------------------
1 files changed, 220 insertions(+), 220 deletions(-)
diff --git a/Main/Core/Platform/WeChatPlatform.cs b/Main/Core/Platform/WeChatPlatform.cs
index 92d2e5b..8a0d8fe 100644
--- a/Main/Core/Platform/WeChatPlatform.cs
+++ b/Main/Core/Platform/WeChatPlatform.cs
@@ -1,256 +1,256 @@
-using System;
-using System.Runtime.InteropServices;
-using Cysharp.Threading.Tasks;
-using UnityEngine;
+// using System;
+// using System.Runtime.InteropServices;
+// using Cysharp.Threading.Tasks;
+// using UnityEngine;
-/// <summary>
-/// 寰俊灏忔父鎴忓钩鍙板疄鐜�
-/// </summary>
-public class WeChatPlatform : IPlatformService
-{
- #if UNITY_WEBGL && !UNITY_EDITOR
- // JavaScript 鎻掍欢鏂规硶澹版槑
- [DllImport("__Internal")]
- private static extern void WX_Init();
+// /// <summary>
+// /// 寰俊灏忔父鎴忓钩鍙板疄鐜�
+// /// </summary>
+// public class WeChatPlatform : IPlatformService
+// {
+// #if UNITY_WEBGL && !UNITY_EDITOR
+// // JavaScript 鎻掍欢鏂规硶澹版槑
+// [DllImport("__Internal")]
+// private static extern void WX_Init();
- [DllImport("__Internal")]
- private static extern void WX_Login(string callbackObjectName, string callbackMethodName);
+// [DllImport("__Internal")]
+// private static extern void WX_Login(string callbackObjectName, string callbackMethodName);
- [DllImport("__Internal")]
- private static extern void WX_GetSystemInfo(string callbackObjectName, string callbackMethodName);
+// [DllImport("__Internal")]
+// private static extern void WX_GetSystemInfo(string callbackObjectName, string callbackMethodName);
- [DllImport("__Internal")]
- private static extern void WX_ShareAppMessage(string title, string imageUrl);
+// [DllImport("__Internal")]
+// private static extern void WX_ShareAppMessage(string title, string imageUrl);
- [DllImport("__Internal")]
- private static extern void WX_CreateRewardedVideoAd(string adUnitId, string callbackObjectName, string callbackMethodName);
+// [DllImport("__Internal")]
+// private static extern void WX_CreateRewardedVideoAd(string adUnitId, string callbackObjectName, string callbackMethodName);
- [DllImport("__Internal")]
- private static extern void WX_SetStorageSync(string key, string value);
+// [DllImport("__Internal")]
+// private static extern void WX_SetStorageSync(string key, string value);
- [DllImport("__Internal")]
- private static extern string WX_GetStorageSync(string key);
+// [DllImport("__Internal")]
+// private static extern string WX_GetStorageSync(string key);
- [DllImport("__Internal")]
- private static extern void WX_VibrateShort();
+// [DllImport("__Internal")]
+// private static extern void WX_VibrateShort();
- [DllImport("__Internal")]
- private static extern void WX_VibrateLong();
- #endif
+// [DllImport("__Internal")]
+// private static extern void WX_VibrateLong();
+// #endif
- private SystemInfo _cachedSystemInfo;
- private bool _isInitialized = false;
+// private SystemInfo _cachedSystemInfo;
+// private bool _isInitialized = false;
- public async UniTask<bool> InitAsync()
- {
- Debug.Log("[WeChatPlatform] 鍒濆鍖栧井淇″皬娓告垙骞冲彴");
+// public async UniTask<bool> InitAsync()
+// {
+// Debug.Log("[WeChatPlatform] 鍒濆鍖栧井淇″皬娓告垙骞冲彴");
- #if UNITY_WEBGL && !UNITY_EDITOR
- try
- {
- WX_Init();
- _isInitialized = true;
- Debug.Log("[WeChatPlatform] 寰俊SDK鍒濆鍖栨垚鍔�");
- }
- catch (Exception e)
- {
- Debug.LogError($"[WeChatPlatform] 寰俊SDK鍒濆鍖栧け璐�: {e.Message}");
- return false;
- }
- #else
- Debug.LogWarning("[WeChatPlatform] 闈濿ebGL骞冲彴锛屼娇鐢ㄦā鎷熸ā寮�");
- _isInitialized = true;
- #endif
+// #if UNITY_WEBGL && !UNITY_EDITOR
+// try
+// {
+// WX_Init();
+// _isInitialized = true;
+// Debug.Log("[WeChatPlatform] 寰俊SDK鍒濆鍖栨垚鍔�");
+// }
+// catch (Exception e)
+// {
+// Debug.LogError($"[WeChatPlatform] 寰俊SDK鍒濆鍖栧け璐�: {e.Message}");
+// return false;
+// }
+// #else
+// Debug.LogWarning("[WeChatPlatform] 闈濿ebGL骞冲彴锛屼娇鐢ㄦā鎷熸ā寮�");
+// _isInitialized = true;
+// #endif
- await UniTask.Delay(100);
- return true;
- }
+// await UniTask.Delay(100);
+// return true;
+// }
- public PlatformType GetPlatformType()
- {
- return PlatformType.WeChat;
- }
+// public PlatformType GetPlatformType()
+// {
+// return PlatformType.WeChat;
+// }
- public async UniTask<LoginResult> LoginAsync()
- {
- Debug.Log("[WeChatPlatform] 寰俊鐧诲綍");
+// public async UniTask<LoginResult> LoginAsync()
+// {
+// Debug.Log("[WeChatPlatform] 寰俊鐧诲綍");
- #if UNITY_WEBGL && !UNITY_EDITOR
- // TODO: 瀹炵幇鍥炶皟鏈哄埗
- // WX_Login("WeChatPlatform", "OnLoginCallback");
- await UniTask.Delay(1000); // 绛夊緟鍥炶皟
- #else
- await UniTask.Delay(500);
- #endif
+// #if UNITY_WEBGL && !UNITY_EDITOR
+// // TODO: 瀹炵幇鍥炶皟鏈哄埗
+// // WX_Login("WeChatPlatform", "OnLoginCallback");
+// await UniTask.Delay(1000); // 绛夊緟鍥炶皟
+// #else
+// await UniTask.Delay(500);
+// #endif
- // 妯℃嫙鐧诲綍鎴愬姛锛堝疄闄呴渶瑕侀�氳繃鍥炶皟鑾峰彇锛�
- return new LoginResult
- {
- Success = true,
- UserId = "wx_user_mock",
- Nickname = "寰俊鐢ㄦ埛",
- AvatarUrl = "https://example.com/avatar.jpg",
- ErrorMessage = null
- };
- }
+// // 妯℃嫙鐧诲綍鎴愬姛锛堝疄闄呴渶瑕侀�氳繃鍥炶皟鑾峰彇锛�
+// return new LoginResult
+// {
+// Success = true,
+// UserId = "wx_user_mock",
+// Nickname = "寰俊鐢ㄦ埛",
+// AvatarUrl = "https://example.com/avatar.jpg",
+// ErrorMessage = null
+// };
+// }
- public async UniTask<bool> ShareAsync(ShareData shareData)
- {
- Debug.Log($"[WeChatPlatform] 鍒嗕韩鍒板井淇�: {shareData.Title}");
+// public async UniTask<bool> ShareAsync(ShareData shareData)
+// {
+// Debug.Log($"[WeChatPlatform] 鍒嗕韩鍒板井淇�: {shareData.Title}");
- #if UNITY_WEBGL && !UNITY_EDITOR
- try
- {
- WX_ShareAppMessage(shareData.Title, shareData.ImageUrl);
- await UniTask.Delay(300);
- return true;
- }
- catch (Exception e)
- {
- Debug.LogError($"[WeChatPlatform] 鍒嗕韩澶辫触: {e.Message}");
- return false;
- }
- #else
- await UniTask.Delay(300);
- return true;
- #endif
- }
+// #if UNITY_WEBGL && !UNITY_EDITOR
+// try
+// {
+// WX_ShareAppMessage(shareData.Title, shareData.ImageUrl);
+// await UniTask.Delay(300);
+// return true;
+// }
+// catch (Exception e)
+// {
+// Debug.LogError($"[WeChatPlatform] 鍒嗕韩澶辫触: {e.Message}");
+// return false;
+// }
+// #else
+// await UniTask.Delay(300);
+// return true;
+// #endif
+// }
- public async UniTask<AdResult> ShowAdAsync(AdType adType)
- {
- Debug.Log($"[WeChatPlatform] 鏄剧ず寰俊骞垮憡: {adType}");
+// public async UniTask<AdResult> ShowAdAsync(AdType adType)
+// {
+// Debug.Log($"[WeChatPlatform] 鏄剧ず寰俊骞垮憡: {adType}");
- #if UNITY_WEBGL && !UNITY_EDITOR
- // TODO: 瀹炵幇骞垮憡鍥炶皟
- string adUnitId = GetAdUnitId(adType);
- // WX_CreateRewardedVideoAd(adUnitId, "WeChatPlatform", "OnAdCallback");
- await UniTask.Delay(3000);
- #else
- await UniTask.Delay(2000);
- #endif
+// #if UNITY_WEBGL && !UNITY_EDITOR
+// // TODO: 瀹炵幇骞垮憡鍥炶皟
+// string adUnitId = GetAdUnitId(adType);
+// // WX_CreateRewardedVideoAd(adUnitId, "WeChatPlatform", "OnAdCallback");
+// await UniTask.Delay(3000);
+// #else
+// await UniTask.Delay(2000);
+// #endif
- return new AdResult
- {
- Success = true,
- Completed = true,
- ErrorMessage = null
- };
- }
+// return new AdResult
+// {
+// Success = true,
+// Completed = true,
+// ErrorMessage = null
+// };
+// }
- public async UniTask<bool> SaveDataAsync(string key, string value)
- {
- Debug.Log($"[WeChatPlatform] 淇濆瓨鏁版嵁鍒板井淇″瓨鍌�: {key}");
+// public async UniTask<bool> SaveDataAsync(string key, string value)
+// {
+// Debug.Log($"[WeChatPlatform] 淇濆瓨鏁版嵁鍒板井淇″瓨鍌�: {key}");
- #if UNITY_WEBGL && !UNITY_EDITOR
- try
- {
- WX_SetStorageSync(key, value);
- await UniTask.Delay(50);
- return true;
- }
- catch (Exception e)
- {
- Debug.LogError($"[WeChatPlatform] 淇濆瓨鏁版嵁澶辫触: {e.Message}");
- return false;
- }
- #else
- await UniTask.Delay(50);
- PlayerPrefs.SetString(key, value);
- PlayerPrefs.Save();
- return true;
- #endif
- }
+// #if UNITY_WEBGL && !UNITY_EDITOR
+// try
+// {
+// WX_SetStorageSync(key, value);
+// await UniTask.Delay(50);
+// return true;
+// }
+// catch (Exception e)
+// {
+// Debug.LogError($"[WeChatPlatform] 淇濆瓨鏁版嵁澶辫触: {e.Message}");
+// return false;
+// }
+// #else
+// await UniTask.Delay(50);
+// PlayerPrefs.SetString(key, value);
+// PlayerPrefs.Save();
+// return true;
+// #endif
+// }
- public async UniTask<string> LoadDataAsync(string key)
- {
- Debug.Log($"[WeChatPlatform] 浠庡井淇″瓨鍌ㄥ姞杞芥暟鎹�: {key}");
+// public async UniTask<string> LoadDataAsync(string key)
+// {
+// Debug.Log($"[WeChatPlatform] 浠庡井淇″瓨鍌ㄥ姞杞芥暟鎹�: {key}");
- #if UNITY_WEBGL && !UNITY_EDITOR
- try
- {
- await UniTask.Delay(50);
- return WX_GetStorageSync(key);
- }
- catch (Exception e)
- {
- Debug.LogError($"[WeChatPlatform] 鍔犺浇鏁版嵁澶辫触: {e.Message}");
- return null;
- }
- #else
- await UniTask.Delay(50);
- return PlayerPrefs.GetString(key, null);
- #endif
- }
+// #if UNITY_WEBGL && !UNITY_EDITOR
+// try
+// {
+// await UniTask.Delay(50);
+// return WX_GetStorageSync(key);
+// }
+// catch (Exception e)
+// {
+// Debug.LogError($"[WeChatPlatform] 鍔犺浇鏁版嵁澶辫触: {e.Message}");
+// return null;
+// }
+// #else
+// await UniTask.Delay(50);
+// return PlayerPrefs.GetString(key, null);
+// #endif
+// }
- public async UniTask<string> DownloadFileAsync(string url, string localPath, Action<float> onProgress = null)
- {
- Debug.Log($"[WeChatPlatform] 涓嬭浇鏂囦欢: {url}");
+// public async UniTask<string> DownloadFileAsync(string url, string localPath, Action<float> onProgress = null)
+// {
+// Debug.Log($"[WeChatPlatform] 涓嬭浇鏂囦欢: {url}");
- // TODO: 瀹炵幇寰俊鏂囦欢涓嬭浇API
- // wx.downloadFile({ url, success, fail })
+// // TODO: 瀹炵幇寰俊鏂囦欢涓嬭浇API
+// // wx.downloadFile({ url, success, fail })
- // 妯℃嫙涓嬭浇
- for (int i = 0; i <= 10; i++)
- {
- await UniTask.Delay(100);
- onProgress?.Invoke(i / 10f);
- }
+// // 妯℃嫙涓嬭浇
+// for (int i = 0; i <= 10; i++)
+// {
+// await UniTask.Delay(100);
+// onProgress?.Invoke(i / 10f);
+// }
- return localPath;
- }
+// return localPath;
+// }
- public SystemInfo GetSystemInfo()
- {
- if (_cachedSystemInfo == null)
- {
- #if UNITY_WEBGL && !UNITY_EDITOR
- // TODO: 浠庡井淇PI鑾峰彇绯荤粺淇℃伅
- // WX_GetSystemInfo("WeChatPlatform", "OnSystemInfoCallback");
- #endif
+// public SystemInfo GetSystemInfo()
+// {
+// if (_cachedSystemInfo == null)
+// {
+// #if UNITY_WEBGL && !UNITY_EDITOR
+// // TODO: 浠庡井淇PI鑾峰彇绯荤粺淇℃伅
+// // WX_GetSystemInfo("WeChatPlatform", "OnSystemInfoCallback");
+// #endif
- _cachedSystemInfo = new SystemInfo
- {
- DeviceModel = UnityEngine.SystemInfo.deviceModel,
- SystemVersion = UnityEngine.SystemInfo.operatingSystem,
- PlatformVersion = "WeChat 8.0.0",
- ScreenWidth = Screen.width,
- ScreenHeight = Screen.height,
- SafeArea = SafeAreaData.FromRect(Screen.safeArea),
- PixelRatio = Screen.dpi / 160f
- };
- }
+// _cachedSystemInfo = new SystemInfo
+// {
+// DeviceModel = UnityEngine.SystemInfo.deviceModel,
+// SystemVersion = UnityEngine.SystemInfo.operatingSystem,
+// PlatformVersion = "WeChat 8.0.0",
+// ScreenWidth = Screen.width,
+// ScreenHeight = Screen.height,
+// SafeArea = SafeAreaData.FromRect(Screen.safeArea),
+// PixelRatio = Screen.dpi / 160f
+// };
+// }
- return _cachedSystemInfo;
- }
+// return _cachedSystemInfo;
+// }
- public void Vibrate(VibrationType vibrationType)
- {
- Debug.Log($"[WeChatPlatform] 闇囧姩: {vibrationType}");
+// public void Vibrate(VibrationType vibrationType)
+// {
+// Debug.Log($"[WeChatPlatform] 闇囧姩: {vibrationType}");
- #if UNITY_WEBGL && !UNITY_EDITOR
- try
- {
- if (vibrationType == VibrationType.Heavy)
- WX_VibrateLong();
- else
- WX_VibrateShort();
- }
- catch (Exception e)
- {
- Debug.LogError($"[WeChatPlatform] 闇囧姩澶辫触: {e.Message}");
- }
- #endif
- }
+// #if UNITY_WEBGL && !UNITY_EDITOR
+// try
+// {
+// if (vibrationType == VibrationType.Heavy)
+// WX_VibrateLong();
+// else
+// WX_VibrateShort();
+// }
+// catch (Exception e)
+// {
+// Debug.LogError($"[WeChatPlatform] 闇囧姩澶辫触: {e.Message}");
+// }
+// #endif
+// }
- private string GetAdUnitId(AdType adType)
- {
- // TODO: 浠庨厤缃枃浠惰鍙栧箍鍛婁綅ID
- return adType switch
- {
- AdType.Video => "adunit-xxxxxx",
- AdType.Banner => "adunit-yyyyyy",
- AdType.Interstitial => "adunit-zzzzzz",
- _ => ""
- };
- }
- }
+// private string GetAdUnitId(AdType adType)
+// {
+// // TODO: 浠庨厤缃枃浠惰鍙栧箍鍛婁綅ID
+// return adType switch
+// {
+// AdType.Video => "adunit-xxxxxx",
+// AdType.Banner => "adunit-yyyyyy",
+// AdType.Interstitial => "adunit-zzzzzz",
+// _ => ""
+// };
+// }
+// }
--
Gitblit v1.8.0