diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json new file mode 100644 index 000000000..155e42522 --- /dev/null +++ b/.config/dotnet-tools.json @@ -0,0 +1,13 @@ +{ + "version": 1, + "isRoot": true, + "tools": { + "csharpier": { + "version": "0.28.2", + "commands": [ + "dotnet-csharpier" + ], + "rollForward": false + } + } +} \ No newline at end of file diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 000000000..565e4e313 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,34 @@ +# Remove the line below if you want to inherit .editorconfig settings from higher directories +root = true + +#### Core EditorConfig Options #### + +[*] +# Indentation and spacing: https://github.com/editorconfig/editorconfig/wiki/EditorConfig-Properties +indent_style = space +indent_size = 4 +end_of_line = crlf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = false + +# C# files +[*.cs] +# C# formatting options: https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/csharp-formatting-options +csharp_new_line_before_open_brace = all +csharp_new_line_before_else = true +csharp_new_line_before_catch = true +csharp_new_line_before_finally = true +csharp_new_line_before_members_in_object_initializers = true +csharp_new_line_before_members_in_anonymous_types = true +csharp_new_line_between_query_expression_clauses = true + +#### .NET Coding Conventions #### + +# this. and Me. preferences +dotnet_style_qualification_for_method = true + +#### Diagnostic configuration #### + +# CA1000: Do not declare static members on generic types +dotnet_diagnostic.CA1000.severity = warning \ No newline at end of file diff --git a/Demo/API_V2/Assets/API/Ad/AdWithAudio/AdWithAudio.cs b/Demo/API_V2/Assets/API/Ad/AdWithAudio/AdWithAudio.cs index 0bef1961c..b5e37cbb3 100644 --- a/Demo/API_V2/Assets/API/Ad/AdWithAudio/AdWithAudio.cs +++ b/Demo/API_V2/Assets/API/Ad/AdWithAudio/AdWithAudio.cs @@ -1,37 +1,37 @@ -using UnityEngine; -using WeChatWASM; -using UnityEngine.UI; -using UnityEngine.Networking; using System; using System.Collections; using System.Collections.Generic; - +using UnityEngine; using UnityEngine.Audio; using UnityEngine.Networking; +using UnityEngine.Networking; +using UnityEngine.UI; +using WeChatWASM; public class AdWithAudio : Details { - private WXRewardedVideoAd _rewardedVideoAd; public AudioSource audioSource; public AudioClip audioClipCDN; - + private void Start() { StartCoroutine(LoadCDNAudio()); - // 创建激励视频广告组件 - _rewardedVideoAd = WX.CreateRewardedVideoAd(new WXCreateRewardedVideoAdParam() + _rewardedVideoAd = WX.CreateRewardedVideoAd( + new WXCreateRewardedVideoAdParam() + { + // adUnitId 请填写自己的广告位 ID + adUnitId = "adunit-881d549c5a14a7e3" + } + ); + + _rewardedVideoAd.OnError(err => { - // adUnitId 请填写自己的广告位 ID - adUnitId = "adunit-881d549c5a14a7e3" - }); - - _rewardedVideoAd.OnError(err => { Debug.Log(JsonUtility.ToJson(err)); }); - + GameManager.Instance.detailsController.BindExtraButtonAction(0, PlayCDN); } @@ -49,7 +49,8 @@ IEnumerator LoadCDNAudio() // 添加 AudioSource 组件 audioSource = newGameObject.AddComponent(); - string uriString = "https://res.wx.qq.com/wechatgame/product/webpack/userupload/20220901/211827/CallMeTeenTop.mp3"; + string uriString = + "https://res.wx.qq.com/wechatgame/product/webpack/userupload/20220901/211827/CallMeTeenTop.mp3"; Uri uri = new Uri(uriString); UnityWebRequest request = UnityWebRequestMultimedia.GetAudioClip(uri, AudioType.MPEG); yield return request.SendWebRequest(); @@ -78,25 +79,35 @@ public void PlayCDN() // 展示广告 private void ShowAd() { - _rewardedVideoAd.Show(res => { - Debug.Log("Show success"); - Debug.Log(JsonUtility.ToJson(res)); - }, err => { - Debug.Log(JsonUtility.ToJson(err)); - _rewardedVideoAd.Load(res => { - Debug.Log("load success"); - _rewardedVideoAd.Show(); - }, err => { - Debug.Log("load fail"); + _rewardedVideoAd.Show( + res => + { + Debug.Log("Show success"); + Debug.Log(JsonUtility.ToJson(res)); + }, + err => + { Debug.Log(JsonUtility.ToJson(err)); - }); - }); + _rewardedVideoAd.Load( + res => + { + Debug.Log("load success"); + _rewardedVideoAd.Show(); + }, + err => + { + Debug.Log("load fail"); + Debug.Log(JsonUtility.ToJson(err)); + } + ); + } + ); } - public void Destroy() { - if (audioSource != null) { + if (audioSource != null) + { audioSource.clip = null; audioSource = null; } diff --git a/Demo/API_V2/Assets/API/Ad/BannerAd/BannerAd.cs b/Demo/API_V2/Assets/API/Ad/BannerAd/BannerAd.cs index da47e4591..d74f07f11 100644 --- a/Demo/API_V2/Assets/API/Ad/BannerAd/BannerAd.cs +++ b/Demo/API_V2/Assets/API/Ad/BannerAd/BannerAd.cs @@ -1,12 +1,12 @@ -using UnityEngine; +using UnityEngine; using WeChatWASM; public class BannerAd : Details { private WXBannerAd _bannerAd; - + private bool _isShow = false; - + private void Start() { // 绑定按钮事件 @@ -21,33 +21,42 @@ protected override void TestAPI(string[] args) // adUnitId 请填写自己的广告位 ID // 创建预设的 Banner 广告 _bannerAd = WX.CreateFixedBottomMiddleBannerAd("adunit-xxxxxxxxxxxxxxxx", 30, 200); - - _bannerAd.OnLoad((res) => - { - WX.ShowModal(new ShowModalOption() + + _bannerAd.OnLoad( + (res) => { - content = "BannerAd OnLoad Result:" + JsonUtility.ToJson(res) - }); - }); - _bannerAd.OnError((res) => - { - WX.ShowModal(new ShowModalOption() + WX.ShowModal( + new ShowModalOption() + { + content = "BannerAd OnLoad Result:" + JsonUtility.ToJson(res) + } + ); + } + ); + _bannerAd.OnError( + (res) => { - content = "BannerAd onError Result:" + JsonUtility.ToJson(res) - }); - }); - _bannerAd.OnResize((res) => - { - WX.ShowModal(new ShowModalOption() + WX.ShowModal( + new ShowModalOption() + { + content = "BannerAd onError Result:" + JsonUtility.ToJson(res) + } + ); + } + ); + _bannerAd.OnResize( + (res) => { - content = "BannerAd onResize Result:" + JsonUtility.ToJson(res) - }); - }); - - WX.ShowToast(new ShowToastOption() - { - title = "已创建广告" - }); + WX.ShowModal( + new ShowModalOption() + { + content = "BannerAd onResize Result:" + JsonUtility.ToJson(res) + } + ); + } + ); + + WX.ShowToast(new ShowToastOption() { title = "已创建广告" }); } // 切换广告显示状态 @@ -57,19 +66,13 @@ private void SwitchAdState() { // 隐藏广告 _bannerAd.Hide(); - WX.ShowToast(new ShowToastOption() - { - title = "已隐藏广告" - }); + WX.ShowToast(new ShowToastOption() { title = "已隐藏广告" }); } else { // 展示广告 _bannerAd.Show(); - WX.ShowToast(new ShowToastOption() - { - title = "已展示广告" - }); + WX.ShowToast(new ShowToastOption() { title = "已展示广告" }); } } @@ -77,10 +80,7 @@ private void SwitchAdState() private void DestroyAd() { _bannerAd.Destroy(); - WX.ShowToast(new ShowToastOption() - { - title = "已销毁广告" - }); + WX.ShowToast(new ShowToastOption() { title = "已销毁广告" }); } private void OnDestroy() diff --git a/Demo/API_V2/Assets/API/Ad/CustomAd/CustomAd.cs b/Demo/API_V2/Assets/API/Ad/CustomAd/CustomAd.cs index f2a50a302..125be8750 100644 --- a/Demo/API_V2/Assets/API/Ad/CustomAd/CustomAd.cs +++ b/Demo/API_V2/Assets/API/Ad/CustomAd/CustomAd.cs @@ -1,4 +1,4 @@ -using UnityEngine; +using UnityEngine; using WeChatWASM; public class CustomAd : Details @@ -7,7 +7,7 @@ public class CustomAd : Details // SDK未支持CustomAd.IsShow()接口,使用自定义变量记录广告显示状态 private bool _isShow; - + private void Start() { // 绑定按钮事件 @@ -19,43 +19,44 @@ private void Start() protected override void TestAPI(string[] args) { // 创建原生模板广告组件 - _customAd = WX.CreateCustomAd(new WXCreateCustomAdParam() - { - // adUnitId 请填写自己的广告位 ID - adUnitId = "adunit-xxxxxxxxxxxxxxxx", - adIntervals = 30, - style = { - left = 0, - top = 100, - }, - }); - _customAd.OnLoad((res) => - { - WX.ShowModal(new ShowModalOption() + _customAd = WX.CreateCustomAd( + new WXCreateCustomAdParam() { - content = "CustomAd OnLoad Result:" + JsonUtility.ToJson(res) - }); - }); - _customAd.OnError((res) => - { - WX.ShowModal(new ShowModalOption() + // adUnitId 请填写自己的广告位 ID + adUnitId = "adunit-xxxxxxxxxxxxxxxx", + adIntervals = 30, + style = { left = 0, top = 100, }, + } + ); + _customAd.OnLoad( + (res) => { - content = "CustomAd onError Result:" + JsonUtility.ToJson(res) - }); - }); + WX.ShowModal( + new ShowModalOption() + { + content = "CustomAd OnLoad Result:" + JsonUtility.ToJson(res) + } + ); + } + ); + _customAd.OnError( + (res) => + { + WX.ShowModal( + new ShowModalOption() + { + content = "CustomAd onError Result:" + JsonUtility.ToJson(res) + } + ); + } + ); _customAd.OnHide(() => { - WX.ShowModal(new ShowModalOption() - { - content = "CustomAd onHide" - }); + WX.ShowModal(new ShowModalOption() { content = "CustomAd onHide" }); }); _customAd.OnClose(() => { - WX.ShowModal(new ShowModalOption() - { - content = "CustomAd onClose" - }); + WX.ShowModal(new ShowModalOption() { content = "CustomAd onClose" }); }); } @@ -66,19 +67,13 @@ private void SwitchAdState() { // 隐藏广告 _customAd.Hide(); - WX.ShowToast(new ShowToastOption() - { - title = "已隐藏广告" - }); + WX.ShowToast(new ShowToastOption() { title = "已隐藏广告" }); } else { // 展示广告 _customAd.Show(); - WX.ShowToast(new ShowToastOption() - { - title = "已展示广告" - }); + WX.ShowToast(new ShowToastOption() { title = "已展示广告" }); } } @@ -86,10 +81,7 @@ private void SwitchAdState() private void DestroyAd() { _customAd.Destroy(); - WX.ShowToast(new ShowToastOption() - { - title = "已销毁广告" - }); + WX.ShowToast(new ShowToastOption() { title = "已销毁广告" }); } private void OnDestroy() diff --git a/Demo/API_V2/Assets/API/Ad/InterstitalAd/InterstitalAd.cs b/Demo/API_V2/Assets/API/Ad/InterstitalAd/InterstitalAd.cs index 148a35821..47434157d 100644 --- a/Demo/API_V2/Assets/API/Ad/InterstitalAd/InterstitalAd.cs +++ b/Demo/API_V2/Assets/API/Ad/InterstitalAd/InterstitalAd.cs @@ -1,10 +1,10 @@ -using UnityEngine; +using UnityEngine; using WeChatWASM; public class InterstitalAd : Details { private WXInterstitialAd _interstitialAd; - + private void Start() { // 绑定按钮事件 @@ -16,60 +16,58 @@ private void Start() protected override void TestAPI(string[] args) { // 创建插屏广告 - _interstitialAd = WX.CreateInterstitialAd(new WXCreateInterstitialAdParam() - { - // adUnitId 请填写自己的广告位 ID - adUnitId = "adunit-xxxxxxxxxxxxxxxx" - }); - - _interstitialAd.OnLoad((res) => - { - WX.ShowModal(new ShowModalOption() + _interstitialAd = WX.CreateInterstitialAd( + new WXCreateInterstitialAdParam() { - content = "RewardedVideoAd OnLoad Result:" + JsonUtility.ToJson(res) - }); - }); - _interstitialAd.OnError((res) => - { - WX.ShowModal(new ShowModalOption() + // adUnitId 请填写自己的广告位 ID + adUnitId = "adunit-xxxxxxxxxxxxxxxx" + } + ); + + _interstitialAd.OnLoad( + (res) => { - content = "RewardedVideoAd onError Result:" + JsonUtility.ToJson(res) - }); - }); + WX.ShowModal( + new ShowModalOption() + { + content = "RewardedVideoAd OnLoad Result:" + JsonUtility.ToJson(res) + } + ); + } + ); + _interstitialAd.OnError( + (res) => + { + WX.ShowModal( + new ShowModalOption() + { + content = "RewardedVideoAd onError Result:" + JsonUtility.ToJson(res) + } + ); + } + ); _interstitialAd.OnClose(() => { - WX.ShowModal(new ShowModalOption() - { - content = "RewardedVideoAd onClose" - }); + WX.ShowModal(new ShowModalOption() { content = "RewardedVideoAd onClose" }); }); // 预加载广告 _interstitialAd.Load(); - - WX.ShowToast(new ShowToastOption() - { - title = "已创建并加载广告" - }); + + WX.ShowToast(new ShowToastOption() { title = "已创建并加载广告" }); } // 展示广告 private void ShowAd() { _interstitialAd.Show(); - WX.ShowToast(new ShowToastOption() - { - title = "已展示广告" - }); + WX.ShowToast(new ShowToastOption() { title = "已展示广告" }); } - + // 销毁广告 private void DestroyAd() { _interstitialAd.Destroy(); - WX.ShowToast(new ShowToastOption() - { - title = "已销毁广告" - }); + WX.ShowToast(new ShowToastOption() { title = "已销毁广告" }); } private void OnDestroy() diff --git a/Demo/API_V2/Assets/API/Ad/RewardedVideoAd/RewardedVideoAd.cs b/Demo/API_V2/Assets/API/Ad/RewardedVideoAd/RewardedVideoAd.cs index 69500e0bc..4191d8731 100644 --- a/Demo/API_V2/Assets/API/Ad/RewardedVideoAd/RewardedVideoAd.cs +++ b/Demo/API_V2/Assets/API/Ad/RewardedVideoAd/RewardedVideoAd.cs @@ -1,10 +1,10 @@ -using UnityEngine; +using UnityEngine; using WeChatWASM; public class RewardedVideoAd : Details { private WXRewardedVideoAd _rewardedVideoAd; - + private void Start() { // 绑定按钮事件 @@ -16,60 +16,65 @@ private void Start() protected override void TestAPI(string[] args) { // 创建激励视频广告组件 - _rewardedVideoAd = WX.CreateRewardedVideoAd(new WXCreateRewardedVideoAdParam() - { - // adUnitId 请填写自己的广告位 ID - adUnitId = "adunit-xxxxxxxxxxxxxxxx" - }); - - _rewardedVideoAd.OnLoad((res) => - { - WX.ShowModal(new ShowModalOption() + _rewardedVideoAd = WX.CreateRewardedVideoAd( + new WXCreateRewardedVideoAdParam() + { + // adUnitId 请填写自己的广告位 ID + adUnitId = "adunit-xxxxxxxxxxxxxxxx" + } + ); + + _rewardedVideoAd.OnLoad( + (res) => { - content = "RewardedVideoAd OnLoad Result:" + JsonUtility.ToJson(res) - }); - }); - _rewardedVideoAd.OnError((res) => - { - WX.ShowModal(new ShowModalOption() + WX.ShowModal( + new ShowModalOption() + { + content = "RewardedVideoAd OnLoad Result:" + JsonUtility.ToJson(res) + } + ); + } + ); + _rewardedVideoAd.OnError( + (res) => { - content = "RewardedVideoAd onError Result:" + JsonUtility.ToJson(res) - }); - }); - _rewardedVideoAd.OnClose((res) => - { - WX.ShowModal(new ShowModalOption() + WX.ShowModal( + new ShowModalOption() + { + content = "RewardedVideoAd onError Result:" + JsonUtility.ToJson(res) + } + ); + } + ); + _rewardedVideoAd.OnClose( + (res) => { - content = "RewardedVideoAd onClose Result:" + JsonUtility.ToJson(res) - }); - }); + WX.ShowModal( + new ShowModalOption() + { + content = "RewardedVideoAd onClose Result:" + JsonUtility.ToJson(res) + } + ); + } + ); // 预加载广告 _rewardedVideoAd.Load(); - - WX.ShowToast(new ShowToastOption() - { - title = "已创建并加载广告" - }); + + WX.ShowToast(new ShowToastOption() { title = "已创建并加载广告" }); } // 展示广告 private void ShowAd() { _rewardedVideoAd.Show(); - WX.ShowToast(new ShowToastOption() - { - title = "已展示广告" - }); + WX.ShowToast(new ShowToastOption() { title = "已展示广告" }); } - + // 销毁广告 private void DestroyAd() { _rewardedVideoAd.Destroy(); - WX.ShowToast(new ShowToastOption() - { - title = "已销毁广告" - }); + WX.ShowToast(new ShowToastOption() { title = "已销毁广告" }); } private void OnDestroy() diff --git a/Demo/API_V2/Assets/API/Audio/AudioManager.cs b/Demo/API_V2/Assets/API/Audio/AudioManager.cs index 8685bb298..a60930727 100644 --- a/Demo/API_V2/Assets/API/Audio/AudioManager.cs +++ b/Demo/API_V2/Assets/API/Audio/AudioManager.cs @@ -1,5 +1,6 @@ using UnityEngine; using UnityEngine.Networking; + public class AudioManager : MonoBehaviour { public AudioSource AudioSource; @@ -46,4 +47,4 @@ public void playDelayed() AudioSource.loop = true; AudioSource.PlayDelayed(3); } -} \ No newline at end of file +} diff --git a/Demo/API_V2/Assets/API/Base/Error/Error.cs b/Demo/API_V2/Assets/API/Base/Error/Error.cs index 26f0af074..8f2c7f798 100644 --- a/Demo/API_V2/Assets/API/Base/Error/Error.cs +++ b/Demo/API_V2/Assets/API/Base/Error/Error.cs @@ -2,62 +2,66 @@ using LitJson; using UnityEngine; using WeChatWASM; + public class Error : Details { - private bool _isListening = false; - private readonly Action _onUnhandledRejection = (res) => { + private readonly Action _onUnhandledRejection = (res) => + { var result = "onUnhandledRejection\n" + JsonMapper.ToJson(res); - GameManager.Instance.detailsController.AddResult(new ResultData() - { - initialContentText = result - }); + GameManager.Instance.detailsController.AddResult( + new ResultData() { initialContentText = result } + ); }; - private readonly Action _onError = (res) => { + private readonly Action _onError = (res) => + { var result = "onError\n" + JsonMapper.ToJson(res); - GameManager.Instance.detailsController.AddResult(new ResultData() - { - initialContentText = result - }); + GameManager.Instance.detailsController.AddResult( + new ResultData() { initialContentText = result } + ); }; - private readonly Action _onAudioInterruptionEnd = (res) => { + private readonly Action _onAudioInterruptionEnd = (res) => + { var result = "onAudioInterruptionEnd\n" + JsonMapper.ToJson(res); - GameManager.Instance.detailsController.AddResult(new ResultData() - { - initialContentText = result - }); + GameManager.Instance.detailsController.AddResult( + new ResultData() { initialContentText = result } + ); }; - private readonly Action _onAudioInterruptionBegin = (res) => { + private readonly Action _onAudioInterruptionBegin = (res) => + { var result = "onAudioInterruptionBegin\n" + JsonMapper.ToJson(res); - GameManager.Instance.detailsController.AddResult(new ResultData() - { - initialContentText = result - }); + GameManager.Instance.detailsController.AddResult( + new ResultData() { initialContentText = result } + ); }; // 测试 API protected override void TestAPI(string[] args) { - if (!_isListening) { + if (!_isListening) + { WX.OnUnhandledRejection(_onUnhandledRejection); WX.OnError(_onError); WX.OnAudioInterruptionEnd(_onAudioInterruptionEnd); WX.OnAudioInterruptionBegin(_onAudioInterruptionBegin); - } else { + } + else + { WX.OffUnhandledRejection(_onUnhandledRejection); WX.OffError(_onError); WX.OffAudioInterruptionEnd(_onAudioInterruptionEnd); WX.OffAudioInterruptionBegin(_onAudioInterruptionBegin); } _isListening = !_isListening; - GameManager.Instance.detailsController.ChangeInitialButtonText(_isListening ? "取消监听" : "开始监听"); + GameManager.Instance.detailsController.ChangeInitialButtonText( + _isListening ? "取消监听" : "开始监听" + ); } - private void OnDestroy() { WX.OffUnhandledRejection(_onUnhandledRejection); diff --git a/Demo/API_V2/Assets/API/Base/Get/GetInfo.cs b/Demo/API_V2/Assets/API/Base/Get/GetInfo.cs index e03748536..54e75aeef 100644 --- a/Demo/API_V2/Assets/API/Base/Get/GetInfo.cs +++ b/Demo/API_V2/Assets/API/Base/Get/GetInfo.cs @@ -3,6 +3,7 @@ using LitJson; using UnityEngine; using WeChatWASM; + public class GetInfo : Details { private void Start() @@ -18,6 +19,7 @@ private void Start() GameManager.Instance.detailsController.BindExtraButtonAction(7, getLaunchOptionsSync); GameManager.Instance.detailsController.BindExtraButtonAction(8, getEnterOptionsSync); } + // 测试 API protected override void TestAPI(string[] args) { @@ -29,10 +31,9 @@ public void getWindowInfo() var res = WX.GetWindowInfo(); // 访问成功,显示结果 - WX.ShowModal(new ShowModalOption() - { - content = "Access Success, Result: " + JsonMapper.ToJson(res) - }); + WX.ShowModal( + new ShowModalOption() { content = "Access Success, Result: " + JsonMapper.ToJson(res) } + ); } public void getSystemSetting() @@ -40,10 +41,9 @@ public void getSystemSetting() var res = WX.GetSystemSetting(); // 访问成功,显示结果 - WX.ShowModal(new ShowModalOption() - { - content = "Access Success, Result: " + JsonMapper.ToJson(res) - }); + WX.ShowModal( + new ShowModalOption() { content = "Access Success, Result: " + JsonMapper.ToJson(res) } + ); } public void getSystemInfoSync() @@ -51,21 +51,24 @@ public void getSystemInfoSync() var res = WX.GetSystemInfoSync(); // 访问成功,显示结果 - WX.ShowModal(new ShowModalOption() - { - content = "Access Success, Result: " + JsonMapper.ToJson(res) - }); + WX.ShowModal( + new ShowModalOption() { content = "Access Success, Result: " + JsonMapper.ToJson(res) } + ); } - public void getSystemInfoAsync() { - WX.GetSystemInfoAsync(new GetSystemInfoAsyncOption + public void getSystemInfoAsync() + { + WX.GetSystemInfoAsync( + new GetSystemInfoAsyncOption { - success = (res) => + success = (res) => { - WX.ShowModal(new ShowModalOption() - { - content = "Access Success, Result: " + JsonMapper.ToJson(res) - }); + WX.ShowModal( + new ShowModalOption() + { + content = "Access Success, Result: " + JsonMapper.ToJson(res) + } + ); }, fail = (res) => { @@ -79,16 +82,19 @@ public void getSystemInfoAsync() { ); } - public void getSystemInfo() + public void getSystemInfo() { - WX.GetSystemInfo(new GetSystemInfoOption + WX.GetSystemInfo( + new GetSystemInfoOption { - success = (res) => + success = (res) => { - WX.ShowModal(new ShowModalOption() - { - content = "Access Success, Result: " + JsonMapper.ToJson(res) - }); + WX.ShowModal( + new ShowModalOption() + { + content = "Access Success, Result: " + JsonMapper.ToJson(res) + } + ); }, fail = (res) => { @@ -102,37 +108,34 @@ public void getSystemInfo() ); } - public void getDeviceInfo() + public void getDeviceInfo() { var res = WX.GetDeviceInfo(); // 访问成功,显示结果 - WX.ShowModal(new ShowModalOption() - { - content = "Access Success, Result: " + JsonMapper.ToJson(res) - }); + WX.ShowModal( + new ShowModalOption() { content = "Access Success, Result: " + JsonMapper.ToJson(res) } + ); } - public void getAppBaseInfo() + public void getAppBaseInfo() { var res = WX.GetAppBaseInfo(); // 访问成功,显示结果 - WX.ShowModal(new ShowModalOption() - { - content = "Access Success, Result: " + JsonMapper.ToJson(res) - }); + WX.ShowModal( + new ShowModalOption() { content = "Access Success, Result: " + JsonMapper.ToJson(res) } + ); } - public void getAppAuthorizeSetting() + public void getAppAuthorizeSetting() { var res = WX.GetAppAuthorizeSetting(); // 访问成功,显示结果 - WX.ShowModal(new ShowModalOption() - { - content = "Access Success, Result: " + JsonMapper.ToJson(res) - }); + WX.ShowModal( + new ShowModalOption() { content = "Access Success, Result: " + JsonMapper.ToJson(res) } + ); } public void getEnterOptionsSync() @@ -140,10 +143,9 @@ public void getEnterOptionsSync() var res = WX.GetEnterOptionsSync(); // 访问成功,显示结果 - WX.ShowModal(new ShowModalOption() - { - content = "Access Success, Result: " + JsonMapper.ToJson(res) - }); + WX.ShowModal( + new ShowModalOption() { content = "Access Success, Result: " + JsonMapper.ToJson(res) } + ); } public void getLaunchOptionsSync() @@ -151,9 +153,8 @@ public void getLaunchOptionsSync() var res = WX.GetLaunchOptionsSync(); // 访问成功,显示结果 - WX.ShowModal(new ShowModalOption() - { - content = "Access Success, Result: " + JsonMapper.ToJson(res) - }); + WX.ShowModal( + new ShowModalOption() { content = "Access Success, Result: " + JsonMapper.ToJson(res) } + ); } } diff --git a/Demo/API_V2/Assets/API/Base/LifeCycle/LifeCycle.cs b/Demo/API_V2/Assets/API/Base/LifeCycle/LifeCycle.cs index 322414af5..932e63af7 100644 --- a/Demo/API_V2/Assets/API/Base/LifeCycle/LifeCycle.cs +++ b/Demo/API_V2/Assets/API/Base/LifeCycle/LifeCycle.cs @@ -3,43 +3,49 @@ using LitJson; using UnityEngine; using WeChatWASM; + public class LifeCycle : Details { - private bool _isListening = false; - private readonly Action _onShow = (res) => { + private readonly Action _onShow = (res) => + { var result = "onShow\n" + JsonMapper.ToJson(res); - GameManager.Instance.detailsController.AddResult(new ResultData() - { - initialContentText = result - }); + GameManager.Instance.detailsController.AddResult( + new ResultData() { initialContentText = result } + ); }; - private readonly Action _onHide = (res) => { + private readonly Action _onHide = (res) => + { var result = "onHide\n" + JsonMapper.ToJson(res); - GameManager.Instance.detailsController.AddResult(new ResultData() - { - initialContentText = result - }); + GameManager.Instance.detailsController.AddResult( + new ResultData() { initialContentText = result } + ); }; // 测试 API protected override void TestAPI(string[] args) { - if (!_isListening) { + if (!_isListening) + { WX.OnShow(_onShow); WX.OnHide(_onHide); - } else { + } + else + { WX.OffShow(_onShow); WX.OffHide(_onHide); } _isListening = !_isListening; - GameManager.Instance.detailsController.ChangeInitialButtonText(_isListening ? "取消监听" : "开始监听"); + GameManager.Instance.detailsController.ChangeInitialButtonText( + _isListening ? "取消监听" : "开始监听" + ); } - private void OnDestroy() { - WX.OffShow(_onShow); - WX.OffHide(_onHide); + private void OnDestroy() + { + WX.OffShow(_onShow); + WX.OffHide(_onHide); } } diff --git a/Demo/API_V2/Assets/API/Base/Open/Open.cs b/Demo/API_V2/Assets/API/Base/Open/Open.cs index 6c77dceeb..df5bb6ae9 100644 --- a/Demo/API_V2/Assets/API/Base/Open/Open.cs +++ b/Demo/API_V2/Assets/API/Base/Open/Open.cs @@ -3,6 +3,7 @@ using LitJson; using UnityEngine; using WeChatWASM; + public class Open : Details { private void Start() @@ -19,39 +20,43 @@ protected override void TestAPI(string[] args) public void openSystemBluetoothSetting() { - WX.OpenSystemBluetoothSetting(new OpenSystemBluetoothSettingOption - { - success = (res) => - { - Debug.Log("success!"); - }, - fail = (res) => - { - Debug.Log("fail:" + res.errMsg); - }, - complete = (res) => + WX.OpenSystemBluetoothSetting( + new OpenSystemBluetoothSettingOption { - Debug.Log("complete!"); + success = (res) => + { + Debug.Log("success!"); + }, + fail = (res) => + { + Debug.Log("fail:" + res.errMsg); + }, + complete = (res) => + { + Debug.Log("complete!"); + } } - }); + ); } public void openAppAuthorizeSetting() { - WX.OpenAppAuthorizeSetting(new OpenAppAuthorizeSettingOption - { - success = (res) => - { - Debug.Log("success!"); - }, - fail = (res) => - { - Debug.Log("fail:" + res.errMsg); - }, - complete = (res) => + WX.OpenAppAuthorizeSetting( + new OpenAppAuthorizeSettingOption { - Debug.Log("complete!"); + success = (res) => + { + Debug.Log("success!"); + }, + fail = (res) => + { + Debug.Log("fail:" + res.errMsg); + }, + complete = (res) => + { + Debug.Log("complete!"); + } } - }); + ); } } diff --git a/Demo/API_V2/Assets/API/Base/Performance/Performance.cs b/Demo/API_V2/Assets/API/Base/Performance/Performance.cs index a85120922..e565ece05 100644 --- a/Demo/API_V2/Assets/API/Base/Performance/Performance.cs +++ b/Demo/API_V2/Assets/API/Base/Performance/Performance.cs @@ -3,6 +3,7 @@ using LitJson; using UnityEngine; using WeChatWASM; + public class Performance : Details { private void Start() @@ -17,23 +18,15 @@ protected override void TestAPI(string[] args) triggerGC(); } - public void triggerGC() + public void triggerGC() { WX.TriggerGC(); - WX.ShowToast(new ShowToastOption() - { - title = "成功调用triggerGC" - }); + WX.ShowToast(new ShowToastOption() { title = "成功调用triggerGC" }); } - public void reportPerformance() + public void reportPerformance() { WX.ReportPerformance(1101, 6880, "custom"); - WX.ShowToast(new ShowToastOption() - { - title = "成功上报" - }); + WX.ShowToast(new ShowToastOption() { title = "成功上报" }); } - - } diff --git a/Demo/API_V2/Assets/API/Base/RealtimeLog/RealtimeLog.cs b/Demo/API_V2/Assets/API/Base/RealtimeLog/RealtimeLog.cs index ce20c2d48..469746d76 100644 --- a/Demo/API_V2/Assets/API/Base/RealtimeLog/RealtimeLog.cs +++ b/Demo/API_V2/Assets/API/Base/RealtimeLog/RealtimeLog.cs @@ -8,7 +8,7 @@ public class RealtimeLog : Details { private WXRealtimeLogManager _log; - private void Start() + private void Start() { _log = WX.GetRealtimeLogManager(); _log.AddFilterMsg("test"); @@ -23,11 +23,13 @@ protected override void TestAPI(string[] args) _log.Info("info msg"); } - private void error() { + private void error() + { _log.Error("error msg"); } - private void warn() { + private void warn() + { _log.Warn("warn msg"); } } diff --git a/Demo/API_V2/Assets/API/Base/Update/Update.cs b/Demo/API_V2/Assets/API/Base/Update/Update.cs index 698c02072..dd6e5771e 100644 --- a/Demo/API_V2/Assets/API/Base/Update/Update.cs +++ b/Demo/API_V2/Assets/API/Base/Update/Update.cs @@ -3,6 +3,7 @@ using LitJson; using UnityEngine; using WeChatWASM; + public class Update : Details { private WXUpdateManager _updateManager; @@ -21,50 +22,65 @@ protected override void TestAPI(string[] args) public void updateWeChatApp() { - WX.UpdateWeChatApp(new UpdateWeChatAppOption - { - success = (res) => - { - Debug.Log("success!"); - }, - fail = (res) => - { - Debug.Log("fail:" + res.errMsg); - }, - complete = (res) => + WX.UpdateWeChatApp( + new UpdateWeChatAppOption { - Debug.Log("complete!"); + success = (res) => + { + Debug.Log("success!"); + }, + fail = (res) => + { + Debug.Log("fail:" + res.errMsg); + }, + complete = (res) => + { + Debug.Log("complete!"); + } } - }); + ); } - public void updateManagerDemo() + public void updateManagerDemo() { _updateManager = WX.GetUpdateManager(); - _updateManager.OnCheckForUpdate((res) => { - // 请求完新版本信息的回调 - Debug.Log("Isupdate: " + res.hasUpdate); - }); + _updateManager.OnCheckForUpdate( + (res) => + { + // 请求完新版本信息的回调 + Debug.Log("Isupdate: " + res.hasUpdate); + } + ); - _updateManager.OnUpdateReady((r) => { - Debug.Log("ready" + r); - WX.ShowModal(new ShowModalOption + _updateManager.OnUpdateReady( + (r) => { - title = "更新提示", - content = "新版本已经准备好,是否重启应用?", - success = (res) => { - if (res.confirm) { - // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启 - _updateManager.ApplyUpdate(); + Debug.Log("ready" + r); + WX.ShowModal( + new ShowModalOption + { + title = "更新提示", + content = "新版本已经准备好,是否重启应用?", + success = (res) => + { + if (res.confirm) + { + // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启 + _updateManager.ApplyUpdate(); + } + } } - } - }); - }); + ); + } + ); - _updateManager.OnUpdateFailed((res) => { - // 新版本下载失败 - Debug.Log("fail" + res); - }); + _updateManager.OnUpdateFailed( + (res) => + { + // 新版本下载失败 + Debug.Log("fail" + res); + } + ); } } diff --git a/Demo/API_V2/Assets/API/Chat/ChatManager/ChatManager.cs b/Demo/API_V2/Assets/API/Chat/ChatManager/ChatManager.cs index 6baab9cfc..50a461ecd 100644 --- a/Demo/API_V2/Assets/API/Chat/ChatManager/ChatManager.cs +++ b/Demo/API_V2/Assets/API/Chat/ChatManager/ChatManager.cs @@ -1,5 +1,4 @@ using UnityEngine; - using WeChatWASM; public class ChatManager : Details @@ -9,7 +8,7 @@ public class ChatManager : Details private void Start() { CreateChat(); - + // 绑定额外的按钮操作 GameManager.Instance.detailsController.BindExtraButtonAction(0, Hide); GameManager.Instance.detailsController.BindExtraButtonAction(1, Open); @@ -19,7 +18,7 @@ private void Start() // 测试 API protected override void TestAPI(string[] args) { - Show(); + Show(); } private void CreateChat() @@ -30,7 +29,7 @@ private void CreateChat() Debug.Log("已创建"); return; } - + WxChat = WX.CreateMiniGameChat(); if (WxChat == null) @@ -40,48 +39,69 @@ private void CreateChat() return; } - WxChat.On("ready", (res) => - { - Debug.Log("wxChat ready"); - SetTabs(); - }); - - WxChat.On("show", (res) => - { - Debug.Log("wxChat show"); - }); - - WxChat.On("hide", (res) => - { - Debug.Log("wxChat hide"); - }); - - WxChat.On("open", (res) => - { - Debug.Log("wxChat open"); - }); - - WxChat.On("close", (res) => - { - Debug.Log("wxChat close"); - }); - - WxChat.On("interact", (res) => - { - Debug.Log("wxChat interact"); - Debug.Log(JsonUtility.ToJson(res)); - - // TODO 处理互动消息 - }); - - WxChat.On("authorize", (res) => - { - Debug.Log("wxChat authorize"); - Debug.Log(JsonUtility.ToJson(res)); - - // TODO 传rawData给后台,后台计算出signature后设置 - WxChat.SetChatSignature("test signature"); - }); + WxChat.On( + "ready", + (res) => + { + Debug.Log("wxChat ready"); + SetTabs(); + } + ); + + WxChat.On( + "show", + (res) => + { + Debug.Log("wxChat show"); + } + ); + + WxChat.On( + "hide", + (res) => + { + Debug.Log("wxChat hide"); + } + ); + + WxChat.On( + "open", + (res) => + { + Debug.Log("wxChat open"); + } + ); + + WxChat.On( + "close", + (res) => + { + Debug.Log("wxChat close"); + } + ); + + WxChat.On( + "interact", + (res) => + { + Debug.Log("wxChat interact"); + Debug.Log(JsonUtility.ToJson(res)); + + // TODO 处理互动消息 + } + ); + + WxChat.On( + "authorize", + (res) => + { + Debug.Log("wxChat authorize"); + Debug.Log(JsonUtility.ToJson(res)); + + // TODO 传rawData给后台,后台计算出signature后设置 + WxChat.SetChatSignature("test signature"); + } + ); } public void Show() @@ -116,7 +136,7 @@ public void Open() } } - public void Close() + public void Close() { if (WxChat != null) { diff --git a/Demo/API_V2/Assets/API/DataStorage/Storage/Storage.cs b/Demo/API_V2/Assets/API/DataStorage/Storage/Storage.cs index 5f59fe4e8..88d023d99 100644 --- a/Demo/API_V2/Assets/API/DataStorage/Storage/Storage.cs +++ b/Demo/API_V2/Assets/API/DataStorage/Storage/Storage.cs @@ -1,7 +1,8 @@ +using System; using LitJson; using UnityEngine; using WeChatWASM; -using System; + // 缓存数据类型 [System.Serializable] public class Data @@ -12,12 +13,12 @@ public class Data public class Storage : Details { - private readonly Action _onBackgroundFetchData = (res) => { + private readonly Action _onBackgroundFetchData = (res) => + { var result = "onBackgroundFetchData\n" + JsonMapper.ToJson(res); - GameManager.Instance.detailsController.AddResult(new ResultData() - { - initialContentText = result - }); + GameManager.Instance.detailsController.AddResult( + new ResultData() { initialContentText = result } + ); }; private void Start() @@ -25,7 +26,6 @@ private void Start() // 监听收到 backgroundFetch 数据事件。 WX.OnBackgroundFetchData(_onBackgroundFetchData); - GameManager.Instance.detailsController.BindExtraButtonAction(0, getStorage); GameManager.Instance.detailsController.BindExtraButtonAction(1, removeStorage); GameManager.Instance.detailsController.BindExtraButtonAction(2, removeStorageSync); @@ -42,137 +42,139 @@ protected override void TestAPI(string[] args) setStorageSync(); } - public void setStorageSync() { - var d = new Data { - data1 = "test", - data2 = 1 - }; + public void setStorageSync() + { + var d = new Data { data1 = "test", data2 = 1 }; PlayerPrefs.SetString("test1", JsonUtility.ToJson(d)); PlayerPrefs.Save(); - WX.ShowToast(new ShowToastOption - { - title = "设置成功" - }); + WX.ShowToast(new ShowToastOption { title = "设置成功" }); } - - public void removeStorageSync() { + public void removeStorageSync() + { WX.RemoveStorageSync("test1"); - WX.ShowToast(new ShowToastOption - { - title = "删除test1成功" - }); + WX.ShowToast(new ShowToastOption { title = "删除test1成功" }); } - public void removeStorage() { - WX.RemoveStorage(new RemoveStorageOption - { - key = "test2", - success = (res) => { - WX.ShowToast(new ShowToastOption + public void removeStorage() + { + WX.RemoveStorage( + new RemoveStorageOption + { + key = "test2", + success = (res) => + { + WX.ShowToast(new ShowToastOption { title = "删除test2成功" }); + }, + fail = (res) => + { + Debug.Log("fail: " + res.errMsg); + }, + complete = (res) => { - title = "删除test2成功" - }); - }, - fail = (res) => { - Debug.Log("fail: " + res.errMsg); - }, - complete = (res) => { - Debug.Log("complete"); + Debug.Log("complete"); + } } - }); + ); } - public void getStorageInfoSync() { - GetStorageInfoSyncOption res = WX.GetStorageInfoSync(); - WX.ShowModal(new ShowModalOption - { - content = JsonMapper.ToJson(res) - }); + public void getStorageInfoSync() + { + GetStorageInfoSyncOption res = WX.GetStorageInfoSync(); + WX.ShowModal(new ShowModalOption { content = JsonMapper.ToJson(res) }); } - public void getStorageInfo() { - WX.GetStorageInfo(new GetStorageInfoOption - { - success = (res) => { - WX.ShowModal(new ShowModalOption + public void getStorageInfo() + { + WX.GetStorageInfo( + new GetStorageInfoOption + { + success = (res) => + { + WX.ShowModal(new ShowModalOption { content = JsonMapper.ToJson(res) }); + }, + fail = (res) => { - content = JsonMapper.ToJson(res) - }); - }, - fail = (res) => { - Debug.Log("fail: " + res.errMsg); - }, - complete = (res) => { - Debug.Log("complete"); + Debug.Log("fail: " + res.errMsg); + }, + complete = (res) => + { + Debug.Log("complete"); + } } - }); + ); } - public void getStorage() { + public void getStorage() + { var res = PlayerPrefs.GetString("test1"); Debug.Log("playerperfs: " + res); - - WX.ShowModal(new ShowModalOption - { - content = res - }); + + WX.ShowModal(new ShowModalOption { content = res }); } - public void setBackgroundFetchToken() { - WX.SetBackgroundFetchToken(new SetBackgroundFetchTokenOption - { - token = "abcdefghijklmn", - success = (res) => { - WX.ShowToast(new ShowToastOption + public void setBackgroundFetchToken() + { + WX.SetBackgroundFetchToken( + new SetBackgroundFetchTokenOption + { + token = "abcdefghijklmn", + success = (res) => { - title = "设置成功" - }); - }, - fail = (res) => { - Debug.Log("fail: " + res.errMsg); - }, - complete = (res) => { - Debug.Log("complete"); + WX.ShowToast(new ShowToastOption { title = "设置成功" }); + }, + fail = (res) => + { + Debug.Log("fail: " + res.errMsg); + }, + complete = (res) => + { + Debug.Log("complete"); + } } - }); + ); } - public void getBackgroundFetchToken() { - WX.GetBackgroundFetchToken(new GetBackgroundFetchTokenOption - { - success = (res) => { - WX.ShowModal(new ShowModalOption + public void getBackgroundFetchToken() + { + WX.GetBackgroundFetchToken( + new GetBackgroundFetchTokenOption + { + success = (res) => { - content = JsonMapper.ToJson(res) - }); - }, - fail = (res) => { - Debug.Log("fail: " + res.errMsg); - }, - complete = (res) => { - Debug.Log("complete"); + WX.ShowModal(new ShowModalOption { content = JsonMapper.ToJson(res) }); + }, + fail = (res) => + { + Debug.Log("fail: " + res.errMsg); + }, + complete = (res) => + { + Debug.Log("complete"); + } } - }); + ); } - public void getBackgroundFetchData() { - WX.GetBackgroundFetchData(new GetBackgroundFetchDataOption - { - fetchType = "pre", - success = (res) => { - WX.ShowModal(new ShowModalOption + public void getBackgroundFetchData() + { + WX.GetBackgroundFetchData( + new GetBackgroundFetchDataOption + { + fetchType = "pre", + success = (res) => { - content = JsonMapper.ToJson(res) - }); - }, - fail = (res) => { - Debug.Log("fail: " + res.errMsg); - }, - complete = (res) => { - Debug.Log("complete"); + WX.ShowModal(new ShowModalOption { content = JsonMapper.ToJson(res) }); + }, + fail = (res) => + { + Debug.Log("fail: " + res.errMsg); + }, + complete = (res) => + { + Debug.Log("complete"); + } } - }); + ); } } - diff --git a/Demo/API_V2/Assets/API/Facility/BLE/BLE.cs b/Demo/API_V2/Assets/API/Facility/BLE/BLE.cs index 9fee84325..1e6080aef 100644 --- a/Demo/API_V2/Assets/API/Facility/BLE/BLE.cs +++ b/Demo/API_V2/Assets/API/Facility/BLE/BLE.cs @@ -3,35 +3,36 @@ using LitJson; using UnityEngine; using WeChatWASM; + public class BLE : Details { - private bool _isListening = false; - private readonly Action _onBLEMTUChange = (res) => { + private readonly Action _onBLEMTUChange = (res) => + { var result = "onBLEMTUChange\n" + JsonMapper.ToJson(res); - GameManager.Instance.detailsController.AddResult(new ResultData() - { - initialContentText = result - }); + GameManager.Instance.detailsController.AddResult( + new ResultData() { initialContentText = result } + ); }; - private readonly Action _onBLEConnectionStateChange = (res) => { - var result = "onBLEConnectionStateChange\n" + JsonMapper.ToJson(res); - GameManager.Instance.detailsController.AddResult(new ResultData() + private readonly Action _onBLEConnectionStateChange = + (res) => { - initialContentText = result - }); - }; + var result = "onBLEConnectionStateChange\n" + JsonMapper.ToJson(res); + GameManager.Instance.detailsController.AddResult( + new ResultData() { initialContentText = result } + ); + }; - private readonly Action _onBLECharacteristicValueChange = (res) => { - var result = "onBLECharacteristicValueChange\n" + JsonMapper.ToJson(res); - GameManager.Instance.detailsController.AddResult(new ResultData() + private readonly Action _onBLECharacteristicValueChange = + (res) => { - initialContentText = result - }); - }; - + var result = "onBLECharacteristicValueChange\n" + JsonMapper.ToJson(res); + GameManager.Instance.detailsController.AddResult( + new ResultData() { initialContentText = result } + ); + }; private void Start() { @@ -44,14 +45,23 @@ private void Start() // 监听蓝牙低功耗设备的特征值变化事件。 WX.OnBLECharacteristicValueChange(_onBLECharacteristicValueChange); - GameManager.Instance.detailsController.BindExtraButtonAction(0, writeBLECharacteristicValue); + GameManager.Instance.detailsController.BindExtraButtonAction( + 0, + writeBLECharacteristicValue + ); GameManager.Instance.detailsController.BindExtraButtonAction(1, setBLEMTU); GameManager.Instance.detailsController.BindExtraButtonAction(2, readBLECharacteristicValue); - GameManager.Instance.detailsController.BindExtraButtonAction(3, notifyBLECharacteristicValueChange); + GameManager.Instance.detailsController.BindExtraButtonAction( + 3, + notifyBLECharacteristicValueChange + ); GameManager.Instance.detailsController.BindExtraButtonAction(4, getBLEMTU); GameManager.Instance.detailsController.BindExtraButtonAction(5, getBLEDeviceServices); GameManager.Instance.detailsController.BindExtraButtonAction(6, getBLEDeviceRSSI); - GameManager.Instance.detailsController.BindExtraButtonAction(7, getBLEDeviceCharacteristics); + GameManager.Instance.detailsController.BindExtraButtonAction( + 7, + getBLEDeviceCharacteristics + ); } // 测试 API @@ -60,184 +70,249 @@ protected override void TestAPI(string[] args) createBLEConnection(); } - public void createBLEConnection() { - if (!_isListening) { - WX.CreateBLEConnection(new CreateBLEConnectionOption + public void createBLEConnection() + { + if (!_isListening) + { + WX.CreateBLEConnection( + new CreateBLEConnectionOption + { + deviceId = "xxx", + timeout = 20000, + success = (res) => + { + Debug.Log("success " + JsonMapper.ToJson(res)); + }, + fail = (res) => + { + Debug.Log("fail" + res.errMsg); + }, + complete = (res) => + { + Debug.Log("complete"); + } + } + ); + } + else + { + WX.CloseBLEConnection( + new CloseBLEConnectionOption + { + deviceId = "xxx", + success = (res) => + { + Debug.Log("success " + JsonMapper.ToJson(res)); + }, + fail = (res) => + { + Debug.Log("fail" + res.errMsg); + }, + complete = (res) => + { + Debug.Log("complete"); + } + } + ); + } + _isListening = !_isListening; + GameManager.Instance.detailsController.ChangeInitialButtonText( + _isListening ? "断开连接" : "开始连接" + ); + } + + // 目前会报param.value类型错误,已知问题,等待修复 + public void writeBLECharacteristicValue() + { + WX.WriteBLECharacteristicValue( + new WriteBLECharacteristicValueOption { deviceId = "xxx", - timeout = 20000, - success = (res) => { + serviceId = "xxx", + characteristicId = "xxx", + value = new byte[] { 1, 2, 3 }, + success = (res) => + { Debug.Log("success " + JsonMapper.ToJson(res)); }, - fail = (res) => { + fail = (res) => + { Debug.Log("fail" + res.errMsg); }, - complete = (res) => { + complete = (res) => + { Debug.Log("complete"); } - }); - } else { - WX.CloseBLEConnection(new CloseBLEConnectionOption + } + ); + } + + public void setBLEMTU() + { + WX.SetBLEMTU( + new SetBLEMTUOption { - deviceId = "xxx", - success = (res) => { + deviceId = "xx", + mtu = 100, + success = (res) => + { Debug.Log("success " + JsonMapper.ToJson(res)); }, - fail = (res) => { - Debug.Log("fail" + res.errMsg); + fail = (res) => + { + Debug.Log("fail" + res.mtu); }, - complete = (res) => { + complete = (res) => + { Debug.Log("complete"); } - }); - } - _isListening = !_isListening; - GameManager.Instance.detailsController.ChangeInitialButtonText(_isListening ? "断开连接" : "开始连接"); - } - - // 目前会报param.value类型错误,已知问题,等待修复 - public void writeBLECharacteristicValue() { - WX.WriteBLECharacteristicValue(new WriteBLECharacteristicValueOption - { - deviceId = "xxx", - serviceId = "xxx", - characteristicId = "xxx", - value = new byte[] {1, 2, 3}, - success = (res) => { - Debug.Log("success " + JsonMapper.ToJson(res)); - }, - fail = (res) => { - Debug.Log("fail" + res.errMsg); - }, - complete = (res) => { - Debug.Log("complete"); - } - }); - } - - public void setBLEMTU() { - WX.SetBLEMTU(new SetBLEMTUOption - { - deviceId = "xx", - mtu = 100, - success = (res) => { - Debug.Log("success " + JsonMapper.ToJson(res)); - }, - fail = (res) => { - Debug.Log("fail" + res.mtu); - }, - complete = (res) => { - Debug.Log("complete"); } - }); + ); } - public void readBLECharacteristicValue() { - WX.ReadBLECharacteristicValue(new ReadBLECharacteristicValueOption - { - deviceId = "xx", - serviceId = "xx", - characteristicId = "xx", - success = (res) => { - Debug.Log("success " + JsonMapper.ToJson(res)); - }, - fail = (res) => { - Debug.Log("fail" + res.errMsg); - }, - complete = (res) => { - Debug.Log("complete"); + public void readBLECharacteristicValue() + { + WX.ReadBLECharacteristicValue( + new ReadBLECharacteristicValueOption + { + deviceId = "xx", + serviceId = "xx", + characteristicId = "xx", + success = (res) => + { + Debug.Log("success " + JsonMapper.ToJson(res)); + }, + fail = (res) => + { + Debug.Log("fail" + res.errMsg); + }, + complete = (res) => + { + Debug.Log("complete"); + } } - }); + ); } - public void notifyBLECharacteristicValueChange() { - WX.NotifyBLECharacteristicValueChange(new NotifyBLECharacteristicValueChangeOption { - deviceId = "xx", - serviceId = "xx", - characteristicId = "xx", - state = true, - type = "indication", - success = (res) => { - Debug.Log("success " + JsonMapper.ToJson(res)); - }, - fail = (res) => { - Debug.Log("fail" + res.errMsg); - }, - complete = (res) => { - Debug.Log("complete"); + public void notifyBLECharacteristicValueChange() + { + WX.NotifyBLECharacteristicValueChange( + new NotifyBLECharacteristicValueChangeOption + { + deviceId = "xx", + serviceId = "xx", + characteristicId = "xx", + state = true, + type = "indication", + success = (res) => + { + Debug.Log("success " + JsonMapper.ToJson(res)); + }, + fail = (res) => + { + Debug.Log("fail" + res.errMsg); + }, + complete = (res) => + { + Debug.Log("complete"); + } } - }); + ); } - public void getBLEMTU() { - WX.GetBLEMTU(new GetBLEMTUOption - { - deviceId = "xx", - success = (res) => { - Debug.Log("success " + JsonMapper.ToJson(res)); - }, - fail = (res) => { - Debug.Log("fail" + res.errMsg); - }, - complete = (res) => { - Debug.Log("complete"); + public void getBLEMTU() + { + WX.GetBLEMTU( + new GetBLEMTUOption + { + deviceId = "xx", + success = (res) => + { + Debug.Log("success " + JsonMapper.ToJson(res)); + }, + fail = (res) => + { + Debug.Log("fail" + res.errMsg); + }, + complete = (res) => + { + Debug.Log("complete"); + } } - }); + ); } - public void getBLEDeviceServices() { - WX.GetBLEDeviceServices(new GetBLEDeviceServicesOption - { - deviceId = "xx", - success = (res) => { - Debug.Log("success " + JsonMapper.ToJson(res)); - }, - fail = (res) => { - Debug.Log("fail" + res.errMsg); - }, - complete = (res) => { - Debug.Log("complete"); + public void getBLEDeviceServices() + { + WX.GetBLEDeviceServices( + new GetBLEDeviceServicesOption + { + deviceId = "xx", + success = (res) => + { + Debug.Log("success " + JsonMapper.ToJson(res)); + }, + fail = (res) => + { + Debug.Log("fail" + res.errMsg); + }, + complete = (res) => + { + Debug.Log("complete"); + } } - }); + ); } - public void getBLEDeviceRSSI() { - WX.GetBLEDeviceRSSI(new GetBLEDeviceRSSIOption - { - deviceId = "xx", - success = (res) => { - Debug.Log("success " + JsonMapper.ToJson(res)); - }, - fail = (res) => { - Debug.Log("fail" + res.errMsg); - }, - complete = (res) => { - Debug.Log("complete"); + public void getBLEDeviceRSSI() + { + WX.GetBLEDeviceRSSI( + new GetBLEDeviceRSSIOption + { + deviceId = "xx", + success = (res) => + { + Debug.Log("success " + JsonMapper.ToJson(res)); + }, + fail = (res) => + { + Debug.Log("fail" + res.errMsg); + }, + complete = (res) => + { + Debug.Log("complete"); + } } - }); + ); } - public void getBLEDeviceCharacteristics() { - WX.GetBLEDeviceCharacteristics(new GetBLEDeviceCharacteristicsOption - { - deviceId = "xx", - serviceId = "xx", - success = (res) => { - Debug.Log("success " + JsonMapper.ToJson(res)); - }, - fail = (res) => { - Debug.Log("fail" + res.errMsg); - }, - complete = (res) => { - Debug.Log("complete"); + public void getBLEDeviceCharacteristics() + { + WX.GetBLEDeviceCharacteristics( + new GetBLEDeviceCharacteristicsOption + { + deviceId = "xx", + serviceId = "xx", + success = (res) => + { + Debug.Log("success " + JsonMapper.ToJson(res)); + }, + fail = (res) => + { + Debug.Log("fail" + res.errMsg); + }, + complete = (res) => + { + Debug.Log("complete"); + } } - }); + ); } - private void OnDestroy() { + private void OnDestroy() + { WX.OffBLEMTUChange(_onBLEMTUChange); WX.OffBLEConnectionStateChange(_onBLEConnectionStateChange); WX.OffBLECharacteristicValueChange(); } } - diff --git a/Demo/API_V2/Assets/API/Facility/BLEPeripheral/BLEPeripheral.cs b/Demo/API_V2/Assets/API/Facility/BLEPeripheral/BLEPeripheral.cs index f699b7691..b3c7ed2e7 100644 --- a/Demo/API_V2/Assets/API/Facility/BLEPeripheral/BLEPeripheral.cs +++ b/Demo/API_V2/Assets/API/Facility/BLEPeripheral/BLEPeripheral.cs @@ -3,67 +3,77 @@ using LitJson; using UnityEngine; using WeChatWASM; + public class BLEPeripheral : Details { - private bool _isListening = false; private BLEPeripheralServer _server; - private readonly Action _onBLEPeripheralConnectionStateChanged = (res) => { - var result = "onBLEPeripheralConnectionStateChanged\n" + JsonMapper.ToJson(res); - GameManager.Instance.detailsController.AddResult(new ResultData() + private readonly Action _onBLEPeripheralConnectionStateChanged = + (res) => { - initialContentText = result - }); - }; + var result = "onBLEPeripheralConnectionStateChanged\n" + JsonMapper.ToJson(res); + GameManager.Instance.detailsController.AddResult( + new ResultData() { initialContentText = result } + ); + }; - private readonly Action _onCharacteristicReadRequest = (res) => { - var result = "onCharacteristicReadRequest\n" + JsonMapper.ToJson(res); - GameManager.Instance.detailsController.AddResult(new ResultData() + private readonly Action _onCharacteristicReadRequest = + (res) => { - initialContentText = result - }); - }; + var result = "onCharacteristicReadRequest\n" + JsonMapper.ToJson(res); + GameManager.Instance.detailsController.AddResult( + new ResultData() { initialContentText = result } + ); + }; - private readonly Action _onCharacteristicSubscribed = (res) => { - var result = "onCharacteristicSubscribed\n" + JsonMapper.ToJson(res); - GameManager.Instance.detailsController.AddResult(new ResultData() + private readonly Action _onCharacteristicSubscribed = + (res) => { - initialContentText = result - }); - }; + var result = "onCharacteristicSubscribed\n" + JsonMapper.ToJson(res); + GameManager.Instance.detailsController.AddResult( + new ResultData() { initialContentText = result } + ); + }; - private readonly Action _onCharacteristicUnsubscribed = (res) => { - var result = "onCharacteristicUnsubscribed\n" + JsonMapper.ToJson(res); - GameManager.Instance.detailsController.AddResult(new ResultData() + private readonly Action _onCharacteristicUnsubscribed = + (res) => { - initialContentText = result - }); - }; + var result = "onCharacteristicUnsubscribed\n" + JsonMapper.ToJson(res); + GameManager.Instance.detailsController.AddResult( + new ResultData() { initialContentText = result } + ); + }; - private readonly Action _onCharacteristicWriteRequest = (res) => { - var result = "onCharacteristicWriteRequest\n" + JsonMapper.ToJson(res); - GameManager.Instance.detailsController.AddResult(new ResultData() + private readonly Action _onCharacteristicWriteRequest = + (res) => { - initialContentText = result - }); - }; + var result = "onCharacteristicWriteRequest\n" + JsonMapper.ToJson(res); + GameManager.Instance.detailsController.AddResult( + new ResultData() { initialContentText = result } + ); + }; private void Start() { - WX.CreateBLEPeripheralServer(new CreateBLEPeripheralServerOption - { - success = (res) => { - Debug.Log("success " + JsonMapper.ToJson(res)); - _server = res.server; - }, - fail = (res) => { - Debug.Log("fail" + res.errMsg); - }, - complete = (res) => { - Debug.Log("complete"); + WX.CreateBLEPeripheralServer( + new CreateBLEPeripheralServerOption + { + success = (res) => + { + Debug.Log("success " + JsonMapper.ToJson(res)); + _server = res.server; + }, + fail = (res) => + { + Debug.Log("fail" + res.errMsg); + }, + complete = (res) => + { + Debug.Log("complete"); + } } - }); + ); // 监听当前外围设备被连接或断开连接事件 WX.OnBLEPeripheralConnectionStateChanged(_onBLEPeripheralConnectionStateChanged); @@ -81,162 +91,201 @@ protected override void TestAPI(string[] args) addService(); } - public void addService() { - var permission1 = new CharacteristicPermission { - readable = true, - writeable = true - }; + public void addService() + { + var permission1 = new CharacteristicPermission { readable = true, writeable = true }; - var properties1 = new CharacteristicProperties { + var properties1 = new CharacteristicProperties + { write = true, read = true, notify = true, indicate = true }; - var descriptorpermission1 = new DescriptorPermission { - read = true, - write = true, - }; + var descriptorpermission1 = new DescriptorPermission { read = true, write = true, }; - var descriptors1 = new Descriptor { + var descriptors1 = new Descriptor + { uuid = "zz", permission = descriptorpermission1, - value = new byte[] {1, 2, 3} + value = new byte[] { 1, 2, 3 } }; - var characteristics1 = new Characteristic { + var characteristics1 = new Characteristic + { uuid = "yy", descriptors = new Descriptor[] { descriptors1 }, permission = permission1, properties = properties1, }; - var service1 = new BLEPeripheralService { + var service1 = new BLEPeripheralService + { uuid = "xx", characteristics = new Characteristic[] { characteristics1 } - }; - - _server.addService(new AddServiceOption - { - service = service1, - success = (res) => { - Debug.Log("success " + JsonMapper.ToJson(res)); - }, - fail = (res) => { - Debug.Log("fail" + res.errMsg); - }, - complete = (res) => { - Debug.Log("complete"); + }; + + _server.addService( + new AddServiceOption + { + service = service1, + success = (res) => + { + Debug.Log("success " + JsonMapper.ToJson(res)); + }, + fail = (res) => + { + Debug.Log("fail" + res.errMsg); + }, + complete = (res) => + { + Debug.Log("complete"); + } } - }); + ); } - public void removeService() { - _server.removeService(new RemoveServiceOption - { - serviceId = "xx", - success = (res) => { - Debug.Log("success " + JsonMapper.ToJson(res)); - }, - fail = (res) => { - Debug.Log("fail" + res.errMsg); - }, - complete = (res) => { - Debug.Log("complete"); + public void removeService() + { + _server.removeService( + new RemoveServiceOption + { + serviceId = "xx", + success = (res) => + { + Debug.Log("success " + JsonMapper.ToJson(res)); + }, + fail = (res) => + { + Debug.Log("fail" + res.errMsg); + }, + complete = (res) => + { + Debug.Log("complete"); + } } - }); + ); } - public void startAdvertising() { - var beacon1 = new BeaconInfoObj { + public void startAdvertising() + { + var beacon1 = new BeaconInfoObj + { major = 100, minor = 90, uuid = "zzzzz", measuredPower = 1000 }; - var manufacturerData1 = new ManufacturerData { + var manufacturerData1 = new ManufacturerData + { manufacturerId = "0x1111", - manufacturerSpecificData = new byte[] {1, 2, 3} + manufacturerSpecificData = new byte[] { 1, 2, 3 } }; - var advertiseRequest1 = new AdvertiseReqObj { + var advertiseRequest1 = new AdvertiseReqObj + { beacon = beacon1, connectable = true, deviceName = "x", manufacturerData = new ManufacturerData[] { manufacturerData1 }, - serviceUuids = new string[] {"xx", "yy", "aa"} + serviceUuids = new string[] { "xx", "yy", "aa" } }; - _server.startAdvertising(new StartAdvertisingObject - { - advertiseRequest = advertiseRequest1, - powerLevel = "medium", - success = (res) => { - Debug.Log("success " + JsonMapper.ToJson(res)); - }, - fail = (res) => { - Debug.Log("fail" + res.errMsg); - }, - complete = (res) => { - Debug.Log("complete"); + _server.startAdvertising( + new StartAdvertisingObject + { + advertiseRequest = advertiseRequest1, + powerLevel = "medium", + success = (res) => + { + Debug.Log("success " + JsonMapper.ToJson(res)); + }, + fail = (res) => + { + Debug.Log("fail" + res.errMsg); + }, + complete = (res) => + { + Debug.Log("complete"); + } } - }); + ); } - public void stopAdvertising() { - _server.stopAdvertising(new StopAdvertisingOption - { - success = (res) => { - Debug.Log("success " + JsonMapper.ToJson(res)); - }, - fail = (res) => { - Debug.Log("fail" + res.errMsg); - }, - complete = (res) => { - Debug.Log("complete"); + public void stopAdvertising() + { + _server.stopAdvertising( + new StopAdvertisingOption + { + success = (res) => + { + Debug.Log("success " + JsonMapper.ToJson(res)); + }, + fail = (res) => + { + Debug.Log("fail" + res.errMsg); + }, + complete = (res) => + { + Debug.Log("complete"); + } } - }); + ); } - public void writeCharacteristicValue() { - _server.writeCharacteristicValue(new WriteCharacteristicValueObject - { - characteristicId = "xx", - needNotify = true, - serviceId = "yy", - value = new byte[] {1, 2, 3}, - callbackId = 100, - success = (res) => { - Debug.Log("success " + JsonMapper.ToJson(res)); - }, - fail = (res) => { - Debug.Log("fail" + res.errMsg); - }, - complete = (res) => { - Debug.Log("complete"); + public void writeCharacteristicValue() + { + _server.writeCharacteristicValue( + new WriteCharacteristicValueObject + { + characteristicId = "xx", + needNotify = true, + serviceId = "yy", + value = new byte[] { 1, 2, 3 }, + callbackId = 100, + success = (res) => + { + Debug.Log("success " + JsonMapper.ToJson(res)); + }, + fail = (res) => + { + Debug.Log("fail" + res.errMsg); + }, + complete = (res) => + { + Debug.Log("complete"); + } } - }); + ); } - public void listen() { - if (!_isListening) { + public void listen() + { + if (!_isListening) + { _server.onCharacteristicReadRequest(_onCharacteristicReadRequest); _server.onCharacteristicSubscribed(_onCharacteristicSubscribed); _server.onCharacteristicUnsubscribed(_onCharacteristicUnsubscribed); _server.onCharacteristicWriteRequest(_onCharacteristicWriteRequest); - } else { + } + else + { _server.offCharacteristicReadRequest(_onCharacteristicReadRequest); _server.offCharacteristicSubscribed(_onCharacteristicSubscribed); _server.offCharacteristicUnsubscribed(_onCharacteristicUnsubscribed); _server.offCharacteristicWriteRequest(_onCharacteristicWriteRequest); } _isListening = !_isListening; - GameManager.Instance.detailsController.ChangeExtraButtonText(4, _isListening ? "取消监听" : "开始监听"); + GameManager.Instance.detailsController.ChangeExtraButtonText( + 4, + _isListening ? "取消监听" : "开始监听" + ); } - private void OnDestroy() { + private void OnDestroy() + { WX.OffBLEPeripheralConnectionStateChanged(_onBLEPeripheralConnectionStateChanged); _server.offCharacteristicReadRequest(_onCharacteristicReadRequest); _server.offCharacteristicSubscribed(_onCharacteristicSubscribed); @@ -245,4 +294,3 @@ private void OnDestroy() { _server = null; } } - diff --git a/Demo/API_V2/Assets/API/Facility/BatteryAndClipboard/BatteryAndClipboard.cs b/Demo/API_V2/Assets/API/Facility/BatteryAndClipboard/BatteryAndClipboard.cs index 34ffdec64..d0e977101 100644 --- a/Demo/API_V2/Assets/API/Facility/BatteryAndClipboard/BatteryAndClipboard.cs +++ b/Demo/API_V2/Assets/API/Facility/BatteryAndClipboard/BatteryAndClipboard.cs @@ -3,9 +3,9 @@ using LitJson; using UnityEngine; using WeChatWASM; + public class BatteryAndClipboard : Details { - private void Start() { GameManager.Instance.detailsController.BindExtraButtonAction(0, getBatteryInfo); @@ -19,62 +19,81 @@ protected override void TestAPI(string[] args) getBatteryInfoSync(); } - public void getBatteryInfoSync() { + public void getBatteryInfoSync() + { var res = WX.GetBatteryInfoSync(); - WX.ShowModal(new ShowModalOption() - { - content = "Access Success, Result: " + JsonMapper.ToJson(res) - }); + WX.ShowModal( + new ShowModalOption() { content = "Access Success, Result: " + JsonMapper.ToJson(res) } + ); } - public void getBatteryInfo() { - WX.GetBatteryInfo(new GetBatteryInfoOption - { - success = (res) => { - Debug.Log("success" + JsonUtility.ToJson(res)); - }, - fail = (res) => { - Debug.Log("fail" + res.errMsg); - }, - complete = (res) => { - Debug.Log("complete"); + public void getBatteryInfo() + { + WX.GetBatteryInfo( + new GetBatteryInfoOption + { + success = (res) => + { + Debug.Log("success" + JsonUtility.ToJson(res)); + }, + fail = (res) => + { + Debug.Log("fail" + res.errMsg); + }, + complete = (res) => + { + Debug.Log("complete"); + } } - }); + ); } - public void getClipboardData() { - WX.GetClipboardData(new GetClipboardDataOption - { - success = (res) => { - WX.ShowModal(new ShowModalOption() + public void getClipboardData() + { + WX.GetClipboardData( + new GetClipboardDataOption + { + success = (res) => { - content = "Access Success, Result: " + JsonMapper.ToJson(res) - }); - }, - fail = (res) => { - Debug.Log("fail" + res.errMsg); - }, - complete = (res) => { - Debug.Log("complete"); + WX.ShowModal( + new ShowModalOption() + { + content = "Access Success, Result: " + JsonMapper.ToJson(res) + } + ); + }, + fail = (res) => + { + Debug.Log("fail" + res.errMsg); + }, + complete = (res) => + { + Debug.Log("complete"); + } } - }); + ); } - public void setClipboardData() { - WX.SetClipboardData(new SetClipboardDataOption - { - data = "123", - success = (res) => { - Debug.Log(JsonUtility.ToJson(res)); - }, - fail = (res) => { - Debug.Log("fail" + res.errMsg); - }, - complete = (res) => { - Debug.Log("complete"); + public void setClipboardData() + { + WX.SetClipboardData( + new SetClipboardDataOption + { + data = "123", + success = (res) => + { + Debug.Log(JsonUtility.ToJson(res)); + }, + fail = (res) => + { + Debug.Log("fail" + res.errMsg); + }, + complete = (res) => + { + Debug.Log("complete"); + } } - }); + ); } } - diff --git a/Demo/API_V2/Assets/API/Facility/Beacon/Beacon.cs b/Demo/API_V2/Assets/API/Facility/Beacon/Beacon.cs index c74493727..274c157ef 100644 --- a/Demo/API_V2/Assets/API/Facility/Beacon/Beacon.cs +++ b/Demo/API_V2/Assets/API/Facility/Beacon/Beacon.cs @@ -3,25 +3,25 @@ using LitJson; using UnityEngine; using WeChatWASM; + public class Beacon : Details { - private bool _isListening = false; - private readonly Action _onBeaconUpdate = (res) => { + private readonly Action _onBeaconUpdate = (res) => + { var result = "onBeaconUpdate\n" + JsonMapper.ToJson(res); - GameManager.Instance.detailsController.AddResult(new ResultData() - { - initialContentText = result - }); + GameManager.Instance.detailsController.AddResult( + new ResultData() { initialContentText = result } + ); }; - private readonly Action _onBeaconServiceChange = (res) => { + private readonly Action _onBeaconServiceChange = (res) => + { var result = "onBeaconServiceChange\n" + JsonMapper.ToJson(res); - GameManager.Instance.detailsController.AddResult(new ResultData() - { - initialContentText = result - }); + GameManager.Instance.detailsController.AddResult( + new ResultData() { initialContentText = result } + ); }; private void Start() @@ -32,70 +32,93 @@ private void Start() // 测试 API protected override void TestAPI(string[] args) { - if (!_isListening) { + if (!_isListening) + { startBeaconDiscovery(); WX.OnBeaconUpdate(_onBeaconUpdate); WX.OnBeaconServiceChange(_onBeaconServiceChange); - } else { + } + else + { stopBeaconDiscovery(); WX.OffBeaconUpdate(_onBeaconUpdate); WX.OffBeaconServiceChange(_onBeaconServiceChange); } _isListening = !_isListening; - GameManager.Instance.detailsController.ChangeInitialButtonText(_isListening ? "取消搜索" : "开始搜索"); + GameManager.Instance.detailsController.ChangeInitialButtonText( + _isListening ? "取消搜索" : "开始搜索" + ); } - public void startBeaconDiscovery() { + public void startBeaconDiscovery() + { //需要更改uuids才能监测到蓝牙-信标 - WX.StartBeaconDiscovery(new StartBeaconDiscoveryOption - { - uuids = new string[] {"xxxxxxxxxx"}, - success = (res) => { - Debug.Log(JsonUtility.ToJson(res)); - }, - fail = (res) => { - Debug.Log("fail" + res.errMsg); - }, - complete = (res) => { - Debug.Log("complete"); + WX.StartBeaconDiscovery( + new StartBeaconDiscoveryOption + { + uuids = new string[] { "xxxxxxxxxx" }, + success = (res) => + { + Debug.Log(JsonUtility.ToJson(res)); + }, + fail = (res) => + { + Debug.Log("fail" + res.errMsg); + }, + complete = (res) => + { + Debug.Log("complete"); + } } - }); + ); } - public void stopBeaconDiscovery() { - WX.StopBeaconDiscovery(new StopBeaconDiscoveryOption - { - success = (res) => { - Debug.Log(JsonUtility.ToJson(res)); - }, - fail = (res) => { - Debug.Log("fail" + res.errMsg); - }, - complete = (res) => { - Debug.Log("complete"); + public void stopBeaconDiscovery() + { + WX.StopBeaconDiscovery( + new StopBeaconDiscoveryOption + { + success = (res) => + { + Debug.Log(JsonUtility.ToJson(res)); + }, + fail = (res) => + { + Debug.Log("fail" + res.errMsg); + }, + complete = (res) => + { + Debug.Log("complete"); + } } - }); + ); } - public void getBeacons() { - WX.GetBeacons(new GetBeaconsOption - { - success = (res) => { - Debug.Log(JsonUtility.ToJson(res)); - }, - fail = (res) => { - Debug.Log("fail" + res.errMsg); - }, - complete = (res) => { - Debug.Log("complete"); + public void getBeacons() + { + WX.GetBeacons( + new GetBeaconsOption + { + success = (res) => + { + Debug.Log(JsonUtility.ToJson(res)); + }, + fail = (res) => + { + Debug.Log("fail" + res.errMsg); + }, + complete = (res) => + { + Debug.Log("complete"); + } } - }); + ); } - private void OnDestroy() { + private void OnDestroy() + { stopBeaconDiscovery(); WX.OffBeaconUpdate(_onBeaconUpdate); WX.OffBeaconServiceChange(_onBeaconServiceChange); } } - diff --git a/Demo/API_V2/Assets/API/Facility/BluetoothDevice/BluetoothDevice.cs b/Demo/API_V2/Assets/API/Facility/BluetoothDevice/BluetoothDevice.cs index 004866c6e..2f48620ea 100644 --- a/Demo/API_V2/Assets/API/Facility/BluetoothDevice/BluetoothDevice.cs +++ b/Demo/API_V2/Assets/API/Facility/BluetoothDevice/BluetoothDevice.cs @@ -3,42 +3,44 @@ using LitJson; using UnityEngine; using WeChatWASM; + public class BluetoothDevice : Details { - private bool _isListening = false; - private bool _isListeningDiscovery = false; + private bool _isListeningDiscovery = false; - private readonly Action _onBluetoothDeviceFound = (res) => { + private readonly Action _onBluetoothDeviceFound = (res) => + { var result = "onBluetoothDeviceFound\n" + JsonMapper.ToJson(res); - GameManager.Instance.detailsController.AddResult(new ResultData() - { - initialContentText = result - }); + GameManager.Instance.detailsController.AddResult( + new ResultData() { initialContentText = result } + ); }; - private readonly Action _onBluetoothAdapterStateChange = (res) => { - var result = "onBluetoothAdapterStateChange\n" + JsonMapper.ToJson(res); - GameManager.Instance.detailsController.AddResult(new ResultData() + private readonly Action _onBluetoothAdapterStateChange = + (res) => { - initialContentText = result - }); - }; - + var result = "onBluetoothAdapterStateChange\n" + JsonMapper.ToJson(res); + GameManager.Instance.detailsController.AddResult( + new ResultData() { initialContentText = result } + ); + }; private void Start() { // 监听搜索到新设备的事件 WX.OnBluetoothDeviceFound(_onBluetoothDeviceFound); - + // 监听蓝牙适配器状态变化事件 WX.OnBluetoothAdapterStateChange(_onBluetoothAdapterStateChange); - GameManager.Instance.detailsController.BindExtraButtonAction(0, bluetoothDevicesDiscovery); GameManager.Instance.detailsController.BindExtraButtonAction(1, makeBluetoothPair); GameManager.Instance.detailsController.BindExtraButtonAction(2, isBluetoothDevicePaired); - GameManager.Instance.detailsController.BindExtraButtonAction(3, getConnectedBluetoothDevices); + GameManager.Instance.detailsController.BindExtraButtonAction( + 3, + getConnectedBluetoothDevices + ); GameManager.Instance.detailsController.BindExtraButtonAction(4, getBluetoothDevices); GameManager.Instance.detailsController.BindExtraButtonAction(5, getBluetoothAdapterState); } @@ -49,154 +51,217 @@ protected override void TestAPI(string[] args) BluetoothAdapter(); } - public void BluetoothAdapter() { - if (!_isListening) { - WX.OpenBluetoothAdapter(new OpenBluetoothAdapterOption + public void BluetoothAdapter() + { + if (!_isListening) + { + WX.OpenBluetoothAdapter( + new OpenBluetoothAdapterOption + { + mode = "peripheral", + success = (res) => + { + Debug.Log("success " + JsonMapper.ToJson(res)); + }, + fail = (res) => + { + Debug.Log("fail" + res.errMsg); + }, + complete = (res) => + { + Debug.Log("complete"); + } + } + ); + } + else + { + WX.CloseBluetoothAdapter( + new CloseBluetoothAdapterOption + { + success = (res) => + { + Debug.Log("success " + JsonMapper.ToJson(res)); + }, + fail = (res) => + { + Debug.Log("fail" + res.errMsg); + }, + complete = (res) => + { + Debug.Log("complete"); + } + } + ); + } + _isListening = !_isListening; + GameManager.Instance.detailsController.ChangeInitialButtonText( + _isListening ? "关闭蓝牙模块" : "初始化蓝牙模块" + ); + } + + public void bluetoothDevicesDiscovery() + { + if (!_isListeningDiscovery) + { + WX.StartBluetoothDevicesDiscovery( + new StartBluetoothDevicesDiscoveryOption + { + success = (res) => + { + Debug.Log("success " + JsonMapper.ToJson(res)); + }, + fail = (res) => + { + Debug.Log("fail" + res.errMsg); + }, + complete = (res) => + { + Debug.Log("complete"); + } + } + ); + } + else + { + WX.StopBluetoothDevicesDiscovery( + new StopBluetoothDevicesDiscoveryOption + { + success = (res) => + { + Debug.Log("success " + JsonMapper.ToJson(res)); + }, + fail = (res) => + { + Debug.Log("fail" + res.errMsg); + }, + complete = (res) => + { + Debug.Log("complete"); + } + } + ); + } + _isListeningDiscovery = !_isListeningDiscovery; + GameManager.Instance.detailsController.ChangeExtraButtonText( + 0, + _isListeningDiscovery ? "停止搜寻蓝牙设备" : "开始搜寻蓝牙设备" + ); + } + + public void makeBluetoothPair() + { + WX.MakeBluetoothPair( + new MakeBluetoothPairOption { - mode = "peripheral", - success = (res) => { + deviceId = "xxx", + pin = "xxx", + timeout = 20000, + success = (res) => + { Debug.Log("success " + JsonMapper.ToJson(res)); }, - fail = (res) => { + fail = (res) => + { Debug.Log("fail" + res.errMsg); }, - complete = (res) => { + complete = (res) => + { Debug.Log("complete"); } - }); - } else { - WX.CloseBluetoothAdapter(new CloseBluetoothAdapterOption + } + ); + } + + public void isBluetoothDevicePaired() + { + WX.IsBluetoothDevicePaired( + new IsBluetoothDevicePairedOption { - success = (res) => { + deviceId = "xx", + success = (res) => + { Debug.Log("success " + JsonMapper.ToJson(res)); }, - fail = (res) => { + fail = (res) => + { Debug.Log("fail" + res.errMsg); }, - complete = (res) => { + complete = (res) => + { Debug.Log("complete"); } - }); - } - _isListening = !_isListening; - GameManager.Instance.detailsController.ChangeInitialButtonText(_isListening ? "关闭蓝牙模块" : "初始化蓝牙模块"); + } + ); } - public void bluetoothDevicesDiscovery() { - if (!_isListeningDiscovery) { - WX.StartBluetoothDevicesDiscovery(new StartBluetoothDevicesDiscoveryOption + public void getConnectedBluetoothDevices() + { + WX.GetConnectedBluetoothDevices( + new GetConnectedBluetoothDevicesOption { - success = (res) => { + services = new string[] { "xx", "yy" }, + success = (res) => + { Debug.Log("success " + JsonMapper.ToJson(res)); }, - fail = (res) => { + fail = (res) => + { Debug.Log("fail" + res.errMsg); }, - complete = (res) => { + complete = (res) => + { Debug.Log("complete"); } - }); - } else { - WX.StopBluetoothDevicesDiscovery(new StopBluetoothDevicesDiscoveryOption + } + ); + } + + public void getBluetoothDevices() + { + WX.GetBluetoothDevices( + new GetBluetoothDevicesOption { - success = (res) => { + success = (res) => + { Debug.Log("success " + JsonMapper.ToJson(res)); }, - fail = (res) => { + fail = (res) => + { Debug.Log("fail" + res.errMsg); }, - complete = (res) => { + complete = (res) => + { Debug.Log("complete"); } - }); - } - _isListeningDiscovery = !_isListeningDiscovery; - GameManager.Instance.detailsController.ChangeExtraButtonText(0, _isListeningDiscovery ? "停止搜寻蓝牙设备" : "开始搜寻蓝牙设备"); - } - - public void makeBluetoothPair() { - WX.MakeBluetoothPair(new MakeBluetoothPairOption - { - deviceId = "xxx", - pin = "xxx", - timeout = 20000, - success = (res) => { - Debug.Log("success " + JsonMapper.ToJson(res)); - }, - fail = (res) => { - Debug.Log("fail" + res.errMsg); - }, - complete = (res) => { - Debug.Log("complete"); - } - }); - } - - public void isBluetoothDevicePaired() { - WX.IsBluetoothDevicePaired(new IsBluetoothDevicePairedOption - { - deviceId = "xx", - success = (res) => { - Debug.Log("success " + JsonMapper.ToJson(res)); - }, - fail = (res) => { - Debug.Log("fail" + res.errMsg); - }, - complete = (res) => { - Debug.Log("complete"); - } - }); - } - - public void getConnectedBluetoothDevices() { - WX.GetConnectedBluetoothDevices(new GetConnectedBluetoothDevicesOption - { - services = new string[]{"xx", "yy"}, - success = (res) => { - Debug.Log("success " + JsonMapper.ToJson(res)); - }, - fail = (res) => { - Debug.Log("fail" + res.errMsg); - }, - complete = (res) => { - Debug.Log("complete"); } - }); + ); } - public void getBluetoothDevices() { - WX.GetBluetoothDevices(new GetBluetoothDevicesOption - { - success = (res) => { - Debug.Log("success " + JsonMapper.ToJson(res)); - }, - fail = (res) => { - Debug.Log("fail" + res.errMsg); - }, - complete = (res) => { - Debug.Log("complete"); - } - }); - } - - public void getBluetoothAdapterState() { - WX.GetBluetoothAdapterState(new GetBluetoothAdapterStateOption - { - success = (res) => { - Debug.Log("success " + JsonMapper.ToJson(res)); - }, - fail = (res) => { - Debug.Log("fail" + res.errMsg); - }, - complete = (res) => { - Debug.Log("complete"); + public void getBluetoothAdapterState() + { + WX.GetBluetoothAdapterState( + new GetBluetoothAdapterStateOption + { + success = (res) => + { + Debug.Log("success " + JsonMapper.ToJson(res)); + }, + fail = (res) => + { + Debug.Log("fail" + res.errMsg); + }, + complete = (res) => + { + Debug.Log("complete"); + } } - }); + ); } - private void OnDestroy() { + private void OnDestroy() + { WX.OffBluetoothDeviceFound(_onBluetoothDeviceFound); WX.OffBluetoothAdapterStateChange(_onBluetoothAdapterStateChange); } } - diff --git a/Demo/API_V2/Assets/API/Facility/Keyboard/Keyboard.cs b/Demo/API_V2/Assets/API/Facility/Keyboard/Keyboard.cs index 830974eb9..e046c345f 100644 --- a/Demo/API_V2/Assets/API/Facility/Keyboard/Keyboard.cs +++ b/Demo/API_V2/Assets/API/Facility/Keyboard/Keyboard.cs @@ -3,67 +3,60 @@ using LitJson; using UnityEngine; using WeChatWASM; + public class Keyboard : Details { - private bool _isListening = false; private System.Random random = new System.Random(); private readonly Action _onKeyUp = (res) => { var result = "onKeyUp\n" + JsonMapper.ToJson(res); - GameManager.Instance.detailsController.AddResult(new ResultData() - { - initialContentText = result - }); + GameManager.Instance.detailsController.AddResult( + new ResultData() { initialContentText = result } + ); }; private readonly Action _onKeyDown = (res) => { var result = "onKeyDown\n" + JsonMapper.ToJson(res); - GameManager.Instance.detailsController.AddResult(new ResultData() - { - initialContentText = result - }); + GameManager.Instance.detailsController.AddResult( + new ResultData() { initialContentText = result } + ); }; private readonly Action _onKeyboardInput = (res) => { var result = "onKeyboardInput\n" + JsonMapper.ToJson(res); - GameManager.Instance.detailsController.AddResult(new ResultData() - { - initialContentText = result - }); + GameManager.Instance.detailsController.AddResult( + new ResultData() { initialContentText = result } + ); }; private readonly Action _onKeyboardComplete = (res) => { var result = "onKeyboardComplete\n" + JsonMapper.ToJson(res); - GameManager.Instance.detailsController.AddResult(new ResultData() - { - initialContentText = result - }); + GameManager.Instance.detailsController.AddResult( + new ResultData() { initialContentText = result } + ); }; private readonly Action _onKeyboardConfirm = (res) => { var result = "onKeyboardConfirm\n" + JsonMapper.ToJson(res); - GameManager.Instance.detailsController.AddResult(new ResultData() - { - initialContentText = result - }); + GameManager.Instance.detailsController.AddResult( + new ResultData() { initialContentText = result } + ); }; private readonly Action _onKeyboardHeightChange = (res) => { var result = "onKeyboardHeightChange\n" + JsonMapper.ToJson(res); - GameManager.Instance.detailsController.AddResult(new ResultData() - { - initialContentText = result - }); + GameManager.Instance.detailsController.AddResult( + new ResultData() { initialContentText = result } + ); }; - private void Start() { // 绑定额外的按钮操作 @@ -100,98 +93,106 @@ public void listening() WX.OffKeyboardComplete(_onKeyboardComplete); } _isListening = !_isListening; - GameManager.Instance.detailsController.ChangeExtraButtonText(3, _isListening ? "取消监听" : "开始监听"); + GameManager.Instance.detailsController.ChangeExtraButtonText( + 3, + _isListening ? "取消监听" : "开始监听" + ); } public void showMultipleKeyboard() { - WX.ShowKeyboard(new ShowKeyboardOption - { - defaultValue = "test", - maxLength = 20, - multiple = true, - confirmHold = false, - confirmType = "done", - success = (res) => - { - Debug.Log("success"); - }, - fail = (res) => + WX.ShowKeyboard( + new ShowKeyboardOption { - Debug.Log("fail" + res.errMsg); - }, - complete = (res) => - { - Debug.Log("complete"); + defaultValue = "test", + maxLength = 20, + multiple = true, + confirmHold = false, + confirmType = "done", + success = (res) => + { + Debug.Log("success"); + }, + fail = (res) => + { + Debug.Log("fail" + res.errMsg); + }, + complete = (res) => + { + Debug.Log("complete"); + } } - }); + ); } public void showKeyboard() { - WX.ShowKeyboard(new ShowKeyboardOption - { - defaultValue = "test", - maxLength = 20, - multiple = false, - confirmHold = false, - confirmType = "done", - success = (res) => - { - Debug.Log("success"); - }, - fail = (res) => + WX.ShowKeyboard( + new ShowKeyboardOption { - Debug.Log("fail" + res.errMsg); - }, - complete = (res) => - { - Debug.Log("complete"); + defaultValue = "test", + maxLength = 20, + multiple = false, + confirmHold = false, + confirmType = "done", + success = (res) => + { + Debug.Log("success"); + }, + fail = (res) => + { + Debug.Log("fail" + res.errMsg); + }, + complete = (res) => + { + Debug.Log("complete"); + } } - }); + ); } public void updateKeyboard() { - WX.UpdateKeyboard(new UpdateKeyboardOption - { - value = "test" + random.Next(0, 100), - success = (res) => + WX.UpdateKeyboard( + new UpdateKeyboardOption { - Debug.Log("success"); - WX.ShowToast(new ShowToastOption + value = "test" + random.Next(0, 100), + success = (res) => { - title = "更改成功" - }); - }, - fail = (res) => - { - Debug.Log("fail" + res.errMsg); - }, - complete = (res) => - { - Debug.Log("complete"); + Debug.Log("success"); + WX.ShowToast(new ShowToastOption { title = "更改成功" }); + }, + fail = (res) => + { + Debug.Log("fail" + res.errMsg); + }, + complete = (res) => + { + Debug.Log("complete"); + } } - }); + ); } public void hideKeyboard() { - WX.HideKeyboard(new HideKeyboardOption - { - success = (res) => - { - Debug.Log("success"); - }, - fail = (res) => - { - Debug.Log("fail" + res.errMsg); - }, - complete = (res) => + WX.HideKeyboard( + new HideKeyboardOption { - Debug.Log("complete"); + success = (res) => + { + Debug.Log("success"); + }, + fail = (res) => + { + Debug.Log("fail" + res.errMsg); + }, + complete = (res) => + { + Debug.Log("complete"); + } } - }); + ); } public void Destroy() @@ -206,4 +207,3 @@ public void Destroy() hideKeyboard(); } } - diff --git a/Demo/API_V2/Assets/API/Facility/Listen/Listen.cs b/Demo/API_V2/Assets/API/Facility/Listen/Listen.cs index 24fadac33..f581dffdc 100644 --- a/Demo/API_V2/Assets/API/Facility/Listen/Listen.cs +++ b/Demo/API_V2/Assets/API/Facility/Listen/Listen.cs @@ -6,51 +6,52 @@ public class Listen : Details { - private bool _isListeningAccelerometer = false; private bool _isListeningCompass = false; private bool _isListeningDeviceMotion = false; private bool _isPortrait = true; private bool _isListeningGyroscope = false; - private readonly Action _onAccelerometerChange = (res) => { + private readonly Action _onAccelerometerChange = (res) => + { var result = "onAccelerometerChange\n" + JsonMapper.ToJson(res); - GameManager.Instance.detailsController.AddResult(new ResultData() - { - initialContentText = result - }); + GameManager.Instance.detailsController.AddResult( + new ResultData() { initialContentText = result } + ); }; - private readonly Action _onCompassChange = (res) => { + private readonly Action _onCompassChange = (res) => + { var result = "onCompassChange\n" + JsonMapper.ToJson(res); - GameManager.Instance.detailsController.AddResult(new ResultData() - { - initialContentText = result - }); + GameManager.Instance.detailsController.AddResult( + new ResultData() { initialContentText = result } + ); }; - private readonly Action _onDeviceMotionChange = (res) => { + private readonly Action _onDeviceMotionChange = (res) => + { var result = "onDeviceMotionChange\n" + JsonMapper.ToJson(res); - GameManager.Instance.detailsController.AddResult(new ResultData() - { - initialContentText = result - }); + GameManager.Instance.detailsController.AddResult( + new ResultData() { initialContentText = result } + ); }; - private readonly Action _onDeviceOrientationChange = (res) => { + private readonly Action _onDeviceOrientationChange = ( + res + ) => + { var result = "onDeviceOrientationChange\n" + JsonMapper.ToJson(res); - GameManager.Instance.detailsController.AddResult(new ResultData() - { - initialContentText = result - }); + GameManager.Instance.detailsController.AddResult( + new ResultData() { initialContentText = result } + ); }; - private readonly Action _onGyroscopeChange = (res) => { + private readonly Action _onGyroscopeChange = (res) => + { var result = "onGyroscopeChange\n" + JsonMapper.ToJson(res); - GameManager.Instance.detailsController.AddResult(new ResultData() - { - initialContentText = result - }); + GameManager.Instance.detailsController.AddResult( + new ResultData() { initialContentText = result } + ); }; private void Start() @@ -70,187 +71,277 @@ protected override void TestAPI(string[] args) Accelerometer(); } - public void Accelerometer() { - if (!_isListeningAccelerometer) { - WX.StartAccelerometer(new StartAccelerometerOption - { - interval = "normal", - success = (res) => { - WX.ShowToast(new ShowToastOption() + public void Accelerometer() + { + if (!_isListeningAccelerometer) + { + WX.StartAccelerometer( + new StartAccelerometerOption + { + interval = "normal", + success = (res) => { - title = "Access Success, Result: " + JsonMapper.ToJson(res) - }); - }, - fail = (res) => { - Debug.Log("fail" + res.errMsg); - }, - complete = (res) => { - Debug.Log("complete"); + WX.ShowToast( + new ShowToastOption() + { + title = "Access Success, Result: " + JsonMapper.ToJson(res) + } + ); + }, + fail = (res) => + { + Debug.Log("fail" + res.errMsg); + }, + complete = (res) => + { + Debug.Log("complete"); + } } - }); + ); WX.OnAccelerometerChange(_onAccelerometerChange); - } else { - WX.StopAccelerometer(new StopAccelerometerOption - { - success = (res) => { - WX.ShowToast(new ShowToastOption() + } + else + { + WX.StopAccelerometer( + new StopAccelerometerOption + { + success = (res) => { - title = "Access Success, Result: " + JsonMapper.ToJson(res) - }); - }, - fail = (res) => { - Debug.Log("fail" + res.errMsg); - }, - complete = (res) => { - Debug.Log("complete"); + WX.ShowToast( + new ShowToastOption() + { + title = "Access Success, Result: " + JsonMapper.ToJson(res) + } + ); + }, + fail = (res) => + { + Debug.Log("fail" + res.errMsg); + }, + complete = (res) => + { + Debug.Log("complete"); + } } - }); + ); WX.OffAccelerometerChange(_onAccelerometerChange); } _isListeningAccelerometer = !_isListeningAccelerometer; - GameManager.Instance.detailsController.ChangeInitialButtonText(_isListeningAccelerometer ? "取消监听加速度" : "开始监听加速度"); + GameManager.Instance.detailsController.ChangeInitialButtonText( + _isListeningAccelerometer ? "取消监听加速度" : "开始监听加速度" + ); } - public void Compass() { - if (!_isListeningCompass) { - WX.StartCompass(new StartCompassOption - { - success = (res) => { - WX.ShowToast(new ShowToastOption() + public void Compass() + { + if (!_isListeningCompass) + { + WX.StartCompass( + new StartCompassOption + { + success = (res) => { - title = "Access Success, Result: " + JsonMapper.ToJson(res) - }); - }, - fail = (res) => { - Debug.Log("fail" + res.errMsg); - }, - complete = (res) => { - Debug.Log("complete"); + WX.ShowToast( + new ShowToastOption() + { + title = "Access Success, Result: " + JsonMapper.ToJson(res) + } + ); + }, + fail = (res) => + { + Debug.Log("fail" + res.errMsg); + }, + complete = (res) => + { + Debug.Log("complete"); + } } - }); + ); WX.OnCompassChange(_onCompassChange); - } else { - WX.StopCompass(new StopCompassOption - { - success = (res) => { - WX.ShowToast(new ShowToastOption() + } + else + { + WX.StopCompass( + new StopCompassOption + { + success = (res) => { - title = "Access Success, Result: " + JsonMapper.ToJson(res) - }); - }, - fail = (res) => { - Debug.Log("fail" + res.errMsg); - }, - complete = (res) => { - Debug.Log("complete"); + WX.ShowToast( + new ShowToastOption() + { + title = "Access Success, Result: " + JsonMapper.ToJson(res) + } + ); + }, + fail = (res) => + { + Debug.Log("fail" + res.errMsg); + }, + complete = (res) => + { + Debug.Log("complete"); + } } - }); + ); WX.OffCompassChange(_onCompassChange); } _isListeningCompass = !_isListeningCompass; - GameManager.Instance.detailsController.ChangeExtraButtonText(0, _isListeningCompass ? "取消监听罗盘" : "开始监听罗盘"); + GameManager.Instance.detailsController.ChangeExtraButtonText( + 0, + _isListeningCompass ? "取消监听罗盘" : "开始监听罗盘" + ); } - public void DeviceMotion() { - if (!_isListeningDeviceMotion) { - WX.StartDeviceMotionListening(new StartDeviceMotionListeningOption - { - interval = "normal", - success = (res) => { - WX.ShowToast(new ShowToastOption() + public void DeviceMotion() + { + if (!_isListeningDeviceMotion) + { + WX.StartDeviceMotionListening( + new StartDeviceMotionListeningOption + { + interval = "normal", + success = (res) => { - title = "Access Success, Result: " + JsonMapper.ToJson(res) - }); - }, - fail = (res) => { - Debug.Log("fail" + res.errMsg); - }, - complete = (res) => { - Debug.Log("complete"); + WX.ShowToast( + new ShowToastOption() + { + title = "Access Success, Result: " + JsonMapper.ToJson(res) + } + ); + }, + fail = (res) => + { + Debug.Log("fail" + res.errMsg); + }, + complete = (res) => + { + Debug.Log("complete"); + } } - }); + ); WX.OnDeviceMotionChange(_onDeviceMotionChange); - } else { - WX.StopDeviceMotionListening(new StopDeviceMotionListeningOption - { - success = (res) => { - WX.ShowToast(new ShowToastOption() + } + else + { + WX.StopDeviceMotionListening( + new StopDeviceMotionListeningOption + { + success = (res) => { - title = "Access Success, Result: " + JsonMapper.ToJson(res) - }); - }, - fail = (res) => { - Debug.Log("fail" + res.errMsg); - }, - complete = (res) => { - Debug.Log("complete"); + WX.ShowToast( + new ShowToastOption() + { + title = "Access Success, Result: " + JsonMapper.ToJson(res) + } + ); + }, + fail = (res) => + { + Debug.Log("fail" + res.errMsg); + }, + complete = (res) => + { + Debug.Log("complete"); + } } - }); + ); WX.OffDeviceMotionChange(_onDeviceMotionChange); } _isListeningDeviceMotion = !_isListeningDeviceMotion; - GameManager.Instance.detailsController.ChangeExtraButtonText(1, _isListeningDeviceMotion ? "取消监听设备方向" : "开始监听设备方向"); - } - - public void DeviceOrientation() { - WX.SetDeviceOrientation(new SetDeviceOrientationOption - { - value = !_isPortrait ? "portrait" : "landscape", - success = (res) => { - Debug.Log("success"); - }, - fail = (res) => { - Debug.Log("fail" + res.errMsg); - }, - complete = (res) => { - Debug.Log("complete"); - } - }); - _isPortrait = !_isPortrait; + GameManager.Instance.detailsController.ChangeExtraButtonText( + 1, + _isListeningDeviceMotion ? "取消监听设备方向" : "开始监听设备方向" + ); } - public void Gyroscope() { - if (!_isListeningGyroscope) { - WX.StartGyroscope(new StartGyroscopeOption + public void DeviceOrientation() + { + WX.SetDeviceOrientation( + new SetDeviceOrientationOption { - interval = "normal", - success = (res) => { - WX.ShowToast(new ShowToastOption() - { - title = "Access Success, Result: " + JsonMapper.ToJson(res) - }); + value = !_isPortrait ? "portrait" : "landscape", + success = (res) => + { + Debug.Log("success"); }, - fail = (res) => { + fail = (res) => + { Debug.Log("fail" + res.errMsg); }, - complete = (res) => { + complete = (res) => + { Debug.Log("complete"); } - }); + } + ); + _isPortrait = !_isPortrait; + } + + public void Gyroscope() + { + if (!_isListeningGyroscope) + { + WX.StartGyroscope( + new StartGyroscopeOption + { + interval = "normal", + success = (res) => + { + WX.ShowToast( + new ShowToastOption() + { + title = "Access Success, Result: " + JsonMapper.ToJson(res) + } + ); + }, + fail = (res) => + { + Debug.Log("fail" + res.errMsg); + }, + complete = (res) => + { + Debug.Log("complete"); + } + } + ); WX.OnGyroscopeChange(_onGyroscopeChange); - } else { - WX.StopGyroscope(new StopGyroscopeOption - { - success = (res) => { - WX.ShowToast(new ShowToastOption() + } + else + { + WX.StopGyroscope( + new StopGyroscopeOption + { + success = (res) => { - title = "Access Success, Result: " + JsonMapper.ToJson(res) - }); - }, - fail = (res) => { - Debug.Log("fail" + res.errMsg); - }, - complete = (res) => { - Debug.Log("complete"); + WX.ShowToast( + new ShowToastOption() + { + title = "Access Success, Result: " + JsonMapper.ToJson(res) + } + ); + }, + fail = (res) => + { + Debug.Log("fail" + res.errMsg); + }, + complete = (res) => + { + Debug.Log("complete"); + } } - }); + ); WX.OffGyroscopeChange(_onGyroscopeChange); } _isListeningGyroscope = !_isListeningGyroscope; - GameManager.Instance.detailsController.ChangeExtraButtonText(3, _isListeningGyroscope ? "取消监听陀螺仪" : "开始监听陀螺仪"); + GameManager.Instance.detailsController.ChangeExtraButtonText( + 3, + _isListeningGyroscope ? "取消监听陀螺仪" : "开始监听陀螺仪" + ); } - private void OnDestroy() { + private void OnDestroy() + { WX.OffDeviceOrientationChange(_onDeviceOrientationChange); WX.OffAccelerometerChange(_onAccelerometerChange); WX.OffCompassChange(_onCompassChange); @@ -258,4 +349,3 @@ private void OnDestroy() { WX.OffGyroscopeChange(_onGyroscopeChange); } } - diff --git a/Demo/API_V2/Assets/API/Facility/MouseAndWheel/MouseAndWheel.cs b/Demo/API_V2/Assets/API/Facility/MouseAndWheel/MouseAndWheel.cs index 5660c315c..f56accfbe 100644 --- a/Demo/API_V2/Assets/API/Facility/MouseAndWheel/MouseAndWheel.cs +++ b/Demo/API_V2/Assets/API/Facility/MouseAndWheel/MouseAndWheel.cs @@ -3,66 +3,71 @@ using LitJson; using UnityEngine; using WeChatWASM; + public class MouseAndWheel : Details { - private bool _isListening = false; - private readonly Action _onMouseUp = (res) => { + private readonly Action _onMouseUp = (res) => + { var result = "onMouseUp\n" + JsonMapper.ToJson(res); - GameManager.Instance.detailsController.AddResult(new ResultData() - { - initialContentText = result - }); + GameManager.Instance.detailsController.AddResult( + new ResultData() { initialContentText = result } + ); }; - private readonly Action _onMouseMove = (res) => { + private readonly Action _onMouseMove = (res) => + { var result = "onMouseMove\n" + JsonMapper.ToJson(res); - GameManager.Instance.detailsController.AddResult(new ResultData() - { - initialContentText = result - }); + GameManager.Instance.detailsController.AddResult( + new ResultData() { initialContentText = result } + ); }; - private readonly Action _onMouseDown = (res) => { + private readonly Action _onMouseDown = (res) => + { var result = "onMouseDown\n" + JsonMapper.ToJson(res); - GameManager.Instance.detailsController.AddResult(new ResultData() - { - initialContentText = result - }); + GameManager.Instance.detailsController.AddResult( + new ResultData() { initialContentText = result } + ); }; - private readonly Action _onWheel = (res) => { + private readonly Action _onWheel = (res) => + { var result = "onWheel\n" + JsonMapper.ToJson(res); - GameManager.Instance.detailsController.AddResult(new ResultData() - { - initialContentText = result - }); + GameManager.Instance.detailsController.AddResult( + new ResultData() { initialContentText = result } + ); }; // 测试 API protected override void TestAPI(string[] args) { - if (!_isListening) { + if (!_isListening) + { WX.OnMouseUp(_onMouseUp); WX.OnMouseDown(_onMouseDown); WX.OnMouseMove(_onMouseMove); WX.OnWheel(_onWheel); - } else { + } + else + { WX.OffMouseUp(_onMouseUp); WX.OffMouseDown(_onMouseDown); WX.OffMouseMove(_onMouseMove); WX.OffWheel(_onWheel); } _isListening = !_isListening; - GameManager.Instance.detailsController.ChangeInitialButtonText(_isListening ? "取消监听" : "开始监听"); + GameManager.Instance.detailsController.ChangeInitialButtonText( + _isListening ? "取消监听" : "开始监听" + ); } - private void OnDestroy() { + private void OnDestroy() + { WX.OffMouseUp(_onMouseUp); WX.OffMouseDown(_onMouseDown); WX.OffMouseMove(_onMouseMove); WX.OffWheel(_onWheel); } } - diff --git a/Demo/API_V2/Assets/API/Facility/Network/Network.cs b/Demo/API_V2/Assets/API/Facility/Network/Network.cs index ffc5e1e7f..691c6a780 100644 --- a/Demo/API_V2/Assets/API/Facility/Network/Network.cs +++ b/Demo/API_V2/Assets/API/Facility/Network/Network.cs @@ -3,28 +3,27 @@ using LitJson; using UnityEngine; using WeChatWASM; + public class Network : Details { - private bool _isListening = false; - private readonly Action _onNetworkWeakChange = (res) => { + private readonly Action _onNetworkWeakChange = (res) => + { var result = "onNetworkWeakChange\n" + JsonMapper.ToJson(res); - GameManager.Instance.detailsController.AddResult(new ResultData() - { - initialContentText = result - }); + GameManager.Instance.detailsController.AddResult( + new ResultData() { initialContentText = result } + ); }; - private readonly Action _onNetworkStatusChange = (res) => { + private readonly Action _onNetworkStatusChange = (res) => + { var result = "onNetworkStatusChange\n" + JsonMapper.ToJson(res); - GameManager.Instance.detailsController.AddResult(new ResultData() - { - initialContentText = result - }); + GameManager.Instance.detailsController.AddResult( + new ResultData() { initialContentText = result } + ); }; - private void Start() { GameManager.Instance.detailsController.BindExtraButtonAction(0, getNetworkType); @@ -34,56 +33,77 @@ private void Start() // 测试 API protected override void TestAPI(string[] args) { - if (!_isListening) { + if (!_isListening) + { WX.OnNetworkWeakChange(_onNetworkWeakChange); WX.OnNetworkStatusChange(_onNetworkStatusChange); - } else { + } + else + { WX.OffNetworkWeakChange(_onNetworkWeakChange); WX.OffNetworkStatusChange(_onNetworkStatusChange); } _isListening = !_isListening; - GameManager.Instance.detailsController.ChangeInitialButtonText(_isListening ? "取消监听" : "开始监听"); + GameManager.Instance.detailsController.ChangeInitialButtonText( + _isListening ? "取消监听" : "开始监听" + ); } - public void getNetworkType() { - WX.GetNetworkType(new GetNetworkTypeOption - { - success = (res) => { - WX.ShowModal(new ShowModalOption() + public void getNetworkType() + { + WX.GetNetworkType( + new GetNetworkTypeOption + { + success = (res) => + { + WX.ShowModal( + new ShowModalOption() + { + content = "Access Success, Result: " + JsonMapper.ToJson(res) + } + ); + }, + fail = (res) => { - content = "Access Success, Result: " + JsonMapper.ToJson(res) - }); - }, - fail = (res) => { - Debug.Log("fail" + res.errMsg); - }, - complete = (res) => { - Debug.Log("complete"); + Debug.Log("fail" + res.errMsg); + }, + complete = (res) => + { + Debug.Log("complete"); + } } - }); + ); } - public void getLocalIPAddress() { - WX.GetLocalIPAddress(new GetLocalIPAddressOption - { - success = (res) => { - WX.ShowModal(new ShowModalOption() + public void getLocalIPAddress() + { + WX.GetLocalIPAddress( + new GetLocalIPAddressOption + { + success = (res) => + { + WX.ShowModal( + new ShowModalOption() + { + content = "Access Success, Result: " + JsonMapper.ToJson(res) + } + ); + }, + fail = (res) => + { + Debug.Log("fail" + res.errMsg); + }, + complete = (res) => { - content = "Access Success, Result: " + JsonMapper.ToJson(res) - }); - }, - fail = (res) => { - Debug.Log("fail" + res.errMsg); - }, - complete = (res) => { - Debug.Log("complete"); + Debug.Log("complete"); + } } - }); + ); } - private void OnDestroy() { + private void OnDestroy() + { WX.OffNetworkWeakChange(_onNetworkWeakChange); WX.OffNetworkStatusChange(_onNetworkStatusChange); } } - diff --git a/Demo/API_V2/Assets/API/Facility/Other/Other.cs b/Demo/API_V2/Assets/API/Facility/Other/Other.cs index bb5dbfd1d..09f94b9ee 100644 --- a/Demo/API_V2/Assets/API/Facility/Other/Other.cs +++ b/Demo/API_V2/Assets/API/Facility/Other/Other.cs @@ -3,20 +3,19 @@ using LitJson; using UnityEngine; using WeChatWASM; + public class Other : Details { - private bool _isListening = false; - private readonly Action _onMemoryWarning = (res) => { + private readonly Action _onMemoryWarning = (res) => + { var result = "onMemoryWarning\n" + JsonMapper.ToJson(res); - GameManager.Instance.detailsController.AddResult(new ResultData() - { - initialContentText = result - }); + GameManager.Instance.detailsController.AddResult( + new ResultData() { initialContentText = result } + ); }; - private void Start() { GameManager.Instance.detailsController.BindExtraButtonAction(0, scanCode); @@ -30,66 +29,90 @@ protected override void TestAPI(string[] args) memoryWarning(); } - public void memoryWarning() { - if (!_isListening) { + public void memoryWarning() + { + if (!_isListening) + { WX.OnMemoryWarning(_onMemoryWarning); - } else { + } + else + { WX.OffMemoryWarning(_onMemoryWarning); } _isListening = !_isListening; - GameManager.Instance.detailsController.ChangeInitialButtonText(_isListening ? "取消监听内存告警" : "开始监听内存告警"); + GameManager.Instance.detailsController.ChangeInitialButtonText( + _isListening ? "取消监听内存告警" : "开始监听内存告警" + ); } - public void scanCode() { - WX.ScanCode(new ScanCodeOption - { - onlyFromCamera = false, - scanType = new string[] {"barCode", "qrcode"}, - success = (res) => { - Debug.Log("success " + JsonMapper.ToJson(res)); - }, - fail = (res) => { - Debug.Log("fail" + res.errMsg); - }, - complete = (res) => { - Debug.Log("complete"); + public void scanCode() + { + WX.ScanCode( + new ScanCodeOption + { + onlyFromCamera = false, + scanType = new string[] { "barCode", "qrcode" }, + success = (res) => + { + Debug.Log("success " + JsonMapper.ToJson(res)); + }, + fail = (res) => + { + Debug.Log("fail" + res.errMsg); + }, + complete = (res) => + { + Debug.Log("complete"); + } } - }); + ); } - public void vibrateShort() { - WX.VibrateShort(new VibrateShortOption - { - type = "heavy", - success = (res) => { - Debug.Log("success "); - }, - fail = (res) => { - Debug.Log("fail" + res.errMsg); - }, - complete = (res) => { - Debug.Log("complete"); + public void vibrateShort() + { + WX.VibrateShort( + new VibrateShortOption + { + type = "heavy", + success = (res) => + { + Debug.Log("success "); + }, + fail = (res) => + { + Debug.Log("fail" + res.errMsg); + }, + complete = (res) => + { + Debug.Log("complete"); + } } - }); + ); } - public void vibrateLong() { - WX.VibrateLong(new VibrateLongOption - { - success = (res) => { - Debug.Log("success "); - }, - fail = (res) => { - Debug.Log("fail" + res.errMsg); - }, - complete = (res) => { - Debug.Log("complete"); + public void vibrateLong() + { + WX.VibrateLong( + new VibrateLongOption + { + success = (res) => + { + Debug.Log("success "); + }, + fail = (res) => + { + Debug.Log("fail" + res.errMsg); + }, + complete = (res) => + { + Debug.Log("complete"); + } } - }); + ); } - private void OnDestroy() { + private void OnDestroy() + { WX.OffMemoryWarning(_onMemoryWarning); } } - diff --git a/Demo/API_V2/Assets/API/Facility/Screen/Screen.cs b/Demo/API_V2/Assets/API/Facility/Screen/Screen.cs index 47c08b50f..376225d5d 100644 --- a/Demo/API_V2/Assets/API/Facility/Screen/Screen.cs +++ b/Demo/API_V2/Assets/API/Facility/Screen/Screen.cs @@ -6,38 +6,37 @@ public class Screen : Details { - private bool _isListening = false; private bool _isListening1 = false; private System.Random random = new System.Random(); - private readonly Action _onUserCaptureScreen = (res) => { - WX.ShowToast(new ShowToastOption - { - title = "截屏触发" - }); + private readonly Action _onUserCaptureScreen = (res) => + { + WX.ShowToast(new ShowToastOption { title = "截屏触发" }); var result = "_onUserCaptureScreen\n" + JsonMapper.ToJson(res); - GameManager.Instance.detailsController.AddResult(new ResultData() - { - initialContentText = result - }); + GameManager.Instance.detailsController.AddResult( + new ResultData() { initialContentText = result } + ); }; - private readonly Action _onScreenRecordingStateChanged = (res) => { - var result = "onScreenRecordingStateChanged\n" + JsonMapper.ToJson(res); - GameManager.Instance.detailsController.AddResult(new ResultData() + private readonly Action _onScreenRecordingStateChanged = + (res) => { - initialContentText = result - }); - }; - + var result = "onScreenRecordingStateChanged\n" + JsonMapper.ToJson(res); + GameManager.Instance.detailsController.AddResult( + new ResultData() { initialContentText = result } + ); + }; private void Start() { GameManager.Instance.detailsController.BindExtraButtonAction(0, setScreenBrightness); GameManager.Instance.detailsController.BindExtraButtonAction(1, setKeepScreenOn); GameManager.Instance.detailsController.BindExtraButtonAction(2, onUserCaptureScreen); - GameManager.Instance.detailsController.BindExtraButtonAction(3, onScreenRecordingStateChanged); + GameManager.Instance.detailsController.BindExtraButtonAction( + 3, + onScreenRecordingStateChanged + ); GameManager.Instance.detailsController.BindExtraButtonAction(4, getScreenRecordingState); GameManager.Instance.detailsController.BindExtraButtonAction(5, getScreenBrightness); } @@ -45,121 +44,179 @@ private void Start() // 测试 API protected override void TestAPI(string[] args) { - setVisualEffectOnCapture(); + setVisualEffectOnCapture(); } - public void setVisualEffectOnCapture() { - WX.SetVisualEffectOnCapture(new SetVisualEffectOnCaptureOption - { - visualEffect = "none", - success = (res) => { - WX.ShowToast(new ShowToastOption() + public void setVisualEffectOnCapture() + { + WX.SetVisualEffectOnCapture( + new SetVisualEffectOnCaptureOption + { + visualEffect = "none", + success = (res) => + { + WX.ShowToast( + new ShowToastOption() + { + title = "Access Success, Result: " + JsonMapper.ToJson(res) + } + ); + }, + fail = (res) => { - title = "Access Success, Result: " + JsonMapper.ToJson(res) - }); - }, - fail = (res) => { - Debug.Log("fail" + res.errMsg); - }, - complete = (res) => { - Debug.Log("complete"); + Debug.Log("fail" + res.errMsg); + }, + complete = (res) => + { + Debug.Log("complete"); + } } - }); - } + ); + } - public void setScreenBrightness() { - WX.SetScreenBrightness(new SetScreenBrightnessOption{ - value = random.NextDouble(), - success = (res) => { - WX.ShowToast(new ShowToastOption() + public void setScreenBrightness() + { + WX.SetScreenBrightness( + new SetScreenBrightnessOption + { + value = random.NextDouble(), + success = (res) => + { + WX.ShowToast( + new ShowToastOption() + { + title = "Access Success, Result: " + JsonMapper.ToJson(res) + } + ); + }, + fail = (res) => { - title = "Access Success, Result: " + JsonMapper.ToJson(res) - }); - }, - fail = (res) => { - Debug.Log("fail" + res.errMsg); - }, - complete = (res) => { - Debug.Log("complete"); + Debug.Log("fail" + res.errMsg); + }, + complete = (res) => + { + Debug.Log("complete"); + } } - }); + ); } - public void setKeepScreenOn() { - WX.SetKeepScreenOn(new SetKeepScreenOnOption{ - keepScreenOn = true, - success = (res) => { - WX.ShowToast(new ShowToastOption() + public void setKeepScreenOn() + { + WX.SetKeepScreenOn( + new SetKeepScreenOnOption + { + keepScreenOn = true, + success = (res) => + { + WX.ShowToast( + new ShowToastOption() + { + title = "Access Success, Result: " + JsonMapper.ToJson(res) + } + ); + }, + fail = (res) => + { + Debug.Log("fail" + res.errMsg); + }, + complete = (res) => { - title = "Access Success, Result: " + JsonMapper.ToJson(res) - }); - }, - fail = (res) => { - Debug.Log("fail" + res.errMsg); - }, - complete = (res) => { - Debug.Log("complete"); + Debug.Log("complete"); + } } - }); + ); } - public void onUserCaptureScreen() { - if (!_isListening) { + public void onUserCaptureScreen() + { + if (!_isListening) + { WX.OnUserCaptureScreen(_onUserCaptureScreen); - } else { + } + else + { WX.OffUserCaptureScreen(_onUserCaptureScreen); } _isListening = !_isListening; - GameManager.Instance.detailsController.ChangeExtraButtonText(2, _isListening ? "取消监听截屏" : "开始监听截屏"); + GameManager.Instance.detailsController.ChangeExtraButtonText( + 2, + _isListening ? "取消监听截屏" : "开始监听截屏" + ); } - public void onScreenRecordingStateChanged() { - if (!_isListening1) { + public void onScreenRecordingStateChanged() + { + if (!_isListening1) + { WX.OnScreenRecordingStateChanged(_onScreenRecordingStateChanged); - } else { + } + else + { WX.OffScreenRecordingStateChanged(_onScreenRecordingStateChanged); } _isListening1 = !_isListening1; - GameManager.Instance.detailsController.ChangeExtraButtonText(3, _isListening1 ? "取消监听录屏" : "开始监听录屏"); + GameManager.Instance.detailsController.ChangeExtraButtonText( + 3, + _isListening1 ? "取消监听录屏" : "开始监听录屏" + ); } - public void getScreenRecordingState() { - WX.GetScreenRecordingState(new GetScreenRecordingStateOption{ - success = (res) => { - WX.ShowModal(new ShowModalOption() + public void getScreenRecordingState() + { + WX.GetScreenRecordingState( + new GetScreenRecordingStateOption + { + success = (res) => + { + WX.ShowModal( + new ShowModalOption() + { + content = "Access Success, Result: " + JsonMapper.ToJson(res) + } + ); + }, + fail = (res) => { - content = "Access Success, Result: " + JsonMapper.ToJson(res) - }); - }, - fail = (res) => { - Debug.Log("fail" + res.errMsg); - }, - complete = (res) => { - Debug.Log("complete"); + Debug.Log("fail" + res.errMsg); + }, + complete = (res) => + { + Debug.Log("complete"); + } } - }); + ); } - public void getScreenBrightness() { - WX.GetScreenBrightness(new GetScreenBrightnessOption{ - success = (res) => { - WX.ShowModal(new ShowModalOption() + public void getScreenBrightness() + { + WX.GetScreenBrightness( + new GetScreenBrightnessOption + { + success = (res) => { - content = "Access Success, Result: " + JsonMapper.ToJson(res) - }); - }, - fail = (res) => { - Debug.Log("fail" + res.errMsg); - }, - complete = (res) => { - Debug.Log("complete"); + WX.ShowModal( + new ShowModalOption() + { + content = "Access Success, Result: " + JsonMapper.ToJson(res) + } + ); + }, + fail = (res) => + { + Debug.Log("fail" + res.errMsg); + }, + complete = (res) => + { + Debug.Log("complete"); + } } - }); + ); } - private void OnDestroy() { + private void OnDestroy() + { WX.OffUserCaptureScreen(_onUserCaptureScreen); WX.OffScreenRecordingStateChanged(_onScreenRecordingStateChanged); } } - diff --git a/Demo/API_V2/Assets/API/Facility/Touch/Touch.cs b/Demo/API_V2/Assets/API/Facility/Touch/Touch.cs index 241f81d88..068f0e503 100644 --- a/Demo/API_V2/Assets/API/Facility/Touch/Touch.cs +++ b/Demo/API_V2/Assets/API/Facility/Touch/Touch.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using LitJson; using UnityEngine; @@ -11,65 +11,68 @@ public class Touch : Details private static GameObject _squarePrefab; private static Dictionary _activeSquares; - + private readonly Action _onTouchStart = (res) => { var result = "Touch Start\n" + JsonMapper.ToJson(res); - GameManager.Instance.detailsController.AddResult(new ResultData() - { - initialContentText = result - }); - + GameManager.Instance.detailsController.AddResult( + new ResultData() { initialContentText = result } + ); + foreach (var touch in res.changedTouches) { - var square = Instantiate(_squarePrefab, GameManager.Instance.detailsController.transform); + var square = Instantiate( + _squarePrefab, + GameManager.Instance.detailsController.transform + ); square.transform.position = new Vector3(touch.clientX, touch.clientY, 0); _activeSquares.Add(touch.identifier, square); } }; - + private readonly Action _onTouchEnd = (res) => { var result = "Touch End\n" + JsonMapper.ToJson(res); - GameManager.Instance.detailsController.AddResult(new ResultData() - { - initialContentText = result - }); + GameManager.Instance.detailsController.AddResult( + new ResultData() { initialContentText = result } + ); foreach (var touch in res.changedTouches) { - if (!_activeSquares.ContainsKey(touch.identifier)) continue; - + if (!_activeSquares.ContainsKey(touch.identifier)) + continue; + var square = _activeSquares[touch.identifier]; Destroy(square); _activeSquares.Remove(touch.identifier); } }; - + private readonly Action _onTouchCancel = (res) => { var result = "Touch Cancel\n" + JsonMapper.ToJson(res); - GameManager.Instance.detailsController.AddResult(new ResultData() - { - initialContentText = result - }); - + GameManager.Instance.detailsController.AddResult( + new ResultData() { initialContentText = result } + ); + foreach (var touch in res.changedTouches) { - if (!_activeSquares.ContainsKey(touch.identifier)) continue; - + if (!_activeSquares.ContainsKey(touch.identifier)) + continue; + var square = _activeSquares[touch.identifier]; Destroy(square); _activeSquares.Remove(touch.identifier); } }; - + private readonly Action _OnTouchMove = (res) => { foreach (var touch in res.changedTouches) { - if (!_activeSquares.ContainsKey(touch.identifier)) continue; - + if (!_activeSquares.ContainsKey(touch.identifier)) + continue; + var square = _activeSquares[touch.identifier]; square.transform.position = new Vector3(touch.clientX, touch.clientY, 0); } @@ -80,7 +83,6 @@ private void Awake() _activeSquares = new Dictionary(); } - private void Start() { _squarePrefab = Resources.Load("Prefabs/Square"); @@ -106,7 +108,9 @@ protected override void TestAPI(string[] args) WX.OffTouchMove(_OnTouchMove); } _isListening = !_isListening; - GameManager.Instance.detailsController.ChangeInitialButtonText(_isListening ? "取消监听" : "开始监听"); + GameManager.Instance.detailsController.ChangeInitialButtonText( + _isListening ? "取消监听" : "开始监听" + ); } // 清除结果 @@ -114,7 +118,7 @@ private void ClearResults() { GameManager.Instance.detailsController.KeepFirstNResults(1); } - + private void OnDestroy() { WX.OffTouchStart(_onTouchStart); diff --git a/Demo/API_V2/Assets/API/FileSystem/Access/Access.cs b/Demo/API_V2/Assets/API/FileSystem/Access/Access.cs index 843930d39..a231ce694 100644 --- a/Demo/API_V2/Assets/API/FileSystem/Access/Access.cs +++ b/Demo/API_V2/Assets/API/FileSystem/Access/Access.cs @@ -1,16 +1,16 @@ -using LitJson; +using LitJson; using WeChatWASM; public class Access : Details { private WXFileSystemManager _fileSystemManager; - + // 路径 // 注意WX.env.USER_DATA_PATH后接字符串需要以/开头 private static readonly string PathPrefix = WX.env.USER_DATA_PATH + "/Access"; private static readonly string DictionaryPath = PathPrefix + "/exist"; private static readonly string FilePath = PathPrefix + "/exist/exist.txt"; - + private void Start() { // 获取全局唯一的文件管理器 @@ -21,20 +21,16 @@ private void Start() { _fileSystemManager.MkdirSync(DictionaryPath, true); } - + // 打开文件并写入数据 - var fd = _fileSystemManager.OpenSync(new OpenSyncOption() - { - filePath = FilePath, - flag = "w+" - }); - _fileSystemManager.WriteSync(new WriteSyncStringOption() - { - fd = fd, - data = "Original Data " - }); + var fd = _fileSystemManager.OpenSync( + new OpenSyncOption() { filePath = FilePath, flag = "w+" } + ); + _fileSystemManager.WriteSync( + new WriteSyncStringOption() { fd = fd, data = "Original Data " } + ); } - + // 测试 API protected override void TestAPI(string[] args) { @@ -47,39 +43,47 @@ protected override void TestAPI(string[] args) RunAsync(args[1]); // 异步执行 } } - + // 异步访问文件 private void RunAsync(string path) - { - _fileSystemManager.Access(new AccessParam() - { - path = PathPrefix + path, - success = (res) => + { + _fileSystemManager.Access( + new AccessParam() { - // 访问成功,显示结果 - WX.ShowModal(new ShowModalOption() + path = PathPrefix + path, + success = (res) => { - content = "Access Success, Result: " + JsonMapper.ToJson(res) - }); - }, - fail = (res) => - { - // 访问失败,显示结果 - WX.ShowModal(new ShowModalOption() + // 访问成功,显示结果 + WX.ShowModal( + new ShowModalOption() + { + content = "Access Success, Result: " + JsonMapper.ToJson(res) + } + ); + }, + fail = (res) => { - content = "Access Fail, Result: " + JsonMapper.ToJson(res) - }); + // 访问失败,显示结果 + WX.ShowModal( + new ShowModalOption() + { + content = "Access Fail, Result: " + JsonMapper.ToJson(res) + } + ); + } } - }); + ); } - + // 同步访问文件 private void RunSync(string path) { // 显示同步访问的结果 - WX.ShowModal(new ShowModalOption() - { - content = "AccessSync Result: " + _fileSystemManager.AccessSync(PathPrefix + path) - }); + WX.ShowModal( + new ShowModalOption() + { + content = "AccessSync Result: " + _fileSystemManager.AccessSync(PathPrefix + path) + } + ); } -} \ No newline at end of file +} diff --git a/Demo/API_V2/Assets/API/FileSystem/AppendFile/AppendFile.cs b/Demo/API_V2/Assets/API/FileSystem/AppendFile/AppendFile.cs index 7c4b95f9c..e99f345bf 100644 --- a/Demo/API_V2/Assets/API/FileSystem/AppendFile/AppendFile.cs +++ b/Demo/API_V2/Assets/API/FileSystem/AppendFile/AppendFile.cs @@ -1,67 +1,62 @@ -using System; +using System; using LitJson; using WeChatWASM; public class AppendFile : Details { private static WXFileSystemManager _fileSystemManager; - + // 路径 // 注意WX.env.USER_DATA_PATH后接字符串需要以/开头 private static readonly string PathPrefix = WX.env.USER_DATA_PATH + "/AppendFile"; private static readonly string Path = PathPrefix + "/hello.txt"; - + // 数据 private string _stringData = "String Data "; - private byte[] _bufferData = {66, 117, 102, 102, 101, 114, 32, 68, 97, 116, 97, 32}; - + private byte[] _bufferData = { 66, 117, 102, 102, 101, 114, 32, 68, 97, 116, 97, 32 }; + // 成功和失败的回调函数 private Action onSuccess = (res) => { // 显示成功的模态对话框 - WX.ShowModal(new ShowModalOption() - { - content = "AppendFile Success, Result: " + JsonMapper.ToJson(res) - }); + WX.ShowModal( + new ShowModalOption() + { + content = "AppendFile Success, Result: " + JsonMapper.ToJson(res) + } + ); UpdateResult(); // 更新结果 }; private Action onFail = (res) => { // 显示失败的模态对话框 - WX.ShowModal(new ShowModalOption() - { - content = "AppendFile Fail, Result: " + JsonMapper.ToJson(res) - }); + WX.ShowModal( + new ShowModalOption() { content = "AppendFile Fail, Result: " + JsonMapper.ToJson(res) } + ); }; - + private void Start() { // 获取全局唯一的文件管理器 _fileSystemManager = WX.GetFileSystemManager(); - + // 检查文件夹是否存在,如果不存在则创建 if (_fileSystemManager.AccessSync(PathPrefix) != "access:ok") { _fileSystemManager.MkdirSync(PathPrefix, true); } - + // 打开文件并写入数据 - var fd = _fileSystemManager.OpenSync(new OpenSyncOption() - { - filePath = Path, - flag = "w+" - }); - - _fileSystemManager.WriteSync(new WriteSyncStringOption() - { - fd = fd, - data = "Original Data " - }); + var fd = _fileSystemManager.OpenSync(new OpenSyncOption() { filePath = Path, flag = "w+" }); + + _fileSystemManager.WriteSync( + new WriteSyncStringOption() { fd = fd, data = "Original Data " } + ); // 绑定额外的按钮操作 GameManager.Instance.detailsController.BindExtraButtonAction(0, ResetFile); } - + // 测试 API protected override void TestAPI(string[] args) { @@ -74,7 +69,7 @@ protected override void TestAPI(string[] args) RunAsync(args[1], args[2]); // 异步执行 } } - + // 异步追加文件 private void RunAsync(string dataType, string encoding) { @@ -82,48 +77,56 @@ private void RunAsync(string dataType, string encoding) { if (encoding == "null") { - _fileSystemManager.AppendFile(new WriteFileParam() - { - filePath = Path, - data = _bufferData, - success = onSuccess, - fail = onFail - }); + _fileSystemManager.AppendFile( + new WriteFileParam() + { + filePath = Path, + data = _bufferData, + success = onSuccess, + fail = onFail + } + ); } else { - _fileSystemManager.AppendFile(new WriteFileParam() - { - filePath = Path, - data = _bufferData, - encoding = encoding, - success = onSuccess, - fail = onFail - }); + _fileSystemManager.AppendFile( + new WriteFileParam() + { + filePath = Path, + data = _bufferData, + encoding = encoding, + success = onSuccess, + fail = onFail + } + ); } } else { if (encoding == "null") { - _fileSystemManager.AppendFile(new WriteFileStringParam() - { - filePath = Path, - data = _stringData, - success = onSuccess, - fail = onFail - }); + _fileSystemManager.AppendFile( + new WriteFileStringParam() + { + filePath = Path, + data = _stringData, + success = onSuccess, + fail = onFail + } + ); } else { - _fileSystemManager.AppendFile(new WriteFileStringParam() - { - filePath = Path, - data = _stringData, - encoding = encoding, - success = onSuccess, - fail = onFail - }); + _fileSystemManager.AppendFile( + new WriteFileStringParam() + { + filePath = Path, + data = _stringData, + encoding = encoding, + success = onSuccess, + fail = onFail + } + ); } } } @@ -155,41 +158,32 @@ private void RunSync(string dataType, string encoding) } UpdateResult(); // 更新结果 - + // 显示成功的提示 - WX.ShowToast(new ShowToastOption() - { - title = "AppendFileSync Success" - }); + WX.ShowToast(new ShowToastOption() { title = "AppendFileSync Success" }); } // 更新文件内容显示结果 private static void UpdateResult() { - GameManager.Instance.detailsController.ChangeResultContent(0, _fileSystemManager.ReadFileSync(Path, "utf8")); + GameManager.Instance.detailsController.ChangeResultContent( + 0, + _fileSystemManager.ReadFileSync(Path, "utf8") + ); } // 重置文件内容 private void ResetFile() { // 重新打开文件并写入原始数据 - var fd = _fileSystemManager.OpenSync(new OpenSyncOption() - { - filePath = Path, - flag = "w+" - }); - _fileSystemManager.WriteSync(new WriteSyncStringOption() - { - fd = fd, - data = "Original Data " - }); - + var fd = _fileSystemManager.OpenSync(new OpenSyncOption() { filePath = Path, flag = "w+" }); + _fileSystemManager.WriteSync( + new WriteSyncStringOption() { fd = fd, data = "Original Data " } + ); + UpdateResult(); // 更新结果 - + // 显示已重置文件的提示 - WX.ShowToast(new ShowToastOption() - { - title = "已重置文件" - }); + WX.ShowToast(new ShowToastOption() { title = "已重置文件" }); } -} \ No newline at end of file +} diff --git a/Demo/API_V2/Assets/API/FileSystem/CopyFile/CopyFile.cs b/Demo/API_V2/Assets/API/FileSystem/CopyFile/CopyFile.cs index 691b967b1..ee1422c7d 100644 --- a/Demo/API_V2/Assets/API/FileSystem/CopyFile/CopyFile.cs +++ b/Demo/API_V2/Assets/API/FileSystem/CopyFile/CopyFile.cs @@ -1,41 +1,35 @@ -using LitJson; +using LitJson; using WeChatWASM; public class CopyFile : Details { private WXFileSystemManager _fileSystemManager; - + // 路径 // 注意WX.env.USER_DATA_PATH后接字符串需要以/开头 private static readonly string PathPrefix = WX.env.USER_DATA_PATH + "/CopyFile"; private static readonly string Path = PathPrefix + "/hello.txt"; private static readonly string SyncPath = PathPrefix + "/copyFileSync.txt"; private static readonly string AsyncPath = PathPrefix + "/copyFileAsync.txt"; - + private void Start() { // 获取全局唯一的文件管理器 _fileSystemManager = WX.GetFileSystemManager(); - + // 检查文件夹是否存在,如果不存在则创建 if (_fileSystemManager.AccessSync(PathPrefix) != "access:ok") { _fileSystemManager.MkdirSync(PathPrefix, true); } - + // 打开文件并写入数据 - var fd = _fileSystemManager.OpenSync(new OpenSyncOption() - { - filePath = Path, - flag = "w+" - }); - - _fileSystemManager.WriteSync(new WriteSyncStringOption() - { - fd = fd, - data = "Original Data " - }); - + var fd = _fileSystemManager.OpenSync(new OpenSyncOption() { filePath = Path, flag = "w+" }); + + _fileSystemManager.WriteSync( + new WriteSyncStringOption() { fd = fd, data = "Original Data " } + ); + // 如果复制的文件已存在,则删除 if (_fileSystemManager.AccessSync(SyncPath) == "access:ok") { @@ -49,7 +43,7 @@ private void Start() // 绑定额外的按钮操作 GameManager.Instance.detailsController.BindExtraButtonAction(0, ClearCopyFile); } - + // 测试 API protected override void TestAPI(string[] args) { @@ -62,47 +56,61 @@ protected override void TestAPI(string[] args) RunAsync(); // 异步执行 } } - + // 异步复制文件 private void RunAsync() { - _fileSystemManager.CopyFile(new CopyFileParam() - { - srcPath = Path, - destPath = AsyncPath, - success = (res) => + _fileSystemManager.CopyFile( + new CopyFileParam() { - // 显示成功的模态对话框 - WX.ShowModal(new ShowModalOption() + srcPath = Path, + destPath = AsyncPath, + success = (res) => { - content = "CopeFile Success, Result: " + JsonMapper.ToJson(res) - + "\nCopied File Content: " + _fileSystemManager.ReadFileSync(AsyncPath, "utf8") - }); - UpdateResults(); // 更新结果 - }, - fail = (res) => - { - // 显示失败的模态对话框 - WX.ShowModal(new ShowModalOption() + // 显示成功的模态对话框 + WX.ShowModal( + new ShowModalOption() + { + content = + "CopeFile Success, Result: " + + JsonMapper.ToJson(res) + + "\nCopied File Content: " + + _fileSystemManager.ReadFileSync(AsyncPath, "utf8") + } + ); + UpdateResults(); // 更新结果 + }, + fail = (res) => { - content = "CopyFile Fail, Result: " + JsonMapper.ToJson(res) - }); + // 显示失败的模态对话框 + WX.ShowModal( + new ShowModalOption() + { + content = "CopyFile Fail, Result: " + JsonMapper.ToJson(res) + } + ); + } } - }); + ); } // 同步复制文件 private void RunSync() { // 显示同步复制文件的结果 - WX.ShowModal(new ShowModalOption() - { - content = "CopyFileSync Result: " + _fileSystemManager.CopyFileSync(Path, SyncPath) - + "\nCopied File Content: " + _fileSystemManager.ReadFileSync(Path, "utf8") - }); + WX.ShowModal( + new ShowModalOption() + { + content = + "CopyFileSync Result: " + + _fileSystemManager.CopyFileSync(Path, SyncPath) + + "\nCopied File Content: " + + _fileSystemManager.ReadFileSync(Path, "utf8") + } + ); UpdateResults(); // 更新结果 } - + // 清除复制的文件 private void ClearCopyFile() { @@ -115,21 +123,27 @@ private void ClearCopyFile() { _fileSystemManager.UnlinkSync(AsyncPath); } - + UpdateResults(); // 更新结果 - + // 显示已清除复制文件的提示 - WX.ShowToast(new ShowToastOption() - { - title = "已清除复制文件" - }); + WX.ShowToast(new ShowToastOption() { title = "已清除复制文件" }); } - + // 更新结果显示 private void UpdateResults() { - GameManager.Instance.detailsController.SetResultActive(0, _fileSystemManager.AccessSync(Path) == "access:ok"); - GameManager.Instance.detailsController.SetResultActive(1, _fileSystemManager.AccessSync(SyncPath) == "access:ok"); - GameManager.Instance.detailsController.SetResultActive(2, _fileSystemManager.AccessSync(AsyncPath) == "access:ok"); + GameManager.Instance.detailsController.SetResultActive( + 0, + _fileSystemManager.AccessSync(Path) == "access:ok" + ); + GameManager.Instance.detailsController.SetResultActive( + 1, + _fileSystemManager.AccessSync(SyncPath) == "access:ok" + ); + GameManager.Instance.detailsController.SetResultActive( + 2, + _fileSystemManager.AccessSync(AsyncPath) == "access:ok" + ); } -} \ No newline at end of file +} diff --git a/Demo/API_V2/Assets/API/FileSystem/Fstat/Fstat.cs b/Demo/API_V2/Assets/API/FileSystem/Fstat/Fstat.cs index 535284d3a..a0ac4d0dd 100644 --- a/Demo/API_V2/Assets/API/FileSystem/Fstat/Fstat.cs +++ b/Demo/API_V2/Assets/API/FileSystem/Fstat/Fstat.cs @@ -1,19 +1,19 @@ -using LitJson; +using LitJson; using WeChatWASM; public class Fstat : Details { // 文件系统管理器 private WXFileSystemManager _fileSystemManager; - + // 文件路径 // 注意WX.env.USER_DATA_PATH后接字符串需要以/开头 private static readonly string PathPrefix = WX.env.USER_DATA_PATH + "/Fstat"; private static readonly string Path = PathPrefix + "/hello.txt"; - + // 文件描述符 private string _fd; - + // 在 Start 方法中初始化 private void Start() { @@ -25,21 +25,15 @@ private void Start() { _fileSystemManager.MkdirSync(PathPrefix, true); } - + // 打开文件,并将文件描述符存储在 _fd 变量中 - _fd = _fileSystemManager.OpenSync(new OpenSyncOption() - { - filePath = Path, - flag = "w+" - }); + _fd = _fileSystemManager.OpenSync(new OpenSyncOption() { filePath = Path, flag = "w+" }); // 向文件中写入原始数据 - _fileSystemManager.WriteSync(new WriteSyncStringOption() - { - fd = _fd, - data = "Original Data " - }); + _fileSystemManager.WriteSync( + new WriteSyncStringOption() { fd = _fd, data = "Original Data " } + ); } - + // 根据参数调用同步或异步方法 protected override void TestAPI(string[] args) { @@ -52,43 +46,52 @@ protected override void TestAPI(string[] args) RunAsync(); } } - + // 异步方法 private void RunAsync() - { + { // 调用 Fstat 方法获取文件信息 - _fileSystemManager.Fstat(new FstatOption() - { - fd = _fd, - success = (res) => + _fileSystemManager.Fstat( + new FstatOption() { - // 成功回调,显示文件信息 - WX.ShowModal(new ShowModalOption() + fd = _fd, + success = (res) => { - content = "Fstat Success, Result: " + JsonMapper.ToJson(res) - }); - }, - fail = (res) => - { - // 失败回调,显示错误信息 - WX.ShowModal(new ShowModalOption() + // 成功回调,显示文件信息 + WX.ShowModal( + new ShowModalOption() + { + content = "Fstat Success, Result: " + JsonMapper.ToJson(res) + } + ); + }, + fail = (res) => { - content = "Fstat Fail, Result: " + JsonMapper.ToJson(res) - }); + // 失败回调,显示错误信息 + WX.ShowModal( + new ShowModalOption() + { + content = "Fstat Fail, Result: " + JsonMapper.ToJson(res) + } + ); + } } - }); + ); } - + // 同步方法 private void RunSync() { // 调用 FstatSync 方法获取文件信息,并显示结果 - WX.ShowModal(new ShowModalOption() - { - content = "FstatSync Result: " + JsonMapper.ToJson(_fileSystemManager.FstatSync(new FstatSyncOption() + WX.ShowModal( + new ShowModalOption() { - fd = _fd - })) - }); + content = + "FstatSync Result: " + + JsonMapper.ToJson( + _fileSystemManager.FstatSync(new FstatSyncOption() { fd = _fd }) + ) + } + ); } -} \ No newline at end of file +} diff --git a/Demo/API_V2/Assets/API/FileSystem/FtruncateAndTruncate/FtruncateAndTruncate.cs b/Demo/API_V2/Assets/API/FileSystem/FtruncateAndTruncate/FtruncateAndTruncate.cs index 0fa53135b..7608ecea3 100644 --- a/Demo/API_V2/Assets/API/FileSystem/FtruncateAndTruncate/FtruncateAndTruncate.cs +++ b/Demo/API_V2/Assets/API/FileSystem/FtruncateAndTruncate/FtruncateAndTruncate.cs @@ -1,18 +1,18 @@ -using LitJson; +using LitJson; using WeChatWASM; public class FtruncateAndTruncate : Details { private WXFileSystemManager _fileSystemManager; - + // 文件路径 // 注意WX.env.USER_DATA_PATH后接字符串需要以/开头 private static readonly string PathPrefix = WX.env.USER_DATA_PATH + "/FtruncateAndTruncate"; private static readonly string Path = PathPrefix + "/hello.txt"; - + // 文件描述符 private string _fd; - + // 在 Start 方法中初始化 private void Start() { @@ -24,24 +24,18 @@ private void Start() { _fileSystemManager.MkdirSync(PathPrefix, true); } - + // 打开文件,并将文件描述符存储在 _fd 变量中 - _fd = _fileSystemManager.OpenSync(new OpenSyncOption() - { - filePath = Path, - flag = "w+" - }); + _fd = _fileSystemManager.OpenSync(new OpenSyncOption() { filePath = Path, flag = "w+" }); // 向文件中写入原始数据 - _fileSystemManager.WriteSync(new WriteSyncStringOption() - { - fd = _fd, - data = "Original Data " - }); - + _fileSystemManager.WriteSync( + new WriteSyncStringOption() { fd = _fd, data = "Original Data " } + ); + // 绑定还原按钮 GameManager.Instance.detailsController.BindExtraButtonAction(0, ResetFile); } - + // 根据参数调用截断文件的方法 protected override void TestAPI(string[] args) { @@ -58,7 +52,7 @@ protected override void TestAPI(string[] args) // 根据同步或异步模式调用 Ftruncate 方法 private void RunFtruncate(string mode, string length) { - if(mode == "同步执行") + if (mode == "同步执行") { RunFtruncateSync(length); } @@ -67,57 +61,58 @@ private void RunFtruncate(string mode, string length) RunFtruncateAsync(length); } } - + // 异步执行 Ftruncate 方法 private void RunFtruncateAsync(string length) - { - _fileSystemManager.Ftruncate(new FtruncateOption() - { - fd = _fd, - length = int.Parse(length), - success = (res) => + { + _fileSystemManager.Ftruncate( + new FtruncateOption() { - // 成功回调,显示文件截断成功信息 - WX.ShowModal(new ShowModalOption() + fd = _fd, + length = int.Parse(length), + success = (res) => { - content = "Ftruncate Success, Result: " + JsonMapper.ToJson(res) - }); - - UpdateResult(); - }, - fail = (res) => - { - // 失败回调,显示文件截断失败信息 - WX.ShowModal(new ShowModalOption() + // 成功回调,显示文件截断成功信息 + WX.ShowModal( + new ShowModalOption() + { + content = "Ftruncate Success, Result: " + JsonMapper.ToJson(res) + } + ); + + UpdateResult(); + }, + fail = (res) => { - content = "Ftruncate Fail, Result: " + JsonMapper.ToJson(res) - }); + // 失败回调,显示文件截断失败信息 + WX.ShowModal( + new ShowModalOption() + { + content = "Ftruncate Fail, Result: " + JsonMapper.ToJson(res) + } + ); + } } - }); + ); } - + // 同步执行 Ftruncate 方法 private void RunFtruncateSync(string length) { - _fileSystemManager.FtruncateSync(new FtruncateSyncOption() - { - fd = _fd, - length = int.Parse(length) - }); - + _fileSystemManager.FtruncateSync( + new FtruncateSyncOption() { fd = _fd, length = int.Parse(length) } + ); + UpdateResult(); - + // 显示文件截断成功提示 - WX.ShowToast(new ShowToastOption() - { - title = "FtruncateSync Success" - }); + WX.ShowToast(new ShowToastOption() { title = "FtruncateSync Success" }); } - + // 根据同步或异步模式调用 Truncate 方法 private void RunTruncate(string mode, string length) { - if(mode == "同步执行") + if (mode == "同步执行") { RunTruncateSync(length); } @@ -126,59 +121,62 @@ private void RunTruncate(string mode, string length) RunTruncateAsync(length); } } - + // 异步执行 Truncate 方法 private void RunTruncateAsync(string length) - { - _fileSystemManager.Truncate(new TruncateOption() - { - filePath = Path, - length = int.Parse(length), - success = (res) => + { + _fileSystemManager.Truncate( + new TruncateOption() { - // 成功回调,显示文件截断成功信息 - WX.ShowModal(new ShowModalOption() + filePath = Path, + length = int.Parse(length), + success = (res) => { - content = "Truncate Success, Result: " + JsonMapper.ToJson(res) - }); - - UpdateResult(); - }, - fail = (res) => - { - // 失败回调,显示文件截断失败信息 - WX.ShowModal(new ShowModalOption() + // 成功回调,显示文件截断成功信息 + WX.ShowModal( + new ShowModalOption() + { + content = "Truncate Success, Result: " + JsonMapper.ToJson(res) + } + ); + + UpdateResult(); + }, + fail = (res) => { - content = "Truncate Fail, Result: " + JsonMapper.ToJson(res) - }); + // 失败回调,显示文件截断失败信息 + WX.ShowModal( + new ShowModalOption() + { + content = "Truncate Fail, Result: " + JsonMapper.ToJson(res) + } + ); + } } - }); + ); } - + // 同步执行 Truncate 方法 private void RunTruncateSync(string length) { - _fileSystemManager.TruncateSync(new TruncateSyncOption() - { - filePath = Path, - length = int.Parse(length) - }); - + _fileSystemManager.TruncateSync( + new TruncateSyncOption() { filePath = Path, length = int.Parse(length) } + ); + // 更新结果 UpdateResult(); - + // 显示文件截断成功提示 - WX.ShowToast(new ShowToastOption() - { - title = "TruncateSync Success" - }); + WX.ShowToast(new ShowToastOption() { title = "TruncateSync Success" }); } // 更新结果 private void UpdateResult() { // 读取文件内容并更新结果 - GameManager.Instance.detailsController.resultObjects[0].GetComponent() + GameManager + .Instance.detailsController.resultObjects[0] + .GetComponent() .ChangeContent(_fileSystemManager.ReadFileSync(Path, "utf8")); } @@ -186,23 +184,14 @@ private void UpdateResult() private void ResetFile() { // 重新打开文件,并写入原始数据 - _fd = _fileSystemManager.OpenSync(new OpenSyncOption() - { - filePath = Path, - flag = "w+" - }); - _fileSystemManager.WriteSync(new WriteSyncStringOption() - { - fd = _fd, - data = "Original Data " - }); + _fd = _fileSystemManager.OpenSync(new OpenSyncOption() { filePath = Path, flag = "w+" }); + _fileSystemManager.WriteSync( + new WriteSyncStringOption() { fd = _fd, data = "Original Data " } + ); // 更新结果 UpdateResult(); - + // 显示文件已重置提示 - WX.ShowToast(new ShowToastOption() - { - title = "已重置文件" - }); + WX.ShowToast(new ShowToastOption() { title = "已重置文件" }); } -} \ No newline at end of file +} diff --git a/Demo/API_V2/Assets/API/FileSystem/LocalCacheFile/LocalCacheFile.cs b/Demo/API_V2/Assets/API/FileSystem/LocalCacheFile/LocalCacheFile.cs index bc19d2f21..e1ac96d41 100644 --- a/Demo/API_V2/Assets/API/FileSystem/LocalCacheFile/LocalCacheFile.cs +++ b/Demo/API_V2/Assets/API/FileSystem/LocalCacheFile/LocalCacheFile.cs @@ -1,10 +1,10 @@ -using LitJson; +using LitJson; using WeChatWASM; public class LocalCacheFile : Details { private WXFileSystemManager _fileSystemManager; - + // 在 Start 方法中初始化 private void Start() { @@ -16,200 +16,222 @@ private void Start() GameManager.Instance.detailsController.BindExtraButtonAction(1, ClearCacheFile); GameManager.Instance.detailsController.BindExtraButtonAction(2, GetCacheFileInfo); } - + // 刷新缓存文件列表 private void RefreshCacheFileList() { GameManager.Instance.detailsController.KeepFirstNResults(1); - + // 获取缓存文件列表 - _fileSystemManager.GetSavedFileList(new GetSavedFileListOption() - { - success = (res) => + _fileSystemManager.GetSavedFileList( + new GetSavedFileListOption() { - // 可视化展示 - foreach (var file in res.fileList) + success = (res) => { - var content = "创建时间:" + file.createTime + "\n" + - "文件大小:" + file.size + "\n" + - "文件路径:" + file.filePath; - GameManager.Instance.detailsController.AddResult(new ResultData() + // 可视化展示 + foreach (var file in res.fileList) { - initialContentText = content - }); - } - }, - fail = (res) => - { - WX.ShowModal(new ShowModalOption() + var content = + "创建时间:" + + file.createTime + + "\n" + + "文件大小:" + + file.size + + "\n" + + "文件路径:" + + file.filePath; + GameManager.Instance.detailsController.AddResult( + new ResultData() { initialContentText = content } + ); + } + }, + fail = (res) => { - content = "GetSavedFileList Fail, Result: " + JsonMapper.ToJson(res) - }); + WX.ShowModal( + new ShowModalOption() + { + content = "GetSavedFileList Fail, Result: " + JsonMapper.ToJson(res) + } + ); + } } - }); + ); } - + // 测试API方法 protected override void TestAPI(string[] args) { RefreshCacheFileList(); - WX.ShowToast(new ShowToastOption() - { - title = "刷新缓存文件列表成功" - }); + WX.ShowToast(new ShowToastOption() { title = "刷新缓存文件列表成功" }); } - + // 生成缓存文件 private void GenerateCacheFile() { - WX.ShowLoading(new ShowLoadingOption() - { - title = "下载临时文件中", - mask = true - }); + WX.ShowLoading(new ShowLoadingOption() { title = "下载临时文件中", mask = true }); // 由DownloadFile接口生成临时文件路径 - WX.DownloadFile(new DownloadFileOption() - { - url = "https://res.wx.qq.com/wechatgame/product/webpack/userupload/20190813/advideo.MP4", - success = (res) => + WX.DownloadFile( + new DownloadFileOption() { - WX.HideLoading(new HideLoadingOption()); - WX.ShowLoading(new ShowLoadingOption() - { - title = "缓存文件中", - mask = true - }); - // 将临时文件保存为缓存文件,注意不填写filePath参数才会保存为缓存文件 - _fileSystemManager.SaveFile(new SaveFileOption() + url = + "https://res.wx.qq.com/wechatgame/product/webpack/userupload/20190813/advideo.MP4", + success = (res) => { - tempFilePath = res.tempFilePath, - success = (res2) => - { - WX.HideLoading(new HideLoadingOption()); - RefreshCacheFileList(); - WX.ShowToast(new ShowToastOption() - { - title = "生成缓存文件成功" - }); - }, - fail = (res2) => - { - WX.HideLoading(new HideLoadingOption()); - WX.ShowModal(new ShowModalOption() + WX.HideLoading(new HideLoadingOption()); + WX.ShowLoading(new ShowLoadingOption() { title = "缓存文件中", mask = true }); + // 将临时文件保存为缓存文件,注意不填写filePath参数才会保存为缓存文件 + _fileSystemManager.SaveFile( + new SaveFileOption() { - content = "SaveFile Fail, Result: " + JsonMapper.ToJson(res2) - }); - } - }); - - }, - fail = (res) => - { - WX.HideLoading(new HideLoadingOption()); - WX.ShowModal(new ShowModalOption() + tempFilePath = res.tempFilePath, + success = (res2) => + { + WX.HideLoading(new HideLoadingOption()); + RefreshCacheFileList(); + WX.ShowToast(new ShowToastOption() { title = "生成缓存文件成功" }); + }, + fail = (res2) => + { + WX.HideLoading(new HideLoadingOption()); + WX.ShowModal( + new ShowModalOption() + { + content = + "SaveFile Fail, Result: " + JsonMapper.ToJson(res2) + } + ); + } + } + ); + }, + fail = (res) => { - content = "DownloadFile Fail, Result: " + JsonMapper.ToJson(res) - }); + WX.HideLoading(new HideLoadingOption()); + WX.ShowModal( + new ShowModalOption() + { + content = "DownloadFile Fail, Result: " + JsonMapper.ToJson(res) + } + ); + } } - }); + ); } // 清空缓存文件 private void ClearCacheFile() { // 获取缓存文件列表 - _fileSystemManager.GetSavedFileList(new GetSavedFileListOption() - { - success = (res) => + _fileSystemManager.GetSavedFileList( + new GetSavedFileListOption() { - for (var i = 0; i < res.fileList.Length; i++) + success = (res) => { - // 移除单个缓存文件 - var i1 = i; - _fileSystemManager.RemoveSavedFile(new RemoveSavedFileOption() + for (var i = 0; i < res.fileList.Length; i++) { - filePath = res.fileList[i].filePath, - success = (res2) => - { - if (i1 == res.fileList.Length - 1) + // 移除单个缓存文件 + var i1 = i; + _fileSystemManager.RemoveSavedFile( + new RemoveSavedFileOption() { - RefreshCacheFileList(); - WX.ShowToast(new ShowToastOption() + filePath = res.fileList[i].filePath, + success = (res2) => + { + if (i1 == res.fileList.Length - 1) + { + RefreshCacheFileList(); + WX.ShowToast(new ShowToastOption() { title = "清空缓存文件成功" }); + } + }, + fail = (res2) => { - title = "清空缓存文件成功" - }); + WX.ShowModal( + new ShowModalOption() + { + content = + "RemoveSavedFile Fail, Result: " + + JsonMapper.ToJson(res2) + } + ); + } } - }, - fail = (res2) => + ); + } + }, + fail = (res) => + { + WX.ShowModal( + new ShowModalOption() { - WX.ShowModal(new ShowModalOption() - { - content = "RemoveSavedFile Fail, Result: " + JsonMapper.ToJson(res2) - }); + content = "GetSavedFileList Fail, Result: " + JsonMapper.ToJson(res) } - }); + ); } - }, - fail = (res) => - { - WX.ShowModal(new ShowModalOption() - { - content = "GetSavedFileList Fail, Result: " + JsonMapper.ToJson(res) - }); } - }); + ); } - + // 获取缓存文件信息 private void GetCacheFileInfo() { // 获取缓存文件列表 - _fileSystemManager.GetSavedFileList(new GetSavedFileListOption() - { - success = (res) => + _fileSystemManager.GetSavedFileList( + new GetSavedFileListOption() { - if (res.fileList.Length == 0) + success = (res) => { - // 如果没有缓存文件,提示用户 - WX.ShowModal(new ShowModalOption() + if (res.fileList.Length == 0) { - content = "请先生成缓存文件!" - }); - } - else - { - // 获取第一个缓存文件的文件信息 - _fileSystemManager.GetFileInfo(new GetFileInfoOption() + // 如果没有缓存文件,提示用户 + WX.ShowModal(new ShowModalOption() { content = "请先生成缓存文件!" }); + } + else { - // 路径可以是代码包绝对路径、本地临时路径、本地路径和本地缓存路径 - filePath = res.fileList[0].filePath, - success = (res2) => - { - // 显示文件信息 - WX.ShowModal(new ShowModalOption() + // 获取第一个缓存文件的文件信息 + _fileSystemManager.GetFileInfo( + new GetFileInfoOption() { - content = "GetFileInfo Success, Result: " + JsonMapper.ToJson(res2) - }); - }, - fail = (res2) => + // 路径可以是代码包绝对路径、本地临时路径、本地路径和本地缓存路径 + filePath = res.fileList[0].filePath, + success = (res2) => + { + // 显示文件信息 + WX.ShowModal( + new ShowModalOption() + { + content = + "GetFileInfo Success, Result: " + + JsonMapper.ToJson(res2) + } + ); + }, + fail = (res2) => + { + // 显示错误信息 + WX.ShowModal( + new ShowModalOption() + { + content = + "GetFileInfo Fail, Result: " + + JsonMapper.ToJson(res2) + } + ); + } + } + ); + } + }, + fail = (res) => + { + // 显示错误信息 + WX.ShowModal( + new ShowModalOption() { - // 显示错误信息 - WX.ShowModal(new ShowModalOption() - { - content = "GetFileInfo Fail, Result: " + JsonMapper.ToJson(res2) - }); + content = "GetSavedFileList Fail, Result: " + JsonMapper.ToJson(res) } - }); + ); } - }, - fail = (res) => - { - // 显示错误信息 - WX.ShowModal(new ShowModalOption() - { - content = "GetSavedFileList Fail, Result: " + JsonMapper.ToJson(res) - }); } - }); + ); } -} \ No newline at end of file +} diff --git a/Demo/API_V2/Assets/API/FileSystem/MkdirAndRmdir/MkdirAndRmdir.cs b/Demo/API_V2/Assets/API/FileSystem/MkdirAndRmdir/MkdirAndRmdir.cs index 7c605b8e4..59432aaed 100644 --- a/Demo/API_V2/Assets/API/FileSystem/MkdirAndRmdir/MkdirAndRmdir.cs +++ b/Demo/API_V2/Assets/API/FileSystem/MkdirAndRmdir/MkdirAndRmdir.cs @@ -1,22 +1,22 @@ -using LitJson; +using LitJson; using WeChatWASM; public class MkdirAndRmdir : Details { private WXFileSystemManager _fileSystemManager; - + // 路径 // 注意WX.env.USER_DATA_PATH后接字符串需要以/开头 private static readonly string PathPrefix = WX.env.USER_DATA_PATH + "/MkdirAndRmdir"; private static readonly string PathA = PathPrefix + "/a"; private static readonly string PathB = PathPrefix + "/a/b"; - + // 在 Start 方法中初始化 private void Start() { // 获取全局唯一的文件管理器 _fileSystemManager = WX.GetFileSystemManager(); - + // 检查并创建目录 if (_fileSystemManager.AccessSync(PathPrefix) != "access:ok") { @@ -32,7 +32,7 @@ private void Start() // 绑定按钮事件 GameManager.Instance.detailsController.BindExtraButtonAction(0, RmDir); } - + // 创建目录 protected override void TestAPI(string[] args) { @@ -45,7 +45,7 @@ protected override void TestAPI(string[] args) MkdirAsync(args[1], args[2]); } } - + // 删除目录 private void RmDir() { @@ -62,78 +62,104 @@ private void RmDir() // 同步创建目录 private void MkdirSync(string dirPath, string recursive) { - WX.ShowModal(new ShowModalOption() - { - content = "MkdirSync Result: " + _fileSystemManager.MkdirSync(PathPrefix + dirPath, recursive == "true") - }); + WX.ShowModal( + new ShowModalOption() + { + content = + "MkdirSync Result: " + + _fileSystemManager.MkdirSync(PathPrefix + dirPath, recursive == "true") + } + ); UpdateResult(); } // 异步创建目录 private void MkdirAsync(string dirPath, string recursive) { - _fileSystemManager.Mkdir(new MkdirParam() - { - dirPath = PathPrefix + dirPath, - recursive = recursive == "true", - success = (res) => + _fileSystemManager.Mkdir( + new MkdirParam() { - WX.ShowModal(new ShowModalOption() + dirPath = PathPrefix + dirPath, + recursive = recursive == "true", + success = (res) => { - content = "MkdirAsync Success, Result: " + JsonMapper.ToJson(res) - }); - UpdateResult(); - }, - fail = (res) => - { - WX.ShowModal(new ShowModalOption() + WX.ShowModal( + new ShowModalOption() + { + content = "MkdirAsync Success, Result: " + JsonMapper.ToJson(res) + } + ); + UpdateResult(); + }, + fail = (res) => { - content = "MkdirAsync Fail, Result: " + JsonMapper.ToJson(res) - }); + WX.ShowModal( + new ShowModalOption() + { + content = "MkdirAsync Fail, Result: " + JsonMapper.ToJson(res) + } + ); + } } - }); + ); } - + // 同步删除目录 private void RmdirSync(string dirPath, string recursive) { - WX.ShowModal(new ShowModalOption() - { - content = "RmdirSync Result: " + _fileSystemManager.RmdirSync(PathPrefix + dirPath, recursive == "true") - }); - + WX.ShowModal( + new ShowModalOption() + { + content = + "RmdirSync Result: " + + _fileSystemManager.RmdirSync(PathPrefix + dirPath, recursive == "true") + } + ); + UpdateResult(); } - + // 异步删除目录 private void RmdirAsync(string dirPath, string recursive) { - _fileSystemManager.Rmdir(new RmdirParam() - { - dirPath = PathPrefix + dirPath, - recursive = recursive == "true", - success = (res) => + _fileSystemManager.Rmdir( + new RmdirParam() { - WX.ShowModal(new ShowModalOption() + dirPath = PathPrefix + dirPath, + recursive = recursive == "true", + success = (res) => { - content = "RmdirAsync Success, Result: " + JsonMapper.ToJson(res) - }); - UpdateResult(); - }, - fail = (res) => - { - WX.ShowModal(new ShowModalOption() + WX.ShowModal( + new ShowModalOption() + { + content = "RmdirAsync Success, Result: " + JsonMapper.ToJson(res) + } + ); + UpdateResult(); + }, + fail = (res) => { - content = "RmdirAsync Fail, Result: " + JsonMapper.ToJson(res) - }); + WX.ShowModal( + new ShowModalOption() + { + content = "RmdirAsync Fail, Result: " + JsonMapper.ToJson(res) + } + ); + } } - }); + ); } // 更新结果 private void UpdateResult() { - GameManager.Instance.detailsController.SetResultActive(0, _fileSystemManager.AccessSync(PathA) == "access:ok"); - GameManager.Instance.detailsController.SetResultActive(1, _fileSystemManager.AccessSync(PathB) == "access:ok"); + GameManager.Instance.detailsController.SetResultActive( + 0, + _fileSystemManager.AccessSync(PathA) == "access:ok" + ); + GameManager.Instance.detailsController.SetResultActive( + 1, + _fileSystemManager.AccessSync(PathB) == "access:ok" + ); } -} \ No newline at end of file +} diff --git a/Demo/API_V2/Assets/API/FileSystem/OpenAndClose/OpenAndClose.cs b/Demo/API_V2/Assets/API/FileSystem/OpenAndClose/OpenAndClose.cs index 8fca8133e..99aded853 100644 --- a/Demo/API_V2/Assets/API/FileSystem/OpenAndClose/OpenAndClose.cs +++ b/Demo/API_V2/Assets/API/FileSystem/OpenAndClose/OpenAndClose.cs @@ -1,26 +1,26 @@ -using System; +using System; using LitJson; using WeChatWASM; public class OpenAndClose : Details { private WXFileSystemManager _fileSystemManager; - + // 路径 // 注意WX.env.USER_DATA_PATH后接字符串需要以/开头 private static readonly string PathPrefix = WX.env.USER_DATA_PATH + "/OpenAndClose"; private static readonly string Path1 = PathPrefix + "/exist.txt"; private static readonly string Path2 = PathPrefix + "/notExist.txt"; - + // 文件描述符 private string[] _fd; - + // 在 Start 方法中初始化 private void Start() { // 获取全局唯一的文件管理器 _fileSystemManager = WX.GetFileSystemManager(); - + // 检查并创建目录 if (_fileSystemManager.AccessSync(PathPrefix) != "access:ok") { @@ -29,32 +29,28 @@ private void Start() // 初始化文件描述符数组 _fd = new string[2]; - var fd = _fileSystemManager.OpenSync(new OpenSyncOption() - { - filePath = Path1, - flag = "w+" - }); - _fileSystemManager.WriteSync(new WriteSyncStringOption() - { - fd = fd, - data = "Original Data " - }); - + var fd = _fileSystemManager.OpenSync( + new OpenSyncOption() { filePath = Path1, flag = "w+" } + ); + _fileSystemManager.WriteSync( + new WriteSyncStringOption() { fd = fd, data = "Original Data " } + ); + // 如果文件存在,则删除 if (_fileSystemManager.AccessSync(Path2) == "access:ok") { _fileSystemManager.UnlinkSync(Path2); } - + // 绑定按钮事件 GameManager.Instance.detailsController.BindExtraButtonAction(0, Close); GameManager.Instance.detailsController.BindExtraButtonAction(1, ResetDetails); } - + // 打开文件 protected override void TestAPI(string[] args) { - if(args[0] == "同步执行") + if (args[0] == "同步执行") { OpenSync(args[1], args[2]); } @@ -63,7 +59,7 @@ protected override void TestAPI(string[] args) OpenAsync(args[1], args[2]); } } - + // 关闭文件 private void Close() { @@ -76,39 +72,32 @@ private void Close() CloseAsync(options[1]); } } - + // 重置 private void ResetDetails() { // 重置文件描述符数组 _fd = new string[2]; - var fd = _fileSystemManager.OpenSync(new OpenSyncOption() - { - filePath = Path1, - flag = "w+" - }); - _fileSystemManager.WriteSync(new WriteSyncStringOption() - { - fd = fd, - data = "Original Data " - }); - + var fd = _fileSystemManager.OpenSync( + new OpenSyncOption() { filePath = Path1, flag = "w+" } + ); + _fileSystemManager.WriteSync( + new WriteSyncStringOption() { fd = fd, data = "Original Data " } + ); + // 如果文件存在,则删除 if (_fileSystemManager.AccessSync(Path2) == "access:ok") { _fileSystemManager.UnlinkSync(Path2); } - + // 更新结果 UpdateResults(); GameManager.Instance.detailsController.SetResultActive(3, false); GameManager.Instance.detailsController.SetResultActive(4, false); - + // 显示已重置提示 - WX.ShowToast(new ShowToastOption() - { - title = "已重置" - }); + WX.ShowToast(new ShowToastOption() { title = "已重置" }); } // 同步打开文件 @@ -118,109 +107,120 @@ private void OpenSync(string filePath, string flag) try { - _fd[index] = _fileSystemManager.OpenSync(new OpenSyncOption() - { - filePath = PathPrefix + filePath, - flag = flag == "null" ? null : flag - }); + _fd[index] = _fileSystemManager.OpenSync( + new OpenSyncOption() + { + filePath = PathPrefix + filePath, + flag = flag == "null" ? null : flag + } + ); } catch (Exception e) { - WX.ShowModal(new ShowModalOption() - { - content = "OpenSync Fail, Exception: " + e.Message - }); + WX.ShowModal( + new ShowModalOption() { content = "OpenSync Fail, Exception: " + e.Message } + ); return; } // 更新结果 GameManager.Instance.detailsController.SetResultActive(index + 3, true); - + // 显示打开文件成功提示 - WX.ShowModal(new ShowModalOption() - { - content = "OpenSync Success, fd: " + _fd[index] - }); + WX.ShowModal(new ShowModalOption() { content = "OpenSync Success, fd: " + _fd[index] }); } - + // 异步打开文件 private void OpenAsync(string filePath, string flag) { var index = filePath == "/exist.txt" ? 0 : 1; - - _fileSystemManager.Open(new OpenOption() - { - filePath = filePath, - flag = flag == "null" ? null : flag, - success = (res) => - { - _fd[index] = res.fd; - GameManager.Instance.detailsController.SetResultActive(index + 3, true); - WX.ShowModal(new ShowModalOption() { - content = "Open Success, Result: " + JsonMapper.ToJson(res) - }); - }, - fail = (res) => + + _fileSystemManager.Open( + new OpenOption() { - WX.ShowModal(new ShowModalOption() + filePath = filePath, + flag = flag == "null" ? null : flag, + success = (res) => { - content = "Open Fail, Result: " + JsonMapper.ToJson(res) - }); + _fd[index] = res.fd; + GameManager.Instance.detailsController.SetResultActive(index + 3, true); + WX.ShowModal( + new ShowModalOption() + { + content = "Open Success, Result: " + JsonMapper.ToJson(res) + } + ); + }, + fail = (res) => + { + WX.ShowModal( + new ShowModalOption() + { + content = "Open Fail, Result: " + JsonMapper.ToJson(res) + } + ); + } } - }); + ); } - + // 同步关闭文件 private void CloseSync(string filePath) { var index = filePath == "/exist.txt" ? 0 : 1; - - _fileSystemManager.CloseSync(new CloseSyncOption() - { - fd = _fd[index] - }); - + + _fileSystemManager.CloseSync(new CloseSyncOption() { fd = _fd[index] }); + // 更新结果 GameManager.Instance.detailsController.SetResultActive(index + 3, false); - + // 显示关闭文件成功提示 - WX.ShowToast(new ShowToastOption() - { - title = "CloseSync Success" - }); + WX.ShowToast(new ShowToastOption() { title = "CloseSync Success" }); } - + // 异步关闭文件 private void CloseAsync(string filePath) { var index = filePath == "/exist.txt" ? 0 : 1; - - _fileSystemManager.Close(new FileSystemManagerCloseOption() - { - fd = _fd[index], - success = (res) => + + _fileSystemManager.Close( + new FileSystemManagerCloseOption() { - // 更新结果 - GameManager.Instance.detailsController.SetResultActive(index + 3, false); - WX.ShowModal(new ShowModalOption() + fd = _fd[index], + success = (res) => { - content = "Close Success, Result: " + JsonMapper.ToJson(res) - }); - }, - fail = (res) => - { - WX.ShowModal(new ShowModalOption() + // 更新结果 + GameManager.Instance.detailsController.SetResultActive(index + 3, false); + WX.ShowModal( + new ShowModalOption() + { + content = "Close Success, Result: " + JsonMapper.ToJson(res) + } + ); + }, + fail = (res) => { - content = "Close Fail, Result: " + JsonMapper.ToJson(res) - }); + WX.ShowModal( + new ShowModalOption() + { + content = "Close Fail, Result: " + JsonMapper.ToJson(res) + } + ); + } } - }); + ); } // 更新结果 private void UpdateResults() { - GameManager.Instance.detailsController.SetResultActive(0, _fileSystemManager.AccessSync(Path1) == "access:ok"); - GameManager.Instance.detailsController.SetResultActive(1, _fileSystemManager.AccessSync(Path1) == "access:ok"); + GameManager.Instance.detailsController.SetResultActive( + 0, + _fileSystemManager.AccessSync(Path1) == "access:ok" + ); + GameManager.Instance.detailsController.SetResultActive( + 1, + _fileSystemManager.AccessSync(Path1) == "access:ok" + ); } -} \ No newline at end of file +} diff --git a/Demo/API_V2/Assets/API/FileSystem/ReadAndWrite/ReadAndWrite.cs b/Demo/API_V2/Assets/API/FileSystem/ReadAndWrite/ReadAndWrite.cs index 71f0c6b46..c85452921 100644 --- a/Demo/API_V2/Assets/API/FileSystem/ReadAndWrite/ReadAndWrite.cs +++ b/Demo/API_V2/Assets/API/FileSystem/ReadAndWrite/ReadAndWrite.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Text; using LitJson; using UnityEngine; @@ -7,45 +7,43 @@ public class ReadAndWrite : Details { private static WXFileSystemManager _fileSystemManager; - + // 路径 // 注意WX.env.USER_DATA_PATH后接字符串需要以/开头 private static readonly string PathPrefix = WX.env.USER_DATA_PATH + "/ReadAndWrite"; private static readonly string Path = PathPrefix + "/hello.txt"; - + // 用于读取数据的缓存 private byte[] _buffer; - + // 文件描述符 private string _fd; - + // 数据 private string _stringData = "String Data "; - private byte[] _bufferData = {66, 117, 102, 102, 101, 114, 32, 68, 97, 116, 97, 32}; - + private byte[] _bufferData = { 66, 117, 102, 102, 101, 114, 32, 68, 97, 116, 97, 32 }; + // 回调函数 private Action onWriteSuccess = (res) => { UpdateFileContent(); - WX.ShowModal(new ShowModalOption() - { - content = "Write Success, Result: " + JsonMapper.ToJson(res) - }); + WX.ShowModal( + new ShowModalOption() { content = "Write Success, Result: " + JsonMapper.ToJson(res) } + ); }; private Action onWriteFail = (res) => { - WX.ShowModal(new ShowModalOption() - { - content = "Write Fail, Result: " + JsonMapper.ToJson(res) - }); + WX.ShowModal( + new ShowModalOption() { content = "Write Fail, Result: " + JsonMapper.ToJson(res) } + ); }; - + // 在 Start 方法中初始化 private void Start() { // 获取全局唯一的文件管理器 _fileSystemManager = WX.GetFileSystemManager(); - + // 检查并创建目录 if (_fileSystemManager.AccessSync(PathPrefix) != "access:ok") { @@ -53,17 +51,11 @@ private void Start() } // 打开文件,并写入初始数据 - _fd = _fileSystemManager.OpenSync(new OpenSyncOption() - { - filePath = Path, - flag = "w+" - }); - - _fileSystemManager.WriteSync(new WriteSyncStringOption() - { - fd = _fd, - data = "Original Data " - }); + _fd = _fileSystemManager.OpenSync(new OpenSyncOption() { filePath = Path, flag = "w+" }); + + _fileSystemManager.WriteSync( + new WriteSyncStringOption() { fd = _fd, data = "Original Data " } + ); // 绑定按钮事件 GameManager.Instance.detailsController.BindExtraButtonAction(0, Write); @@ -74,7 +66,7 @@ private void Start() protected override void TestAPI(string[] args) { _buffer = new byte[20]; - + // 根据参数决定执行同步读取还是异步读取 if (args[0] == "同步执行") { @@ -85,7 +77,7 @@ protected override void TestAPI(string[] args) ReadAsync(args[2], args[3], args[5]); } } - + // 写入文件 private void Write() { @@ -99,135 +91,160 @@ private void Write() WriteAsync(options[1], options[2], options[3], options[4], options[5]); } } + /***** Buttons *****/ // 同步读取 private void ReadSync(string offset, string length, string position) { - WX.ShowModal(new ShowModalOption() - { - content = "ReadSync接口暂无法正常使用" - }); + WX.ShowModal(new ShowModalOption() { content = "ReadSync接口暂无法正常使用" }); return; - var readResult = _fileSystemManager.ReadSync(new ReadSyncOption() - { - arrayBuffer = _buffer, - fd = _fd, - length = length == "null" ? null : (double?)int.Parse(length), - offset = offset == "null" ? null : (double?)int.Parse(offset), - position = position == "null" ? null : (double?)int.Parse(position) - }); - + var readResult = _fileSystemManager.ReadSync( + new ReadSyncOption() + { + arrayBuffer = _buffer, + fd = _fd, + length = length == "null" ? null : (double?)int.Parse(length), + offset = offset == "null" ? null : (double?)int.Parse(offset), + position = position == "null" ? null : (double?)int.Parse(position) + } + ); + // 更新读取结果 UpdateReadResult(); - WX.ShowToast(new ShowToastOption() - { - title = "ReadSync Success" - }); - + WX.ShowToast(new ShowToastOption() { title = "ReadSync Success" }); + // 下列buffer为同一份引用 Debug.Log("option buffer: " + JsonMapper.ToJson(_buffer)); Debug.Log("result buffer: " + JsonMapper.ToJson(readResult.arrayBuffer)); } - + // 异步读取 private void ReadAsync(string offset, string length, string position) { - _fileSystemManager.Read(new ReadOption() - { - arrayBuffer = _buffer, - fd = _fd, - length = length == "null" ? null : (double?)int.Parse(length), - offset = offset == "null" ? null : (double?)int.Parse(offset), - position = position == "null" ? null : (double?)int.Parse(position), - success = (res) => + _fileSystemManager.Read( + new ReadOption() { - // 更新读取结果 - UpdateReadResult(); - WX.ShowModal(new ShowModalOption() + arrayBuffer = _buffer, + fd = _fd, + length = length == "null" ? null : (double?)int.Parse(length), + offset = offset == "null" ? null : (double?)int.Parse(offset), + position = position == "null" ? null : (double?)int.Parse(position), + success = (res) => { - content = "Read Success, bytesRead: " + res.bytesRead - }); - // 下列buffer为同一份引用 - // Debug.Log("option buffer: " + JsonMapper.ToJson(_buffer)); - // Debug.Log("result buffer: " + JsonMapper.ToJson(res.arrayBuffer)); - }, - fail = (res) => - { - WX.ShowModal(new ShowModalOption() + // 更新读取结果 + UpdateReadResult(); + WX.ShowModal( + new ShowModalOption() + { + content = "Read Success, bytesRead: " + res.bytesRead + } + ); + // 下列buffer为同一份引用 + // Debug.Log("option buffer: " + JsonMapper.ToJson(_buffer)); + // Debug.Log("result buffer: " + JsonMapper.ToJson(res.arrayBuffer)); + }, + fail = (res) => { - content = "Read Fail, Result: " + JsonMapper.ToJson(res) - }); + WX.ShowModal( + new ShowModalOption() + { + content = "Read Fail, Result: " + JsonMapper.ToJson(res) + } + ); + } } - }); + ); } // 同步写入 - private void WriteSync(string dataType, string offset, string length, string encoding, string position) + private void WriteSync( + string dataType, + string offset, + string length, + string encoding, + string position + ) { WriteResult writeResult; if (dataType == "string") { - writeResult = _fileSystemManager.WriteSync(new WriteSyncStringOption() - { - data = _stringData, - fd = _fd, - encoding = encoding == "null" ? null : encoding, - length = length == "null" ? null : (double?)int.Parse(length), - offset = offset == "null" ? null : (double?)int.Parse(offset), - position = position == "null" ? null : (double?)int.Parse(position) - }); + writeResult = _fileSystemManager.WriteSync( + new WriteSyncStringOption() + { + data = _stringData, + fd = _fd, + encoding = encoding == "null" ? null : encoding, + length = length == "null" ? null : (double?)int.Parse(length), + offset = offset == "null" ? null : (double?)int.Parse(offset), + position = position == "null" ? null : (double?)int.Parse(position) + } + ); } else { - writeResult = _fileSystemManager.WriteSync(new WriteSyncOption() - { - data = _bufferData, - fd = _fd, - encoding = encoding == "null" ? null : encoding, - length = length == "null" ? null : (double?)int.Parse(length), - offset = offset == "null" ? null : (double?)int.Parse(offset), - position = position == "null" ? null : (double?)int.Parse(position) - }); + writeResult = _fileSystemManager.WriteSync( + new WriteSyncOption() + { + data = _bufferData, + fd = _fd, + encoding = encoding == "null" ? null : encoding, + length = length == "null" ? null : (double?)int.Parse(length), + offset = offset == "null" ? null : (double?)int.Parse(offset), + position = position == "null" ? null : (double?)int.Parse(position) + } + ); } // 更新文件内容 UpdateFileContent(); - WX.ShowModal(new ShowModalOption() - { - content = "Write Success, Result: " + JsonMapper.ToJson(writeResult) - }); + WX.ShowModal( + new ShowModalOption() + { + content = "Write Success, Result: " + JsonMapper.ToJson(writeResult) + } + ); } - + // 异步写入 - private void WriteAsync(string dataType, string offset, string length, string encoding, string position) + private void WriteAsync( + string dataType, + string offset, + string length, + string encoding, + string position + ) { if (dataType == "string") { - _fileSystemManager.Write(new WriteStringOption() - { - data = _stringData, - fd = _fd, - encoding = encoding == "null" ? null : encoding, - length = length == "null" ? null : (double?)int.Parse(length), - offset = offset == "null" ? null : (double?)int.Parse(offset), - position = position == "null" ? null : (double?)int.Parse(position), - success = onWriteSuccess, - fail = onWriteFail - }); + _fileSystemManager.Write( + new WriteStringOption() + { + data = _stringData, + fd = _fd, + encoding = encoding == "null" ? null : encoding, + length = length == "null" ? null : (double?)int.Parse(length), + offset = offset == "null" ? null : (double?)int.Parse(offset), + position = position == "null" ? null : (double?)int.Parse(position), + success = onWriteSuccess, + fail = onWriteFail + } + ); } else { - _fileSystemManager.Write(new WriteOption() - { - data = _bufferData, - fd = _fd, - encoding = encoding == "null" ? null : encoding, - length = length == "null" ? null : (double?)int.Parse(length), - offset = offset == "null" ? null : (double?)int.Parse(offset), - position = position == "null" ? null : (double?)int.Parse(position), - success = onWriteSuccess, - fail = onWriteFail - }); + _fileSystemManager.Write( + new WriteOption() + { + data = _bufferData, + fd = _fd, + encoding = encoding == "null" ? null : encoding, + length = length == "null" ? null : (double?)int.Parse(length), + offset = offset == "null" ? null : (double?)int.Parse(offset), + position = position == "null" ? null : (double?)int.Parse(position), + success = onWriteSuccess, + fail = onWriteFail + } + ); } } @@ -235,13 +252,19 @@ private void WriteAsync(string dataType, string offset, string length, string en private void UpdateReadResult() { // 使用UTF8编码显示读取内容 - GameManager.Instance.detailsController.ChangeResultContent(0, Encoding.UTF8.GetString(_buffer)); + GameManager.Instance.detailsController.ChangeResultContent( + 0, + Encoding.UTF8.GetString(_buffer) + ); } // 更新文件内容 private static void UpdateFileContent() { // 使用UTF8编码显示文件内容 - GameManager.Instance.detailsController.ChangeResultContent(1, _fileSystemManager.ReadFileSync(Path, "utf8")); + GameManager.Instance.detailsController.ChangeResultContent( + 1, + _fileSystemManager.ReadFileSync(Path, "utf8") + ); } -} \ No newline at end of file +} diff --git a/Demo/API_V2/Assets/API/FileSystem/ReadFileAndWriteFile/ReadFileAndWriteFile.cs b/Demo/API_V2/Assets/API/FileSystem/ReadFileAndWriteFile/ReadFileAndWriteFile.cs index 122f1017c..b3230cd78 100644 --- a/Demo/API_V2/Assets/API/FileSystem/ReadFileAndWriteFile/ReadFileAndWriteFile.cs +++ b/Demo/API_V2/Assets/API/FileSystem/ReadFileAndWriteFile/ReadFileAndWriteFile.cs @@ -1,43 +1,44 @@ -using System; +using System; using LitJson; using WeChatWASM; public class ReadFileAndWriteFile : Details { private static WXFileSystemManager _fileSystemManager; - + // 路径 // 注意WX.env.USER_DATA_PATH后接字符串需要以/开头 private static readonly string PathPrefix = WX.env.USER_DATA_PATH + "/ReadFileAndWriteFile"; private static readonly string Path = PathPrefix + "/hello.txt"; - + // 数据 private string _stringData = "String Data "; - private byte[] _bufferData = {66, 117, 102, 102, 101, 114, 32, 68, 97, 116, 97, 32}; - + private byte[] _bufferData = { 66, 117, 102, 102, 101, 114, 32, 68, 97, 116, 97, 32 }; + // 回调函数 private Action onWriteFileSuccess = (res) => { UpdateFileContent(); - WX.ShowModal(new ShowModalOption() - { - content = "WriteFile Success, Result: " + JsonMapper.ToJson(res) - }); + WX.ShowModal( + new ShowModalOption() + { + content = "WriteFile Success, Result: " + JsonMapper.ToJson(res) + } + ); }; private Action onWriteFileFail = (res) => { - WX.ShowModal(new ShowModalOption() - { - content = "WriteFile Fail, Result: " + JsonMapper.ToJson(res) - }); + WX.ShowModal( + new ShowModalOption() { content = "WriteFile Fail, Result: " + JsonMapper.ToJson(res) } + ); }; - + // 在 Start 方法中初始化 private void Start() { // 获取全局唯一的文件管理器 _fileSystemManager = WX.GetFileSystemManager(); - + // 检查并创建目录 if (_fileSystemManager.AccessSync(PathPrefix) != "access:ok") { @@ -45,23 +46,17 @@ private void Start() } // 创建文件 - var fd = _fileSystemManager.OpenSync(new OpenSyncOption() - { - filePath = Path, - flag = "w+" - }); - + var fd = _fileSystemManager.OpenSync(new OpenSyncOption() { filePath = Path, flag = "w+" }); + // 写入初始数据 - _fileSystemManager.WriteSync(new WriteSyncStringOption() - { - fd = fd, - data = "Original Data " - }); + _fileSystemManager.WriteSync( + new WriteSyncStringOption() { fd = fd, data = "Original Data " } + ); // 绑定按钮事件 GameManager.Instance.detailsController.BindExtraButtonAction(0, WriteFile); } - + // 读取文件 protected override void TestAPI(string[] args) { @@ -74,7 +69,7 @@ protected override void TestAPI(string[] args) ReadFileAsync(args[2], args[3], args[4]); } } - + // 写入文件 private void WriteFile() { @@ -93,51 +88,52 @@ private void ReadFileSync(string encoding, string position, string length) { if (encoding == "null") { - var readResult = _fileSystemManager.ReadFileSync(Path, + var readResult = _fileSystemManager.ReadFileSync( + Path, position == "null" ? null : (long?)int.Parse(position), - length == "null" ? null : (long?)int.Parse(length)); + length == "null" ? null : (long?)int.Parse(length) + ); UpdateReadResult(readResult); } else { - var readResult = _fileSystemManager.ReadFileSync(Path, encoding, + var readResult = _fileSystemManager.ReadFileSync( + Path, + encoding, position == "null" ? null : (long?)int.Parse(position), - length == "null" ? null : (long?)int.Parse(length)); + length == "null" ? null : (long?)int.Parse(length) + ); UpdateReadResult(readResult); } - - WX.ShowToast(new ShowToastOption() - { - title = "ReadFileSync Success" - }); + + WX.ShowToast(new ShowToastOption() { title = "ReadFileSync Success" }); } - + // 异步读取文件 private void ReadFileAsync(string encoding, string position, string length) { - _fileSystemManager.ReadFile(new ReadFileParam() - { - filePath = Path, - encoding = encoding == "null" ? null : encoding, - position = position == "null" ? null : (long?)int.Parse(position), - length = length == "null" ? null : (long?)int.Parse(length), - success = (res) => + _fileSystemManager.ReadFile( + new ReadFileParam() { - // 若encoding为null,则数据位于res.binData,否则数据位于res.stringData - if (encoding == "null") + filePath = Path, + encoding = encoding == "null" ? null : encoding, + position = position == "null" ? null : (long?)int.Parse(position), + length = length == "null" ? null : (long?)int.Parse(length), + success = (res) => { - UpdateReadResult(res.binData); + // 若encoding为null,则数据位于res.binData,否则数据位于res.stringData + if (encoding == "null") + { + UpdateReadResult(res.binData); + } + else + { + UpdateReadResult(res.stringData); + } + WX.ShowToast(new ShowToastOption() { title = "ReadFile Success" }); } - else - { - UpdateReadResult(res.stringData); - } - WX.ShowToast(new ShowToastOption() - { - title = "ReadFile Success" - }); } - }); + ); } // 同步写入文件 @@ -168,12 +164,9 @@ private void WriteFileSync(string dataType, string encoding) // 更新文件内容 UpdateFileContent(); - WX.ShowToast(new ShowToastOption() - { - title = "WriteFile Success" - }); + WX.ShowToast(new ShowToastOption() { title = "WriteFile Success" }); } - + // 异步写入文件 private void WriteFileAsync(string dataType, string encoding) { @@ -181,48 +174,56 @@ private void WriteFileAsync(string dataType, string encoding) { if (encoding == "null") { - _fileSystemManager.WriteFile(new WriteFileStringParam() - { - filePath = Path, - data = _stringData, - success = onWriteFileSuccess, - fail = onWriteFileFail - }); + _fileSystemManager.WriteFile( + new WriteFileStringParam() + { + filePath = Path, + data = _stringData, + success = onWriteFileSuccess, + fail = onWriteFileFail + } + ); } else { - _fileSystemManager.WriteFile(new WriteFileStringParam() - { - filePath = Path, - data = _stringData, - encoding = encoding, - success = onWriteFileSuccess, - fail = onWriteFileFail - }); + _fileSystemManager.WriteFile( + new WriteFileStringParam() + { + filePath = Path, + data = _stringData, + encoding = encoding, + success = onWriteFileSuccess, + fail = onWriteFileFail + } + ); } } else { if (encoding == "null") { - _fileSystemManager.WriteFile(new WriteFileParam() - { - filePath = Path, - data = _bufferData, - success = onWriteFileSuccess, - fail = onWriteFileFail - }); + _fileSystemManager.WriteFile( + new WriteFileParam() + { + filePath = Path, + data = _bufferData, + success = onWriteFileSuccess, + fail = onWriteFileFail + } + ); } else { - _fileSystemManager.WriteFile(new WriteFileParam() - { - filePath = Path, - data = _bufferData, - encoding = encoding, - success = onWriteFileSuccess, - fail = onWriteFileFail - }); + _fileSystemManager.WriteFile( + new WriteFileParam() + { + filePath = Path, + data = _bufferData, + encoding = encoding, + success = onWriteFileSuccess, + fail = onWriteFileFail + } + ); } } } @@ -230,7 +231,10 @@ private void WriteFileAsync(string dataType, string encoding) // 更新读取结果(字节数组) private void UpdateReadResult(byte[] readResult) { - GameManager.Instance.detailsController.ChangeResultContent(0, JsonMapper.ToJson(readResult)); + GameManager.Instance.detailsController.ChangeResultContent( + 0, + JsonMapper.ToJson(readResult) + ); } // 更新读取结果(字符串) @@ -243,6 +247,9 @@ private void UpdateReadResult(string readResult) private static void UpdateFileContent() { // 使用UTF8编码显示文件内容 - GameManager.Instance.detailsController.ChangeResultContent(1, _fileSystemManager.ReadFileSync(Path, "utf8")); + GameManager.Instance.detailsController.ChangeResultContent( + 1, + _fileSystemManager.ReadFileSync(Path, "utf8") + ); } -} \ No newline at end of file +} diff --git a/Demo/API_V2/Assets/API/FileSystem/ReaddirAndUnlink/ReaddirAndUnlink.cs b/Demo/API_V2/Assets/API/FileSystem/ReaddirAndUnlink/ReaddirAndUnlink.cs index ff9e5a41b..c860c1888 100644 --- a/Demo/API_V2/Assets/API/FileSystem/ReaddirAndUnlink/ReaddirAndUnlink.cs +++ b/Demo/API_V2/Assets/API/FileSystem/ReaddirAndUnlink/ReaddirAndUnlink.cs @@ -1,15 +1,15 @@ -using LitJson; +using LitJson; using WeChatWASM; public class ReaddirAndUnlink : Details { private WXFileSystemManager _fileSystemManager; - + // 路径 // 注意WX.env.USER_DATA_PATH后接字符串需要以/开头 private static readonly string PathPrefix = WX.env.USER_DATA_PATH + "/ReaddirAndUnlink"; private static readonly string DirPath = PathPrefix + "/dir"; - + private void Start() { // 获取全局唯一的文件管理器 @@ -20,12 +20,12 @@ private void Start() { _fileSystemManager.MkdirSync(DirPath, true); } - + // 绑定按钮事件 GameManager.Instance.detailsController.BindExtraButtonAction(0, Unlink); GameManager.Instance.detailsController.BindExtraButtonAction(1, ReadDir); } - + // 创建文件 protected override void TestAPI(string[] args) { @@ -38,7 +38,7 @@ protected override void TestAPI(string[] args) OpenAsync(args[1]); } } - + // 删除文件 private void Unlink() { @@ -51,7 +51,7 @@ private void Unlink() UnlinkAsync(options[1]); } } - + // 获取目录下的文件列表 private void ReadDir() { @@ -64,118 +64,117 @@ private void ReadDir() ReaddirAsync(); } } - + // 同步创建文件 private void OpenSync(string filePath) { - _fileSystemManager.OpenSync(new OpenSyncOption() - { - filePath = PathPrefix + filePath, - flag = "w+" - }); - - WX.ShowToast(new ShowToastOption() - { - title = "同步创建文件成功" - }); + _fileSystemManager.OpenSync( + new OpenSyncOption() { filePath = PathPrefix + filePath, flag = "w+" } + ); + + WX.ShowToast(new ShowToastOption() { title = "同步创建文件成功" }); } - + // 异步创建文件 private void OpenAsync(string filePath) { - _fileSystemManager.Open(new OpenOption() - { - filePath = PathPrefix + filePath, - flag = "w+", - success = (res) => + _fileSystemManager.Open( + new OpenOption() { - WX.ShowToast(new ShowToastOption() + filePath = PathPrefix + filePath, + flag = "w+", + success = (res) => { - title = "异步创建文件成功" - }); - }, - fail = (res) => - { - WX.ShowModal(new ShowModalOption() + WX.ShowToast(new ShowToastOption() { title = "异步创建文件成功" }); + }, + fail = (res) => { - content = "Open Fail, Result: " + JsonMapper.ToJson(res) - }); + WX.ShowModal( + new ShowModalOption() + { + content = "Open Fail, Result: " + JsonMapper.ToJson(res) + } + ); + } } - }); + ); } - + // 同步删除文件 private void UnlinkSync(string filePath) { var res = _fileSystemManager.UnlinkSync(PathPrefix + filePath); - - WX.ShowModal(new ShowModalOption() - { - content = "UnlinkSync Result: " + res - }); + + WX.ShowModal(new ShowModalOption() { content = "UnlinkSync Result: " + res }); } - + // 异步删除文件 private void UnlinkAsync(string filePath) { - _fileSystemManager.Unlink(new UnlinkParam() - { - filePath = PathPrefix + filePath, - success = (res) => + _fileSystemManager.Unlink( + new UnlinkParam() { - WX.ShowToast(new ShowToastOption() + filePath = PathPrefix + filePath, + success = (res) => { - title = "Unlink Success, Result: " + JsonMapper.ToJson(res) - }); - }, - fail = (res) => - { - WX.ShowModal(new ShowModalOption() + WX.ShowToast( + new ShowToastOption() + { + title = "Unlink Success, Result: " + JsonMapper.ToJson(res) + } + ); + }, + fail = (res) => { - content = "Unlink Fail, Result: " + JsonMapper.ToJson(res) - }); + WX.ShowModal( + new ShowModalOption() + { + content = "Unlink Fail, Result: " + JsonMapper.ToJson(res) + } + ); + } } - }); + ); } - + // 同步获取目录下的文件列表 private void ReaddirSync() { var res = _fileSystemManager.ReaddirSync(PathPrefix); - + // 更新文件列表 UpdateResults(res); - - WX.ShowToast(new ShowToastOption() - { - title = "ReadDirSync Success" - }); + + WX.ShowToast(new ShowToastOption() { title = "ReadDirSync Success" }); } // 异步获取目录下的文件列表 private void ReaddirAsync() { - _fileSystemManager.Readdir(new ReaddirOption() - { - dirPath = PathPrefix, - success = (res) => + _fileSystemManager.Readdir( + new ReaddirOption() { - // 更新文件列表 - UpdateResults(res.files); - - WX.ShowModal(new ShowModalOption() + dirPath = PathPrefix, + success = (res) => { - content = "ReadDir Success, Result: " + res.errMsg - }); - }, - fail = (res) => - { - WX.ShowModal(new ShowModalOption() + // 更新文件列表 + UpdateResults(res.files); + + WX.ShowModal( + new ShowModalOption() { content = "ReadDir Success, Result: " + res.errMsg } + ); + }, + fail = (res) => { - content = "ReadDir Fail, Result: " + JsonMapper.ToJson(res) - }); + WX.ShowModal( + new ShowModalOption() + { + content = "ReadDir Fail, Result: " + JsonMapper.ToJson(res) + } + ); + } } - }); + ); } // 更新文件列表 @@ -187,10 +186,9 @@ private void UpdateResults(string[] fileList) // 遍历文件列表,将每个文件添加到结果列表中 foreach (var file in fileList) { - GameManager.Instance.detailsController.AddResult(new ResultData() - { - initialContentText = file - }); + GameManager.Instance.detailsController.AddResult( + new ResultData() { initialContentText = file } + ); } } -} \ No newline at end of file +} diff --git a/Demo/API_V2/Assets/API/FileSystem/Rename/Rename.cs b/Demo/API_V2/Assets/API/FileSystem/Rename/Rename.cs index f7bacbe29..d51be23ab 100644 --- a/Demo/API_V2/Assets/API/FileSystem/Rename/Rename.cs +++ b/Demo/API_V2/Assets/API/FileSystem/Rename/Rename.cs @@ -1,10 +1,10 @@ -using LitJson; +using LitJson; using WeChatWASM; public class Rename : Details { private WXFileSystemManager _fileSystemManager; - + // 路径 // 注意WX.env.USER_DATA_PATH后接字符串需要以/开头 private static readonly string PathPrefix = WX.env.USER_DATA_PATH + "/Rename"; @@ -15,7 +15,7 @@ public class Rename : Details // 当前路径 private string _oldPath = "/hello.txt"; - + private void Start() { // 获取全局唯一的文件管理器 @@ -26,20 +26,16 @@ private void Start() { _fileSystemManager.MkdirSync(DirPath, true); } - + // 创建并写入初始数据到文件 - var fd = _fileSystemManager.OpenSync(new OpenSyncOption() - { - filePath = Path1, - flag = "w+" - }); - _fileSystemManager.WriteSync(new WriteSyncStringOption() - { - fd = fd, - data = "Original Data " - }); + var fd = _fileSystemManager.OpenSync( + new OpenSyncOption() { filePath = Path1, flag = "w+" } + ); + _fileSystemManager.WriteSync( + new WriteSyncStringOption() { fd = fd, data = "Original Data " } + ); } - + // 重命名文件 protected override void TestAPI(string[] args) { @@ -52,33 +48,39 @@ protected override void TestAPI(string[] args) RunAsync(args[1]); } } - + // 异步重命名文件 private void RunAsync(string newPath) - { - _fileSystemManager.Rename(new RenameOption() - { - newPath = PathPrefix + newPath, - oldPath = PathPrefix + _oldPath, - success = (res) => - { - _oldPath = newPath; - UpdateResults(); - WX.ShowModal(new ShowModalOption() - { - content = "Rename Success, Result: " + JsonMapper.ToJson(res) - }); - }, - fail = (res) => - { - WX.ShowModal(new ShowModalOption() - { - content = "Rename Fail, Result: " + JsonMapper.ToJson(res) - }); - } - }); + { + _fileSystemManager.Rename( + new RenameOption() + { + newPath = PathPrefix + newPath, + oldPath = PathPrefix + _oldPath, + success = (res) => + { + _oldPath = newPath; + UpdateResults(); + WX.ShowModal( + new ShowModalOption() + { + content = "Rename Success, Result: " + JsonMapper.ToJson(res) + } + ); + }, + fail = (res) => + { + WX.ShowModal( + new ShowModalOption() + { + content = "Rename Fail, Result: " + JsonMapper.ToJson(res) + } + ); + } + } + ); } - + // 同步重命名文件 private void RunSync(string newPath) { @@ -86,17 +88,23 @@ private void RunSync(string newPath) _oldPath = newPath; UpdateResults(); - WX.ShowToast(new ShowToastOption() - { - title = "Rename Success" - }); + WX.ShowToast(new ShowToastOption() { title = "Rename Success" }); } // 更新结果 private void UpdateResults() { - GameManager.Instance.detailsController.SetResultActive(0, _fileSystemManager.AccessSync(Path1) == "access:ok"); - GameManager.Instance.detailsController.SetResultActive(1, _fileSystemManager.AccessSync(Path2) == "access:ok"); - GameManager.Instance.detailsController.SetResultActive(2, _fileSystemManager.AccessSync(Path3) == "access:ok"); + GameManager.Instance.detailsController.SetResultActive( + 0, + _fileSystemManager.AccessSync(Path1) == "access:ok" + ); + GameManager.Instance.detailsController.SetResultActive( + 1, + _fileSystemManager.AccessSync(Path2) == "access:ok" + ); + GameManager.Instance.detailsController.SetResultActive( + 2, + _fileSystemManager.AccessSync(Path3) == "access:ok" + ); } -} \ No newline at end of file +} diff --git a/Demo/API_V2/Assets/API/FileSystem/Stat/Stat.cs b/Demo/API_V2/Assets/API/FileSystem/Stat/Stat.cs index 18ab28bb5..beaaf8799 100644 --- a/Demo/API_V2/Assets/API/FileSystem/Stat/Stat.cs +++ b/Demo/API_V2/Assets/API/FileSystem/Stat/Stat.cs @@ -1,11 +1,11 @@ -using System; +using System; using UnityEngine; using WeChatWASM; public class Stat : Details { private WXFileSystemManager _fileSystemManager; - + // 路径 // 注意WX.env.USER_DATA_PATH后接字符串需要以/开头 private static readonly string PathPrefix = WX.env.USER_DATA_PATH + "/Stat"; @@ -14,16 +14,13 @@ public class Stat : Details private static readonly string Path6 = PathPrefix + "/dir/Six.txt"; private static readonly string Path8 = PathPrefix + "/dir/Eight.txt"; private static readonly string Path9 = PathPrefix + "/dir/Nine.txt"; - + // 失败回调 private Action onFail = (res) => { - WX.ShowModal(new ShowModalOption() - { - content = "Stat Fail" - }); + WX.ShowModal(new ShowModalOption() { content = "Stat Fail" }); }; - + private void Start() { // 获取全局唯一的文件管理器 @@ -36,26 +33,10 @@ private void Start() } // 创建文件 - _fileSystemManager.OpenSync(new OpenSyncOption() - { - filePath = Path5, - flag = "w+" - }); - _fileSystemManager.OpenSync(new OpenSyncOption() - { - filePath = Path6, - flag = "w+" - }); - _fileSystemManager.OpenSync(new OpenSyncOption() - { - filePath = Path8, - flag = "w+" - }); - _fileSystemManager.OpenSync(new OpenSyncOption() - { - filePath = Path9, - flag = "w+" - }); + _fileSystemManager.OpenSync(new OpenSyncOption() { filePath = Path5, flag = "w+" }); + _fileSystemManager.OpenSync(new OpenSyncOption() { filePath = Path6, flag = "w+" }); + _fileSystemManager.OpenSync(new OpenSyncOption() { filePath = Path8, flag = "w+" }); + _fileSystemManager.OpenSync(new OpenSyncOption() { filePath = Path9, flag = "w+" }); // 写入文件内容 _fileSystemManager.WriteFileSync(Path5, "Five words form this statement."); @@ -63,7 +44,7 @@ private void Start() _fileSystemManager.WriteFileSync(Path8, "This phrase has a total of eight words."); _fileSystemManager.WriteFileSync(Path9, "Here, you'll find a sentence with nine words."); } - + // 获取文件状态 protected override void TestAPI(string[] args) { @@ -76,75 +57,66 @@ protected override void TestAPI(string[] args) RunAsync(args[1], args[2]); } } - + // 同步获取文件状态 private void RunSync(string path) { var fileStats = _fileSystemManager.StatSync(PathPrefix + path); UpdateResults(fileStats); - WX.ShowToast(new ShowToastOption() - { - title = "StatSync Success" - }); + WX.ShowToast(new ShowToastOption() { title = "StatSync Success" }); } - + // 异步获取文件状态 private void RunAsync(string path, string recursive) { if (recursive == "null") { - _fileSystemManager.Stat(new WXStatOption() - { - path = PathPrefix + path, - success = (res) => + _fileSystemManager.Stat( + new WXStatOption() { - UpdateResults(res.stats.ToArray()); - WX.ShowToast(new ShowToastOption() + path = PathPrefix + path, + success = (res) => { - title = "Stat Success" - }); - }, - fail = onFail - }); + UpdateResults(res.stats.ToArray()); + WX.ShowToast(new ShowToastOption() { title = "Stat Success" }); + }, + fail = onFail + } + ); } else { - _fileSystemManager.Stat(new WXStatOption() - { - path = PathPrefix + path, - recursive = recursive == "true", - success = (res) => + _fileSystemManager.Stat( + new WXStatOption() { - if (recursive == "true") + path = PathPrefix + path, + recursive = recursive == "true", + success = (res) => { - UpdateResults(res.stats.ToArray()); - WX.ShowToast(new ShowToastOption() + if (recursive == "true") { - title = "Stat Success" - }); - } - else - { - UpdateResults(res.one_stat); - WX.ShowToast(new ShowToastOption() + UpdateResults(res.stats.ToArray()); + WX.ShowToast(new ShowToastOption() { title = "Stat Success" }); + } + else { - title = "Stat Success" - }); - } - - }, - fail = onFail - }); + UpdateResults(res.one_stat); + WX.ShowToast(new ShowToastOption() { title = "Stat Success" }); + } + }, + fail = onFail + } + ); } } - + // 清除结果 private void ClearResults() { GameManager.Instance.detailsController.KeepFirstNResults(5); } - + // 更新结果 private void UpdateResults(WXStat[] fileStats) { @@ -152,28 +124,43 @@ private void UpdateResults(WXStat[] fileStats) foreach (var fileStat in fileStats) { - GameManager.Instance.detailsController.AddResult(new ResultData() - { - initialContentText = "文件路径:" + fileStat.path - + "\n文件的类型和存取的权限:" + fileStat.stats.mode - + "\n文件大小,单位:B:" + fileStat.stats.size - + "\n文件最近一次被存取或被执行的时间:" + fileStat.stats.lastAccessedTime - + "\n文件最后一次被修改的时间:" + fileStat.stats.lastModifiedTime - }); + GameManager.Instance.detailsController.AddResult( + new ResultData() + { + initialContentText = + "文件路径:" + + fileStat.path + + "\n文件的类型和存取的权限:" + + fileStat.stats.mode + + "\n文件大小,单位:B:" + + fileStat.stats.size + + "\n文件最近一次被存取或被执行的时间:" + + fileStat.stats.lastAccessedTime + + "\n文件最后一次被修改的时间:" + + fileStat.stats.lastModifiedTime + } + ); } } - + // 更新结果 private void UpdateResults(WXStatInfo stats) { ClearResults(); - GameManager.Instance.detailsController.AddResult(new ResultData() - { - initialContentText = "文件的类型和存取的权限:" + stats.mode - + "\n文件大小,单位:B:" + stats.size - + "\n文件最近一次被存取或被执行的时间:" + stats.lastAccessedTime - + "\n文件最后一次被修改的时间:" + stats.lastModifiedTime - }); + GameManager.Instance.detailsController.AddResult( + new ResultData() + { + initialContentText = + "文件的类型和存取的权限:" + + stats.mode + + "\n文件大小,单位:B:" + + stats.size + + "\n文件最近一次被存取或被执行的时间:" + + stats.lastAccessedTime + + "\n文件最后一次被修改的时间:" + + stats.lastModifiedTime + } + ); } -} \ No newline at end of file +} diff --git a/Demo/API_V2/Assets/API/GUI/Interact/Interact.cs b/Demo/API_V2/Assets/API/GUI/Interact/Interact.cs index 9ca8b4f93..c9e8e5cb7 100644 --- a/Demo/API_V2/Assets/API/GUI/Interact/Interact.cs +++ b/Demo/API_V2/Assets/API/GUI/Interact/Interact.cs @@ -3,6 +3,7 @@ using LitJson; using UnityEngine; using WeChatWASM; + public class Interact : Details { private void Start() @@ -21,126 +22,145 @@ protected override void TestAPI(string[] args) showToast(); } - public void showToast() { - WX.ShowToast(new ShowToastOption - { - title = "showToast", - duration = 5000, - success = (res) => - { - Debug.Log(res); - }, - fail = (res) => - { - Debug.Log("fail:" + res.errMsg); - }, - complete = (res) => - { - Debug.Log("complete!"); + public void showToast() + { + WX.ShowToast( + new ShowToastOption + { + title = "showToast", + duration = 5000, + success = (res) => + { + Debug.Log(res); + }, + fail = (res) => + { + Debug.Log("fail:" + res.errMsg); + }, + complete = (res) => + { + Debug.Log("complete!"); + } } - }); + ); } - public void showModal() { - WX.ShowModal(new ShowModalOption - { - title = "showModal", - content = "show", - showCancel = true, - cancelText = "取消", - confirmText = "确定", - success = (res) => - { - Debug.Log("success"); - }, - fail = (res) => - { - Debug.Log("fail:" + res.errMsg); - }, - complete = (res) => - { - Debug.Log("complete!"); + public void showModal() + { + WX.ShowModal( + new ShowModalOption + { + title = "showModal", + content = "show", + showCancel = true, + cancelText = "取消", + confirmText = "确定", + success = (res) => + { + Debug.Log("success"); + }, + fail = (res) => + { + Debug.Log("fail:" + res.errMsg); + }, + complete = (res) => + { + Debug.Log("complete!"); + } } - }); + ); } - public void showLoading() { - WX.ShowLoading(new ShowLoadingOption - { - title = "showLoading", - success = (res) => - { - Debug.Log("success"); - }, - fail = (res) => - { - Debug.Log("fail:" + res.errMsg); - }, - complete = (res) => - { - Debug.Log("complete!"); + public void showLoading() + { + WX.ShowLoading( + new ShowLoadingOption + { + title = "showLoading", + success = (res) => + { + Debug.Log("success"); + }, + fail = (res) => + { + Debug.Log("fail:" + res.errMsg); + }, + complete = (res) => + { + Debug.Log("complete!"); + } } - }); + ); } - public void showActionSheet() { - WX.ShowActionSheet(new ShowActionSheetOption - { - alertText = "showActionSheet", - itemList = new string[] {"1", "2", "3"}, - success = (res) => - { - Debug.Log("success"); - }, - fail = (res) => - { - Debug.Log("fail:" + res.errMsg); - }, - complete = (res) => - { - Debug.Log("complete!"); + public void showActionSheet() + { + WX.ShowActionSheet( + new ShowActionSheetOption + { + alertText = "showActionSheet", + itemList = new string[] { "1", "2", "3" }, + success = (res) => + { + Debug.Log("success"); + }, + fail = (res) => + { + Debug.Log("fail:" + res.errMsg); + }, + complete = (res) => + { + Debug.Log("complete!"); + } } - }); + ); } - public void hideToast() { - WX.HideToast(new HideToastOption - { - success = (res) => - { - Debug.Log("success"); - }, - fail = (res) => - { - Debug.Log("fail:" + res.errMsg); - }, - complete = (res) => - { - Debug.Log("complete!"); + public void hideToast() + { + WX.HideToast( + new HideToastOption + { + success = (res) => + { + Debug.Log("success"); + }, + fail = (res) => + { + Debug.Log("fail:" + res.errMsg); + }, + complete = (res) => + { + Debug.Log("complete!"); + } } - }); + ); } - public void hideLoading() { - WX.HideLoading(new HideLoadingOption - { - success = (res) => - { - Debug.Log("success"); - }, - fail = (res) => - { - Debug.Log("fail:" + res.errMsg); - }, - complete = (res) => - { - Debug.Log("complete!"); + public void hideLoading() + { + WX.HideLoading( + new HideLoadingOption + { + success = (res) => + { + Debug.Log("success"); + }, + fail = (res) => + { + Debug.Log("fail:" + res.errMsg); + }, + complete = (res) => + { + Debug.Log("complete!"); + } } - }); + ); } - public void Destroy() { - WX.HideToast(new HideToastOption{}); - WX.HideLoading(new HideLoadingOption{}); + public void Destroy() + { + WX.HideToast(new HideToastOption { }); + WX.HideLoading(new HideLoadingOption { }); } } diff --git a/Demo/API_V2/Assets/API/GUI/Menu/Menu.cs b/Demo/API_V2/Assets/API/GUI/Menu/Menu.cs index 6f2b826c8..3fd53dd52 100644 --- a/Demo/API_V2/Assets/API/GUI/Menu/Menu.cs +++ b/Demo/API_V2/Assets/API/GUI/Menu/Menu.cs @@ -3,12 +3,16 @@ using LitJson; using UnityEngine; using WeChatWASM; + public class Menu : Details { private void Start() { // 绑定额外的按钮操作 - GameManager.Instance.detailsController.BindExtraButtonAction(0, getMenuButtonBoundingClientRect); + GameManager.Instance.detailsController.BindExtraButtonAction( + 0, + getMenuButtonBoundingClientRect + ); GameManager.Instance.detailsController.BindExtraButtonAction(1, setStatusBarStyle); } @@ -18,57 +22,57 @@ protected override void TestAPI(string[] args) setMenuStyle(); } - public void setMenuStyle() { - WX.SetMenuStyle(new SetMenuStyleOption - { - style = "light", - success = (res) => + public void setMenuStyle() + { + WX.SetMenuStyle( + new SetMenuStyleOption { - WX.ShowToast(new ShowToastOption + style = "light", + success = (res) => { - title = "设置成功" - }); - }, - fail = (res) => - { - Debug.Log("fail:" + res.errMsg); - }, - complete = (res) => - { - Debug.Log("complete!"); + WX.ShowToast(new ShowToastOption { title = "设置成功" }); + }, + fail = (res) => + { + Debug.Log("fail:" + res.errMsg); + }, + complete = (res) => + { + Debug.Log("complete!"); + } } - }); + ); } - public void getMenuButtonBoundingClientRect() { + public void getMenuButtonBoundingClientRect() + { var res = WX.GetMenuButtonBoundingClientRect(); // 访问成功,显示结果 - WX.ShowModal(new ShowModalOption() - { - content = "Access Success, Result: " + JsonMapper.ToJson(res) - }); + WX.ShowModal( + new ShowModalOption() { content = "Access Success, Result: " + JsonMapper.ToJson(res) } + ); } - public void setStatusBarStyle() { - WX.SetStatusBarStyle(new SetStatusBarStyleOption - { - style = "black", - success = (res) => + public void setStatusBarStyle() + { + WX.SetStatusBarStyle( + new SetStatusBarStyleOption { - WX.ShowToast(new ShowToastOption + style = "black", + success = (res) => { - title = "设置成功" - }); - }, - fail = (res) => - { - Debug.Log("fail:" + res.errMsg); - }, - complete = (res) => - { - Debug.Log("complete!"); + WX.ShowToast(new ShowToastOption { title = "设置成功" }); + }, + fail = (res) => + { + Debug.Log("fail:" + res.errMsg); + }, + complete = (res) => + { + Debug.Log("complete!"); + } } - }); + ); } } diff --git a/Demo/API_V2/Assets/API/GUI/Window/Window.cs b/Demo/API_V2/Assets/API/GUI/Window/Window.cs index 6a71d4159..40a45a8a1 100644 --- a/Demo/API_V2/Assets/API/GUI/Window/Window.cs +++ b/Demo/API_V2/Assets/API/GUI/Window/Window.cs @@ -3,31 +3,38 @@ using LitJson; using UnityEngine; using WeChatWASM; + public class Window : Details { private bool _isListening = false; - private readonly Action _onWindowResize = (res) => { + private readonly Action _onWindowResize = (res) => + { var result = "onWindowResize\n" + JsonMapper.ToJson(res); - GameManager.Instance.detailsController.AddResult(new ResultData() - { - initialContentText = result - }); + GameManager.Instance.detailsController.AddResult( + new ResultData() { initialContentText = result } + ); }; // 测试 API protected override void TestAPI(string[] args) { - if (!_isListening) { + if (!_isListening) + { WX.OnWindowResize(_onWindowResize); - } else { + } + else + { WX.OffWindowResize(_onWindowResize); } _isListening = !_isListening; - GameManager.Instance.detailsController.ChangeInitialButtonText(_isListening ? "取消监听" : "开始监听"); + GameManager.Instance.detailsController.ChangeInitialButtonText( + _isListening ? "取消监听" : "开始监听" + ); } - private void OnDestroy() { + private void OnDestroy() + { WX.OffWindowResize(_onWindowResize); } } diff --git a/Demo/API_V2/Assets/API/GameRecorder/GameRecorder/GameRecorder.cs b/Demo/API_V2/Assets/API/GameRecorder/GameRecorder/GameRecorder.cs index f6e189e50..8cfb1659a 100644 --- a/Demo/API_V2/Assets/API/GameRecorder/GameRecorder/GameRecorder.cs +++ b/Demo/API_V2/Assets/API/GameRecorder/GameRecorder/GameRecorder.cs @@ -1,4 +1,4 @@ -using UnityEngine; +using UnityEngine; using WeChatWASM; public class GameRecorder : Details @@ -16,32 +16,50 @@ void Start() _gameRecorder = WX.GetGameRecorder(); } - _gameRecorder.On("timeUpdate", (res) => - { - Debug.Log(res.currentTime); - }); - _gameRecorder.On("start", (res) => - { - Debug.Log("GameRecorder start"); - }); + _gameRecorder.On( + "timeUpdate", + (res) => + { + Debug.Log(res.currentTime); + } + ); + _gameRecorder.On( + "start", + (res) => + { + Debug.Log("GameRecorder start"); + } + ); - _gameRecorder.On("pause", (res) => - { - Debug.Log("GameRecorder pause"); - }); - _gameRecorder.On("resume", (res) => - { - // IOS客户端resume事件有问题 - Debug.Log("GameRecorder resume"); - }); - _gameRecorder.On("stop", (res) => - { - Debug.Log("GameRecorder stop:" + res.duration); - }); - _gameRecorder.On("error", (res) => - { - Debug.Log("GameRecorder error:" + JsonUtility.ToJson(res)); - }); + _gameRecorder.On( + "pause", + (res) => + { + Debug.Log("GameRecorder pause"); + } + ); + _gameRecorder.On( + "resume", + (res) => + { + // IOS客户端resume事件有问题 + Debug.Log("GameRecorder resume"); + } + ); + _gameRecorder.On( + "stop", + (res) => + { + Debug.Log("GameRecorder stop:" + res.duration); + } + ); + _gameRecorder.On( + "error", + (res) => + { + Debug.Log("GameRecorder error:" + JsonUtility.ToJson(res)); + } + ); GameManager.Instance.detailsController.BindExtraButtonAction(0, PauseRecorder); GameManager.Instance.detailsController.BindExtraButtonAction(1, ResumeRecorder); @@ -52,10 +70,12 @@ void Start() // 开始 protected override void TestAPI(string[] args) { - _gameRecorder.Start(new GameRecorderStartOption() - { - // hookBgm = false, - }); + _gameRecorder.Start( + new GameRecorderStartOption() + { + // hookBgm = false, + } + ); } // 暂停 @@ -79,16 +99,19 @@ private void StopRecorder() // 分享 private void ShareRecorder() { - WX.OperateGameRecorderVideo(new OperateGameRecorderVideoOption() - { - title = "游戏标题", - desc = "游戏简介", - timeRange = new double[][] { - new double[] { 0, 2000 }, - new double[] { 5000, 8000 }, - }, - query = "test=123456", - }); + WX.OperateGameRecorderVideo( + new OperateGameRecorderVideoOption() + { + title = "游戏标题", + desc = "游戏简介", + timeRange = new double[][] + { + new double[] { 0, 2000 }, + new double[] { 5000, 8000 }, + }, + query = "test=123456", + } + ); } public void OffEvent() @@ -105,4 +128,4 @@ public void Destroy() OffEvent(); _gameRecorder.Stop(); } -} \ No newline at end of file +} diff --git a/Demo/API_V2/Assets/API/Location/Location/Location.cs b/Demo/API_V2/Assets/API/Location/Location/Location.cs index 62e736822..c6022243a 100644 --- a/Demo/API_V2/Assets/API/Location/Location/Location.cs +++ b/Demo/API_V2/Assets/API/Location/Location/Location.cs @@ -3,6 +3,7 @@ using LitJson; using UnityEngine; using WeChatWASM; + public class Location : Details { // 测试 API @@ -11,25 +12,30 @@ protected override void TestAPI(string[] args) getFuzzyLocation(); } - public void getFuzzyLocation() { - WX.GetFuzzyLocation(new GetFuzzyLocationOption - { - type = "wgs84", - success = (res) => + public void getFuzzyLocation() + { + WX.GetFuzzyLocation( + new GetFuzzyLocationOption { - WX.ShowModal(new ShowModalOption() + type = "wgs84", + success = (res) => { - content = "Access Success, Result: " + JsonMapper.ToJson(res) - }); - }, - fail = (res) => - { - Debug.Log("fail:" + res.errMsg); - }, - complete = (res) => - { - Debug.Log("complete!"); + WX.ShowModal( + new ShowModalOption() + { + content = "Access Success, Result: " + JsonMapper.ToJson(res) + } + ); + }, + fail = (res) => + { + Debug.Log("fail:" + res.errMsg); + }, + complete = (res) => + { + Debug.Log("complete!"); + } } - }); + ); } } diff --git a/Demo/API_V2/Assets/API/Media/Camera/Camera.cs b/Demo/API_V2/Assets/API/Media/Camera/Camera.cs index 63c453a7b..61a2e407c 100644 --- a/Demo/API_V2/Assets/API/Media/Camera/Camera.cs +++ b/Demo/API_V2/Assets/API/Media/Camera/Camera.cs @@ -1,4 +1,4 @@ -using UnityEngine; +using UnityEngine; using WeChatWASM; public class Camera : Details @@ -8,25 +8,28 @@ public class Camera : Details private bool _firstLoad = true; private bool _isListening = false; + private void Start() { // 该功能无法在IOS高性能模式使用 // 该功能无法在开发者工具使用 - _camera = WX.CreateCamera(new CreateCameraOption() - { - x = -144, - y = -256, - width = 144, - height = 256, - success = (res) => + _camera = WX.CreateCamera( + new CreateCameraOption() { - Debug.Log("创建相机成功" + JsonUtility.ToJson(res)); - }, - fail = (res) => - { - Debug.Log("创建相机失败" + JsonUtility.ToJson(res)); + x = -144, + y = -256, + width = 144, + height = 256, + success = (res) => + { + Debug.Log("创建相机成功" + JsonUtility.ToJson(res)); + }, + fail = (res) => + { + Debug.Log("创建相机失败" + JsonUtility.ToJson(res)); + } } - }); + ); _camera.OnAuthCancel(() => { @@ -40,11 +43,13 @@ private void Start() Debug.Log("摄像头暂停,如退出后台"); }); - _camera.OnCameraFrame((response) => - { - // 获取每帧数据 - RenderTexture(response.data, response.width, response.height); - }); + _camera.OnCameraFrame( + (response) => + { + // 获取每帧数据 + RenderTexture(response.data, response.width, response.height); + } + ); } protected override void TestAPI(string[] args) diff --git a/Demo/API_V2/Assets/API/Media/Photo/Photo.cs b/Demo/API_V2/Assets/API/Media/Photo/Photo.cs index 09bf294a2..f0aa6674b 100644 --- a/Demo/API_V2/Assets/API/Media/Photo/Photo.cs +++ b/Demo/API_V2/Assets/API/Media/Photo/Photo.cs @@ -3,9 +3,9 @@ using LitJson; using UnityEngine; using WeChatWASM; + public class Photo : Details { - private void Start() { // 绑定额外的按钮操作 @@ -22,115 +22,125 @@ protected override void TestAPI(string[] args) } // 图片路径需使用本地路径 - public void saveImageToPhotosAlbum() { - WX.SaveImageToPhotosAlbum(new SaveImageToPhotosAlbumOption - { - filePath = "xxxx", - success = (res) => - { - Debug.Log("success"); - }, - fail = (res) => - { - Debug.Log("fail:" + res.errMsg); - }, - complete = (res) => + public void saveImageToPhotosAlbum() + { + WX.SaveImageToPhotosAlbum( + new SaveImageToPhotosAlbumOption { - Debug.Log("complete!"); + filePath = "xxxx", + success = (res) => + { + Debug.Log("success"); + }, + fail = (res) => + { + Debug.Log("fail:" + res.errMsg); + }, + complete = (res) => + { + Debug.Log("complete!"); + } } - }); + ); } - public void previewMedia() { - WX.PreviewMedia(new PreviewMediaOption - { - sources = new MediaSource[] { - new MediaSource { - url = "xxxxx", - type = "image" + public void previewMedia() + { + WX.PreviewMedia( + new PreviewMediaOption + { + sources = new MediaSource[] + { + new MediaSource { url = "xxxxx", type = "image" }, + new MediaSource { url = "yyyy", type = "image" } + }, + current = 0, + showmenu = true, + referrerPolicy = "no-referrer", + success = (res) => + { + Debug.Log("success"); }, - new MediaSource { - url = "yyyy", - type = "image" + fail = (res) => + { + Debug.Log("fail:" + res.errMsg); + }, + complete = (res) => + { + Debug.Log("complete!"); } - }, - current = 0, - showmenu = true, - referrerPolicy = "no-referrer", - success = (res) => - { - Debug.Log("success"); - }, - fail = (res) => - { - Debug.Log("fail:" + res.errMsg); - }, - complete = (res) => - { - Debug.Log("complete!"); } - }); + ); } - public void previewImage() { - WX.PreviewImage(new PreviewImageOption - { - urls = new string[] {"xxx", "yyy"}, - showmenu = true, - success = (res) => - { - Debug.Log("success"); - }, - fail = (res) => - { - Debug.Log("fail:" + res.errMsg); - }, - complete = (res) => + public void previewImage() + { + WX.PreviewImage( + new PreviewImageOption { - Debug.Log("complete!"); + urls = new string[] { "xxx", "yyy" }, + showmenu = true, + success = (res) => + { + Debug.Log("success"); + }, + fail = (res) => + { + Debug.Log("fail:" + res.errMsg); + }, + complete = (res) => + { + Debug.Log("complete!"); + } } - }); + ); } - public void compressImage() { - WX.CompressImage(new CompressImageOption - { - src = "xxxx", - quality = 80, - compressedWidth = 500, - compressedHeight = 500, - success = (res) => - { - Debug.Log("success " + JsonMapper.ToJson(res)); - }, - fail = (res) => - { - Debug.Log("fail:" + res.errMsg); - }, - complete = (res) => + public void compressImage() + { + WX.CompressImage( + new CompressImageOption { - Debug.Log("complete!"); + src = "xxxx", + quality = 80, + compressedWidth = 500, + compressedHeight = 500, + success = (res) => + { + Debug.Log("success " + JsonMapper.ToJson(res)); + }, + fail = (res) => + { + Debug.Log("fail:" + res.errMsg); + }, + complete = (res) => + { + Debug.Log("complete!"); + } } - }); + ); } - public void chooseMessageFile() { - WX.ChooseMessageFile(new ChooseMessageFileOption - { - count = 10, - type = "image", - success = (res) => - { - Debug.Log("success " + JsonMapper.ToJson(res)); - }, - fail = (res) => - { - Debug.Log("fail:" + res.errMsg); - }, - complete = (res) => + public void chooseMessageFile() + { + WX.ChooseMessageFile( + new ChooseMessageFileOption { - Debug.Log("complete!"); + count = 10, + type = "image", + success = (res) => + { + Debug.Log("success " + JsonMapper.ToJson(res)); + }, + fail = (res) => + { + Debug.Log("fail:" + res.errMsg); + }, + complete = (res) => + { + Debug.Log("complete!"); + } } - }); + ); } } diff --git a/Demo/API_V2/Assets/API/Media/Recorder/Recorder.cs b/Demo/API_V2/Assets/API/Media/Recorder/Recorder.cs index b85760902..ba0a9da36 100644 --- a/Demo/API_V2/Assets/API/Media/Recorder/Recorder.cs +++ b/Demo/API_V2/Assets/API/Media/Recorder/Recorder.cs @@ -1,4 +1,4 @@ -using UnityEngine; +using UnityEngine; using WeChatWASM; public class Recorder : Details @@ -31,21 +31,25 @@ private void Start() Debug.Log("recorder onResume"); }); - _recorderManager.OnStop((res) => - { - Debug.Log("recorder onStop"); - Debug.Log(res.tempFilePath); - Debug.Log(res.duration); - Debug.Log(res.fileSize); - _tempFilePath = res.tempFilePath; - }); + _recorderManager.OnStop( + (res) => + { + Debug.Log("recorder onStop"); + Debug.Log(res.tempFilePath); + Debug.Log(res.duration); + Debug.Log(res.fileSize); + _tempFilePath = res.tempFilePath; + } + ); - _recorderManager.OnFrameRecorded((res) => - { - Debug.Log("recorder onFrameRecorded"); - Debug.Log(res.frameBuffer.Length); - Debug.Log(res.isLastFrame); - }); + _recorderManager.OnFrameRecorded( + (res) => + { + Debug.Log("recorder onFrameRecorded"); + Debug.Log(res.frameBuffer.Length); + Debug.Log(res.isLastFrame); + } + ); _recorderManager.OnInterruptionBegin(() => { @@ -56,7 +60,7 @@ private void Start() { Debug.Log("recorder onInterruptionEnd"); }); - + GameManager.Instance.detailsController.BindExtraButtonAction(0, RecorderPause); GameManager.Instance.detailsController.BindExtraButtonAction(1, RecorderResume); GameManager.Instance.detailsController.BindExtraButtonAction(2, RecorderStop); @@ -67,15 +71,17 @@ private void Start() // 开始 protected override void TestAPI(string[] args) { - _recorderManager.Start(new RecorderManagerStartOption() - { - duration = 10000, - sampleRate = 44100, - numberOfChannels = 1, - encodeBitRate = 192000, - format = "aac", - frameSize = 50 - }); + _recorderManager.Start( + new RecorderManagerStartOption() + { + duration = 10000, + sampleRate = 44100, + numberOfChannels = 1, + encodeBitRate = 192000, + format = "aac", + frameSize = 50 + } + ); } // 暂停 @@ -89,13 +95,13 @@ public void RecorderResume() { _recorderManager.Resume(); } - + // 停止 public void RecorderStop() { _recorderManager.Stop(); } - + // 播放 public void RecorderPlay() { @@ -111,51 +117,59 @@ public void RecorderPlay() Debug.Log("recorder audio OnCanplay"); audioPlayRightNow.Play(); }); - audioPlayRightNow.OnError((res) => - { - Debug.Log("recorder audio OnError"); - }); + audioPlayRightNow.OnError( + (res) => + { + Debug.Log("recorder audio OnError"); + } + ); } // 上传 public void UploadFile() { - _uploadTask = WX.UploadFile(new UploadFileOption() - { - url = "xxxxxxxx", // 此处填写开发者自己的后台地址 - filePath = _tempFilePath, - name = "test", - timeout = 10000, - success = (successResult) => + _uploadTask = WX.UploadFile( + new UploadFileOption() { - Debug.Log("successResult"); - Debug.Log(JsonUtility.ToJson(successResult)); - }, - fail = (failResult) => - { - Debug.Log("failResult"); - Debug.Log(JsonUtility.ToJson(failResult)); - }, - complete = (completeResult) => - { - Debug.Log("completeResult"); - Debug.Log(JsonUtility.ToJson(completeResult)); + url = "xxxxxxxx", // 此处填写开发者自己的后台地址 + filePath = _tempFilePath, + name = "test", + timeout = 10000, + success = (successResult) => + { + Debug.Log("successResult"); + Debug.Log(JsonUtility.ToJson(successResult)); + }, + fail = (failResult) => + { + Debug.Log("failResult"); + Debug.Log(JsonUtility.ToJson(failResult)); + }, + complete = (completeResult) => + { + Debug.Log("completeResult"); + Debug.Log(JsonUtility.ToJson(completeResult)); + } } - }); + ); - _uploadTask.OnHeadersReceived((data) => - { - Debug.Log("onHeadersReceived"); - Debug.Log(JsonUtility.ToJson(data.header)); - }); + _uploadTask.OnHeadersReceived( + (data) => + { + Debug.Log("onHeadersReceived"); + Debug.Log(JsonUtility.ToJson(data.header)); + } + ); - _uploadTask.OnProgressUpdate((data) => - { - Debug.Log("onProgressUpdate"); - Debug.Log(data.progress); - Debug.Log(data.totalBytesSent); - Debug.Log(data.totalBytesExpectedToSend); - }); + _uploadTask.OnProgressUpdate( + (data) => + { + Debug.Log("onProgressUpdate"); + Debug.Log(data.progress); + Debug.Log(data.totalBytesSent); + Debug.Log(data.totalBytesExpectedToSend); + } + ); } private void OnDestroy() diff --git a/Demo/API_V2/Assets/API/Media/VideoDecoder/VideoDecoder.cs b/Demo/API_V2/Assets/API/Media/VideoDecoder/VideoDecoder.cs index 14f183a0d..f317da554 100644 --- a/Demo/API_V2/Assets/API/Media/VideoDecoder/VideoDecoder.cs +++ b/Demo/API_V2/Assets/API/Media/VideoDecoder/VideoDecoder.cs @@ -2,33 +2,37 @@ using System.Collections.Generic; using LitJson; using UnityEngine; -using WeChatWASM; using UnityEngine.UI; - +using WeChatWASM; public class VideoDecoder : Details { private WXVideoDecoder _videoDecoder; - private readonly Action _onStart = (res) => { + private readonly Action _onStart = (res) => + { Debug.Log("videodecoder onStart " + JsonUtility.ToJson(res)); }; - private readonly Action _onStop = (res) => { + private readonly Action _onStop = (res) => + { Debug.Log("videodecoder onStop " + JsonUtility.ToJson(res)); }; - private readonly Action _onSeek = (res) => { + private readonly Action _onSeek = (res) => + { Debug.Log("videodecoder onSeek " + JsonUtility.ToJson(res)); }; - private readonly Action _onBufferchange = (res) => { + private readonly Action _onBufferchange = (res) => + { Debug.Log("videodecoder onBufferchange " + JsonUtility.ToJson(res)); }; - private readonly Action _onEnded = (res) => { + private readonly Action _onEnded = (res) => + { // ended = true; - Debug.Log("videodecoder onEnded " + JsonUtility.ToJson(res)); + Debug.Log("videodecoder onEnded " + JsonUtility.ToJson(res)); }; private void Start() @@ -44,7 +48,6 @@ private void Start() _videoDecoder.On("bufferchange", _onBufferchange); _videoDecoder.On("ended", _onEnded); - GameManager.Instance.detailsController.BindExtraButtonAction(0, stop); GameManager.Instance.detailsController.BindExtraButtonAction(1, seek); GameManager.Instance.detailsController.BindExtraButtonAction(2, getFrameData); @@ -53,26 +56,29 @@ private void Start() // 开始 protected override void TestAPI(string[] args) { - _videoDecoder.Start(new VideoDecoderStartOption() - { - source = "https://res.wx.qq.com/wechatgame/product/webpack/userupload/20190812/video.mp4", - mode = 1, - abortAudio = false, - abortVideo = false, - }); + _videoDecoder.Start( + new VideoDecoderStartOption() + { + source = + "https://res.wx.qq.com/wechatgame/product/webpack/userupload/20190812/video.mp4", + mode = 1, + abortAudio = false, + abortVideo = false, + } + ); } - + // 停止 public void stop() { _videoDecoder.Stop(); } - - public void seek() + + public void seek() { _videoDecoder.Seek(12000); } - + public void getFrameData() { FrameDataOptions res = _videoDecoder.GetFrameData(); diff --git a/Demo/API_V2/Assets/API/Media/VoipManager/VoipManager.cs b/Demo/API_V2/Assets/API/Media/VoipManager/VoipManager.cs index 9dccabd77..bea4b3beb 100644 --- a/Demo/API_V2/Assets/API/Media/VoipManager/VoipManager.cs +++ b/Demo/API_V2/Assets/API/Media/VoipManager/VoipManager.cs @@ -19,73 +19,85 @@ protected override void TestAPI(string[] args) public void JoinVoIPChat() { - WX.JoinVoIPChat(new JoinVoIPChatOption() - { - signature = "xxxxxxxx", - nonceStr = "xxxxxxx", - timeStamp = 111111, - groupId = "xxxxxxxx", - success = (res) => + WX.JoinVoIPChat( + new JoinVoIPChatOption() { - Debug.Log("JoinVoIPChat success"); - Debug.Log(JsonUtility.ToJson(res)); - }, - fail = (res) => + signature = "xxxxxxxx", + nonceStr = "xxxxxxx", + timeStamp = 111111, + groupId = "xxxxxxxx", + success = (res) => + { + Debug.Log("JoinVoIPChat success"); + Debug.Log(JsonUtility.ToJson(res)); + }, + fail = (res) => + { + Debug.Log("JoinVoIPChat fail"); + Debug.Log(JsonUtility.ToJson(res)); + }, + complete = (res) => + { + Debug.Log("JoinVoIPChat complete"); + Debug.Log(JsonUtility.ToJson(res)); + }, + } + ); + + WX.OnVoIPChatInterrupted( + (res) => { - Debug.Log("JoinVoIPChat fail"); + Debug.Log("OnVoIPChatInterrupted"); Debug.Log(JsonUtility.ToJson(res)); - }, - complete = (res) => + } + ); + + WX.OnVoIPChatMembersChanged( + (res) => { - Debug.Log("JoinVoIPChat complete"); + Debug.Log("OnVoIPChatMembersChanged"); Debug.Log(JsonUtility.ToJson(res)); - }, - }); - - WX.OnVoIPChatInterrupted((res) => - { - Debug.Log("OnVoIPChatInterrupted"); - Debug.Log(JsonUtility.ToJson(res)); - }); + } + ); - WX.OnVoIPChatMembersChanged((res) => - { - Debug.Log("OnVoIPChatMembersChanged"); - Debug.Log(JsonUtility.ToJson(res)); - }); - - WX.OnVoIPChatSpeakersChanged((res) => - { - Debug.Log("OnVoIPChatSpeakersChanged"); - Debug.Log(JsonUtility.ToJson(res)); - }); + WX.OnVoIPChatSpeakersChanged( + (res) => + { + Debug.Log("OnVoIPChatSpeakersChanged"); + Debug.Log(JsonUtility.ToJson(res)); + } + ); - WX.OnVoIPChatStateChanged((res) => - { - Debug.Log("OnVoIPChatStateChanged"); - Debug.Log(JsonUtility.ToJson(res)); - }); + WX.OnVoIPChatStateChanged( + (res) => + { + Debug.Log("OnVoIPChatStateChanged"); + Debug.Log(JsonUtility.ToJson(res)); + } + ); } public void ExitVoIPChat() { - WX.ExitVoIPChat(new ExitVoIPChatOption() - { - success = (res) => - { - Debug.Log("ExitVoIPChat success"); - Debug.Log(JsonUtility.ToJson(res)); - }, - fail = (res) => + WX.ExitVoIPChat( + new ExitVoIPChatOption() { - Debug.Log("ExitVoIPChat fail"); - Debug.Log(JsonUtility.ToJson(res)); - }, - complete = (res) => - { - Debug.Log("ExitVoIPChat complete"); - Debug.Log(JsonUtility.ToJson(res)); - }, - }); + success = (res) => + { + Debug.Log("ExitVoIPChat success"); + Debug.Log(JsonUtility.ToJson(res)); + }, + fail = (res) => + { + Debug.Log("ExitVoIPChat fail"); + Debug.Log(JsonUtility.ToJson(res)); + }, + complete = (res) => + { + Debug.Log("ExitVoIPChat complete"); + Debug.Log(JsonUtility.ToJson(res)); + }, + } + ); } } diff --git a/Demo/API_V2/Assets/API/Media/WXVideo/WXvideo.cs b/Demo/API_V2/Assets/API/Media/WXVideo/WXvideo.cs index df44d7544..48f3cb794 100644 --- a/Demo/API_V2/Assets/API/Media/WXVideo/WXvideo.cs +++ b/Demo/API_V2/Assets/API/Media/WXVideo/WXvideo.cs @@ -7,6 +7,7 @@ public class WXvideo : MonoBehaviour { private WXVideo _video; + // Start is called before the first frame update void Start() { @@ -19,22 +20,27 @@ void Start() private void AutoPlayVideo() { var systemInfo = WX.GetSystemInfoSync(); - _video = WX.CreateVideo(new WXCreateVideoParam() + _video = WX.CreateVideo( + new WXCreateVideoParam() + { + src = + "http://wxsnsdy.tc.qq.com/105/20210/snsdyvideodownload?filekey=30280201010421301f0201690402534804102ca905ce620b1241b726bc41dcff44e00204012882540400&bizid=1023&hy=SH&fileparam=302c020101042530230204136ffd93020457e3c4ff02024ef202031e8d7f02030f42400204045a320a0201000400", + controls = false, + showProgress = false, + showProgressInControlMode = false, + autoplay = true, + showCenterPlayBtn = false, + underGameView = true, + width = ((int)systemInfo.screenWidth), + height = ((int)systemInfo.screenHeight), + } + ); + _video.OnPlay(() => { - src = "http://wxsnsdy.tc.qq.com/105/20210/snsdyvideodownload?filekey=30280201010421301f0201690402534804102ca905ce620b1241b726bc41dcff44e00204012882540400&bizid=1023&hy=SH&fileparam=302c020101042530230204136ffd93020457e3c4ff02024ef202031e8d7f02030f42400204045a320a0201000400", - controls = false, - showProgress = false, - showProgressInControlMode = false, - autoplay = true, - showCenterPlayBtn = false, - underGameView = true, - width = ((int)systemInfo.screenWidth), - height = ((int)systemInfo.screenHeight), - }); - _video.OnPlay(() => { Debug.Log("video on play"); }); - _video.OnError(() => { + _video.OnError(() => + { Debug.Log("video on error"); }); } @@ -47,5 +53,5 @@ private void OnClick() private void OnDestroy() { _video.Destroy(); - } + } } diff --git a/Demo/API_V2/Assets/API/Navigate/Navigate/Navigate.cs b/Demo/API_V2/Assets/API/Navigate/Navigate/Navigate.cs index e3acadf10..4207998a8 100644 --- a/Demo/API_V2/Assets/API/Navigate/Navigate/Navigate.cs +++ b/Demo/API_V2/Assets/API/Navigate/Navigate/Navigate.cs @@ -3,6 +3,7 @@ using LitJson; using UnityEngine; using WeChatWASM; + public class Navigate : Details { private void Start() @@ -18,32 +19,41 @@ protected override void TestAPI(string[] args) restartMiniProgram(); } - public void restartMiniProgram() { - WX.RestartMiniProgram(new RestartMiniProgramOption{}); + public void restartMiniProgram() + { + WX.RestartMiniProgram(new RestartMiniProgramOption { }); } - public void navigateToMiniProgram() { + public void navigateToMiniProgram() + { Dictionary myDictionary = new Dictionary(); myDictionary.Add("key1", "value1"); myDictionary.Add("key2", "value2"); - WX.NavigateToMiniProgram(new NavigateToMiniProgramOption() { - appId = "wx7a727ff7d940bb3f", - path = "?id=123", - extraData = myDictionary, - envVersion = "develop", - success = (res) => { - Debug.Log("success: " + JsonUtility.ToJson(res)); - }, - fail = (res) => { - Debug.Log("fail: " + JsonUtility.ToJson(res)); - }, - complete = (res) => { - Debug.Log("complete"); + WX.NavigateToMiniProgram( + new NavigateToMiniProgramOption() + { + appId = "wx7a727ff7d940bb3f", + path = "?id=123", + extraData = myDictionary, + envVersion = "develop", + success = (res) => + { + Debug.Log("success: " + JsonUtility.ToJson(res)); + }, + fail = (res) => + { + Debug.Log("fail: " + JsonUtility.ToJson(res)); + }, + complete = (res) => + { + Debug.Log("complete"); + } } - }); + ); } - public void exitMiniProgram() { - WX.ExitMiniProgram(new ExitMiniProgramOption{}); + public void exitMiniProgram() + { + WX.ExitMiniProgram(new ExitMiniProgramOption { }); } } diff --git a/Demo/API_V2/Assets/API/Network/Download/Download.cs b/Demo/API_V2/Assets/API/Network/Download/Download.cs index 5cf7fc1f7..122846833 100644 --- a/Demo/API_V2/Assets/API/Network/Download/Download.cs +++ b/Demo/API_V2/Assets/API/Network/Download/Download.cs @@ -3,51 +3,58 @@ using LitJson; using UnityEngine; using WeChatWASM; + public class Download : Details { - private WXDownloadTask _downloadTask; - private readonly Action _onHeadersReceived = (res) => { + private readonly Action _onHeadersReceived = ( + res + ) => + { var result = "onHeadersReceived\n" + JsonMapper.ToJson(res); - GameManager.Instance.detailsController.AddResult(new ResultData() - { - initialContentText = result - }); + GameManager.Instance.detailsController.AddResult( + new ResultData() { initialContentText = result } + ); }; - private readonly Action _onProgressUpdate = (res) => { + private readonly Action _onProgressUpdate = (res) => + { var result = "onProgressUpdate\n" + JsonMapper.ToJson(res); - GameManager.Instance.detailsController.AddResult(new ResultData() - { - initialContentText = result - }); + GameManager.Instance.detailsController.AddResult( + new ResultData() { initialContentText = result } + ); }; // 测试 API protected override void TestAPI(string[] args) { // 填入具体的url和其它参数 - _downloadTask = WX.DownloadFile(new DownloadFileOption - { - url = "https://res.wx.qq.com/wxdoc/dist/assets/img/demo.ef5c5bef.jpg", - success = (res) => { - Debug.Log(JsonMapper.ToJson(res)); - }, - fail = (res) => { - Debug.Log("fail: " + res.errMsg); - }, - complete = (res) => { - Debug.Log("complete"); + _downloadTask = WX.DownloadFile( + new DownloadFileOption + { + url = "https://res.wx.qq.com/wxdoc/dist/assets/img/demo.ef5c5bef.jpg", + success = (res) => + { + Debug.Log(JsonMapper.ToJson(res)); + }, + fail = (res) => + { + Debug.Log("fail: " + res.errMsg); + }, + complete = (res) => + { + Debug.Log("complete"); + } } - }); + ); _downloadTask.OnHeadersReceived(_onHeadersReceived); _downloadTask.OnProgressUpdate(_onProgressUpdate); } - public void abort() { + public void abort() + { _downloadTask.Abort(); } } - diff --git a/Demo/API_V2/Assets/API/Network/TCPSocket/TCPSocket.cs b/Demo/API_V2/Assets/API/Network/TCPSocket/TCPSocket.cs index edb568f59..5ae47a006 100644 --- a/Demo/API_V2/Assets/API/Network/TCPSocket/TCPSocket.cs +++ b/Demo/API_V2/Assets/API/Network/TCPSocket/TCPSocket.cs @@ -13,13 +13,13 @@ public class TCPSocket : Details // 数据 private string _stringData1 = "String Data"; private string _stringData2 = "123\n"; - private byte[] _bufferData1 = { 66, 117, 102, 102, 101, 114, 32, 68, 97, 116, 97, 32 }; private byte[] _bufferData2 = { 0xab, 0x05, 0xd7, 0x05 }; private byte[] _bufferData3 = new byte[8]; - private void Start() { + private void Start() + { GameManager.Instance.detailsController.BindExtraButtonAction(0, connect); GameManager.Instance.detailsController.BindExtraButtonAction(1, write); GameManager.Instance.detailsController.BindExtraButtonAction(2, close); @@ -28,64 +28,77 @@ private void Start() { // 测试 API protected override void TestAPI(string[] args) { - if(_tcpSocket == null) + if (_tcpSocket == null) { _tcpSocket = WX.CreateTCPSocket(); Debug.Log("tcpSocket: " + JsonUtility.ToJson(_tcpSocket)); - _tcpSocket.OnMessage((res) => { - Debug.Log("onMessage: " + JsonUtility.ToJson(res)); - }); - - _tcpSocket.OnConnect((res) => { - Debug.Log("onConnect: " + JsonUtility.ToJson(res)); - }); - - _tcpSocket.OnError((res) => { - Debug.Log("onError: " + JsonUtility.ToJson(res)); - }); - - _tcpSocket.OnClose((res) => { - Debug.Log("onClose: " + JsonUtility.ToJson(res)); - }); - } else + _tcpSocket.OnMessage( + (res) => + { + Debug.Log("onMessage: " + JsonUtility.ToJson(res)); + } + ); + + _tcpSocket.OnConnect( + (res) => + { + Debug.Log("onConnect: " + JsonUtility.ToJson(res)); + } + ); + + _tcpSocket.OnError( + (res) => + { + Debug.Log("onError: " + JsonUtility.ToJson(res)); + } + ); + + _tcpSocket.OnClose( + (res) => + { + Debug.Log("onClose: " + JsonUtility.ToJson(res)); + } + ); + } + else { Debug.LogError("tcp实例已初始化"); } - } private void close() { - if(_tcpSocket != null && _connected) + if (_tcpSocket != null && _connected) { _tcpSocket.Close(); _connected = false; _tcpSocket = null; - } else + } + else { Debug.LogError("关闭失败:tcp实例未初始化或未连接"); } - } - - private void connect() { - if (_tcpSocket != null && !_connected) { - _tcpSocket.Connect(new TCPSocketConnectOption() - { - address = "www.oooceanworld.com", - port = 8101 - }); + private void connect() + { + if (_tcpSocket != null && !_connected) + { + _tcpSocket.Connect( + new TCPSocketConnectOption() { address = "www.oooceanworld.com", port = 8101 } + ); _connected = true; - } else + } + else { Debug.LogError("连接失败:tcp实例未初始化或已连接"); } } - private void write() { + private void write() + { if (_tcpSocket != null && _connected) { if (options[0] == "String") @@ -104,10 +117,10 @@ private void write() { Debug.Log("test 3: " + _bufferData3); _tcpSocket.Write(_bufferData3); } - } else + } + else { Debug.LogError("发送失败:tcp实例未初始化或未连接"); } } } - diff --git a/Demo/API_V2/Assets/API/Network/UDPSocket/UDPSocket.cs b/Demo/API_V2/Assets/API/Network/UDPSocket/UDPSocket.cs index 230feb816..9cc52d771 100644 --- a/Demo/API_V2/Assets/API/Network/UDPSocket/UDPSocket.cs +++ b/Demo/API_V2/Assets/API/Network/UDPSocket/UDPSocket.cs @@ -3,6 +3,7 @@ using LitJson; using UnityEngine; using WeChatWASM; + public class UDPSocket : Details { private WXUDPSocket _udpSocket; @@ -12,7 +13,8 @@ public class UDPSocket : Details private string _stringData = "hello, how are you"; private byte[] _bufferData = { 66, 117, 102, 102, 101, 114, 32, 68, 97, 116, 97, 32 }; - private void Start() { + private void Start() + { GameManager.Instance.detailsController.BindExtraButtonAction(0, connect); GameManager.Instance.detailsController.BindExtraButtonAction(1, write); GameManager.Instance.detailsController.BindExtraButtonAction(2, send); @@ -22,28 +24,40 @@ private void Start() { // 测试 API protected override void TestAPI(string[] args) { - if(_udpSocket == null) + if (_udpSocket == null) { _udpSocket = WX.CreateUDPSocket(); var port = _udpSocket.Bind(); Debug.Log("udpSocket: " + JsonUtility.ToJson(_udpSocket)); - _udpSocket.OnListening((res) => { - Debug.Log("onListening: " + JsonUtility.ToJson(res)); - }); + _udpSocket.OnListening( + (res) => + { + Debug.Log("onListening: " + JsonUtility.ToJson(res)); + } + ); - _udpSocket.OnError((res) => { - Debug.Log("onError: " + JsonUtility.ToJson(res)); - }); + _udpSocket.OnError( + (res) => + { + Debug.Log("onError: " + JsonUtility.ToJson(res)); + } + ); - _udpSocket.OnClose((res) => { - Debug.Log("onClose: " + JsonUtility.ToJson(res)); - }); + _udpSocket.OnClose( + (res) => + { + Debug.Log("onClose: " + JsonUtility.ToJson(res)); + } + ); - _udpSocket.OnMessage((res) => { - Debug.Log("onMessage: " + JsonUtility.ToJson(res)); - }); + _udpSocket.OnMessage( + (res) => + { + Debug.Log("onMessage: " + JsonUtility.ToJson(res)); + } + ); } else { @@ -51,16 +65,16 @@ protected override void TestAPI(string[] args) } } - private void connect() { + private void connect() + { if (_udpSocket != null && !_connected) { - _udpSocket.Connect(new UDPSocketConnectOption() - { - address = "www.oooceanworld.com", - port = 8101 - }); + _udpSocket.Connect( + new UDPSocketConnectOption() { address = "www.oooceanworld.com", port = 8101 } + ); _connected = true; - } else + } + else { Debug.LogError("连接失败:udp实例未初始化或已连接"); } @@ -120,16 +134,17 @@ private void send() } } - private void close() { + private void close() + { if (_udpSocket != null && _connected) { _udpSocket.Close(); _connected = false; _udpSocket = null; - } else + } + else { Debug.LogError("关闭失败:udp实例未初始化或未连接"); } } } - diff --git a/Demo/API_V2/Assets/API/Network/UnityWebRequest/WebRequest.cs b/Demo/API_V2/Assets/API/Network/UnityWebRequest/WebRequest.cs index 8a867f002..eb254f09a 100644 --- a/Demo/API_V2/Assets/API/Network/UnityWebRequest/WebRequest.cs +++ b/Demo/API_V2/Assets/API/Network/UnityWebRequest/WebRequest.cs @@ -1,9 +1,9 @@ using System; +using System.Collections; using System.Collections.Generic; using LitJson; using UnityEngine; using UnityEngine.Networking; -using System.Collections; using WeChatWASM; public class WebRequest : Details @@ -30,7 +30,7 @@ private void testPost() { StartCoroutine(Post()); } - + private void testPut() { StartCoroutine(Put()); @@ -48,7 +48,6 @@ IEnumerator Get() { Debug.Log("get complete: " + webRequest.downloadHandler.text); } - } IEnumerator Post() diff --git a/Demo/API_V2/Assets/API/Network/Upload/Upload.cs b/Demo/API_V2/Assets/API/Network/Upload/Upload.cs index e2feb8b2a..7cc34f736 100644 --- a/Demo/API_V2/Assets/API/Network/Upload/Upload.cs +++ b/Demo/API_V2/Assets/API/Network/Upload/Upload.cs @@ -12,37 +12,47 @@ public class Upload : Details protected override void TestAPI(string[] args) { // 需要修改url - WX.ChooseMedia(new ChooseMediaOption() { - count = 1, - mediaType = new String[] {"image"}, - sourceType = new String[] {"album"}, - sizeType = new String[] {"compressed"}, - success = (res) => { - Debug.Log(JsonUtility.ToJson(res)); - _uploadTask = WX.UploadFile(new UploadFileOption() { - url = "https://developers.weixin.qq.com/minigame/dev/api/render/image/wx.createImage.html", - filePath = res.tempFiles[0].tempFilePath, - name = "data", - success = (res) => { - Debug.Log("success: " + JsonUtility.ToJson(res)); - }, - fail = (res) => { - Debug.Log("fail: " + JsonUtility.ToJson(res)); - }, - complete = (res) => { - Debug.Log("complete"); - } - }); - }, - fail = (res) => { - Debug.Log("fail: " + JsonUtility.ToJson(res)); - }, - complete = (res) => { - Debug.Log("complete"); + WX.ChooseMedia( + new ChooseMediaOption() + { + count = 1, + mediaType = new String[] { "image" }, + sourceType = new String[] { "album" }, + sizeType = new String[] { "compressed" }, + success = (res) => + { + Debug.Log(JsonUtility.ToJson(res)); + _uploadTask = WX.UploadFile( + new UploadFileOption() + { + url = + "https://developers.weixin.qq.com/minigame/dev/api/render/image/wx.createImage.html", + filePath = res.tempFiles[0].tempFilePath, + name = "data", + success = (res) => + { + Debug.Log("success: " + JsonUtility.ToJson(res)); + }, + fail = (res) => + { + Debug.Log("fail: " + JsonUtility.ToJson(res)); + }, + complete = (res) => + { + Debug.Log("complete"); + } + } + ); + }, + fail = (res) => + { + Debug.Log("fail: " + JsonUtility.ToJson(res)); + }, + complete = (res) => + { + Debug.Log("complete"); + } } - }); + ); } - - } - diff --git a/Demo/API_V2/Assets/API/OpenInterface/GameClub/GameClub.cs b/Demo/API_V2/Assets/API/OpenInterface/GameClub/GameClub.cs index b528288bd..9b7775f54 100644 --- a/Demo/API_V2/Assets/API/OpenInterface/GameClub/GameClub.cs +++ b/Demo/API_V2/Assets/API/OpenInterface/GameClub/GameClub.cs @@ -1,10 +1,10 @@ using System; using System.Collections; using System.Collections.Generic; -using UnityEngine; +using System.Threading; using LitJson; +using UnityEngine; using WeChatWASM; -using System.Threading; public class GameClub : Details { @@ -30,17 +30,19 @@ IEnumerator CreateGameClubButton(float delay) Vector2 size = GameManager.Instance.detailsController.GetInitialButtonSize(); Vector2 position = GameManager.Instance.detailsController.GetButtonPosition(0); var systemInfo = WX.GetSystemInfoSync(); - _gameClubButton = WX.CreateGameClubButton(new WXCreateGameClubButtonParam() - { - type = GameClubButtonType.text, - style = new GameClubButtonStyle() + _gameClubButton = WX.CreateGameClubButton( + new WXCreateGameClubButtonParam() { - left = Math.Abs((int)(position.x / systemInfo.pixelRatio)), - top = Math.Abs((int)(position.y / systemInfo.pixelRatio)), - width = (int)(size.x * systemInfo.screenWidth / 1080f), - height = (int)(size.y * systemInfo.screenWidth / 1080f), + type = GameClubButtonType.text, + style = new GameClubButtonStyle() + { + left = Math.Abs((int)(position.x / systemInfo.pixelRatio)), + top = Math.Abs((int)(position.y / systemInfo.pixelRatio)), + width = (int)(size.x * systemInfo.screenWidth / 1080f), + height = (int)(size.y * systemInfo.screenWidth / 1080f), + } } - }); + ); } // 测试API @@ -115,7 +117,4 @@ public void Destroy() _gameClubButton = null; } } - } - - diff --git a/Demo/API_V2/Assets/API/OpenInterface/OpenData/OpenData.cs b/Demo/API_V2/Assets/API/OpenInterface/OpenData/OpenData.cs index 7527c7427..6c3a22b31 100644 --- a/Demo/API_V2/Assets/API/OpenInterface/OpenData/OpenData.cs +++ b/Demo/API_V2/Assets/API/OpenInterface/OpenData/OpenData.cs @@ -3,11 +3,11 @@ using LitJson; using UnityEngine; using WeChatWASM; + public class OpenData : Details { private void Start() { - GameManager.Instance.detailsController.BindExtraButtonAction(0, checkSession); GameManager.Instance.detailsController.BindExtraButtonAction(1, authorize); GameManager.Instance.detailsController.BindExtraButtonAction(2, getGroupEnterInfo); @@ -22,116 +22,152 @@ protected override void TestAPI(string[] args) login(); } - public void login() { - WX.Login(new LoginOption - { - timeout = 2000, - success = (res) => { - WX.ShowModal(new ShowModalOption - { - content = JsonMapper.ToJson(res) - }); - }, - fail = (res) => { - Debug.Log("fail : " + res.errMsg); - }, - complete = (res) => { - Debug.Log("complete"); + public void login() + { + WX.Login( + new LoginOption + { + timeout = 2000, + success = (res) => + { + WX.ShowModal(new ShowModalOption { content = JsonMapper.ToJson(res) }); + }, + fail = (res) => + { + Debug.Log("fail : " + res.errMsg); + }, + complete = (res) => + { + Debug.Log("complete"); + } } - }); + ); } - public void checkSession() { - WX.CheckSession(new CheckSessionOption - { - success = (res) => { - Debug.Log("success"); - }, - fail = (res) => { - Debug.Log("fail : " + res.errMsg); - }, - complete = (res) => { - Debug.Log("complete"); + public void checkSession() + { + WX.CheckSession( + new CheckSessionOption + { + success = (res) => + { + Debug.Log("success"); + }, + fail = (res) => + { + Debug.Log("fail : " + res.errMsg); + }, + complete = (res) => + { + Debug.Log("complete"); + } } - }); + ); } - public void authorize() { - WX.Authorize(new AuthorizeOption - { - scope = "scope.writePhotosAlbum", - success = (res) => { - Debug.Log("success"); - }, - fail = (res) => { - Debug.Log("fail : " + res.errMsg); - }, - complete = (res) => { - Debug.Log("complete"); + public void authorize() + { + WX.Authorize( + new AuthorizeOption + { + scope = "scope.writePhotosAlbum", + success = (res) => + { + Debug.Log("success"); + }, + fail = (res) => + { + Debug.Log("fail : " + res.errMsg); + }, + complete = (res) => + { + Debug.Log("complete"); + } } - }); + ); } - public void getGroupEnterInfo() { - WX.GetGroupEnterInfo(new GetGroupEnterInfoOption - { - success = (res) => { - WX.ShowModal(new ShowModalOption - { - content = JsonMapper.ToJson(res) - }); - }, - fail = (res) => { - Debug.Log("fail : " + res.errMsg); - }, - complete = (res) => { - Debug.Log("complete"); + public void getGroupEnterInfo() + { + WX.GetGroupEnterInfo( + new GetGroupEnterInfoOption + { + success = (res) => + { + WX.ShowModal(new ShowModalOption { content = JsonMapper.ToJson(res) }); + }, + fail = (res) => + { + Debug.Log("fail : " + res.errMsg); + }, + complete = (res) => + { + Debug.Log("complete"); + } } - }); + ); } - public void requirePrivacyAuthorize() { - WX.RequirePrivacyAuthorize(new RequirePrivacyAuthorizeOption - { - success = (res) => { - Debug.Log("success"); - }, - fail = (res) => { - Debug.Log("fail : " + res.errMsg); - }, - complete = (res) => { - Debug.Log("complete"); + public void requirePrivacyAuthorize() + { + WX.RequirePrivacyAuthorize( + new RequirePrivacyAuthorizeOption + { + success = (res) => + { + Debug.Log("success"); + }, + fail = (res) => + { + Debug.Log("fail : " + res.errMsg); + }, + complete = (res) => + { + Debug.Log("complete"); + } } - }); + ); } - public void openPrivacyContract() { - WX.OpenPrivacyContract(new OpenPrivacyContractOption - { - success = (res) => { - Debug.Log("success"); - }, - fail = (res) => { - Debug.Log("fail : " + res.errMsg); - }, - complete = (res) => { - Debug.Log("complete"); + public void openPrivacyContract() + { + WX.OpenPrivacyContract( + new OpenPrivacyContractOption + { + success = (res) => + { + Debug.Log("success"); + }, + fail = (res) => + { + Debug.Log("fail : " + res.errMsg); + }, + complete = (res) => + { + Debug.Log("complete"); + } } - }); + ); } - public void getPrivacySetting() { - WX.GetPrivacySetting(new GetPrivacySettingOption - { - success = (res) => { - Debug.Log("success " + JsonMapper.ToJson(res)); - }, - fail = (res) => { - Debug.Log("fail : " + res.errMsg); - }, - complete = (res) => { - Debug.Log("complete"); + public void getPrivacySetting() + { + WX.GetPrivacySetting( + new GetPrivacySettingOption + { + success = (res) => + { + Debug.Log("success " + JsonMapper.ToJson(res)); + }, + fail = (res) => + { + Debug.Log("fail : " + res.errMsg); + }, + complete = (res) => + { + Debug.Log("complete"); + } } - }); + ); } } diff --git a/Demo/API_V2/Assets/API/OpenInterface/Setting/Setting.cs b/Demo/API_V2/Assets/API/OpenInterface/Setting/Setting.cs index e663ae6cd..9ceb12ce5 100644 --- a/Demo/API_V2/Assets/API/OpenInterface/Setting/Setting.cs +++ b/Demo/API_V2/Assets/API/OpenInterface/Setting/Setting.cs @@ -8,33 +8,51 @@ private void Start() { GameManager.Instance.detailsController.BindExtraButtonAction(0, getSetting); } - + protected override void TestAPI(string[] args) { openSetting(); } - public void openSetting() { - WX.OpenSetting(new OpenSettingOption() { - success = res => { - Debug.Log("success " + JsonUtility.ToJson(res)); - }, fail = res => { - Debug.Log("fail " + JsonUtility.ToJson(res)); - }, complete = (res) => { - Debug.Log("complete " + JsonUtility.ToJson(res)); + public void openSetting() + { + WX.OpenSetting( + new OpenSettingOption() + { + success = res => + { + Debug.Log("success " + JsonUtility.ToJson(res)); + }, + fail = res => + { + Debug.Log("fail " + JsonUtility.ToJson(res)); + }, + complete = (res) => + { + Debug.Log("complete " + JsonUtility.ToJson(res)); + } } - }); + ); } - - public void getSetting() { - WX.GetSetting(new GetSettingOption() { - success = res => { - Debug.Log("success " + JsonUtility.ToJson(res)); - }, fail = res => { - Debug.Log("fail " + JsonUtility.ToJson(res)); - }, complete = (res) => { - Debug.Log("complete " + JsonUtility.ToJson(res)); + + public void getSetting() + { + WX.GetSetting( + new GetSettingOption() + { + success = res => + { + Debug.Log("success " + JsonUtility.ToJson(res)); + }, + fail = res => + { + Debug.Log("fail " + JsonUtility.ToJson(res)); + }, + complete = (res) => + { + Debug.Log("complete " + JsonUtility.ToJson(res)); + } } - }); + ); } } diff --git a/Demo/API_V2/Assets/API/OpenInterface/SystemButton/SystemButton.cs b/Demo/API_V2/Assets/API/OpenInterface/SystemButton/SystemButton.cs index e3eb7db95..807352672 100644 --- a/Demo/API_V2/Assets/API/OpenInterface/SystemButton/SystemButton.cs +++ b/Demo/API_V2/Assets/API/OpenInterface/SystemButton/SystemButton.cs @@ -1,9 +1,10 @@ -using System; +using System; +using System.Collections; using System.Collections.Generic; +using System.Threading; using UnityEngine; using WeChatWASM; -using System.Collections; -using System.Threading; + public class SystemButton : Details { private WXFeedbackButton _feedbackButton; @@ -15,30 +16,40 @@ private void Start() StartCoroutine(CreateFeedbackButton(1.0f)); - WX.GetSetting(new GetSettingOption() - { - withSubscriptions = true, - success = (res) => + WX.GetSetting( + new GetSettingOption() { - Dictionary itemSettings = res.subscriptionsSetting.itemSettings; - // 是否已授权过SYS_MSG_TYPE_INTERACTIVE,授权过不再展示按钮 - if (itemSettings.ContainsKey("SYS_MSG_TYPE_INTERACTIVE") && itemSettings["SYS_MSG_TYPE_INTERACTIVE"] == "accept") + withSubscriptions = true, + success = (res) => { - GameObject requestSubscribeButton = GameObject.Find("RequestSubscribeSystemMessage"); - if (requestSubscribeButton != null) + Dictionary itemSettings = res.subscriptionsSetting.itemSettings; + // 是否已授权过SYS_MSG_TYPE_INTERACTIVE,授权过不再展示按钮 + if ( + itemSettings.ContainsKey("SYS_MSG_TYPE_INTERACTIVE") + && itemSettings["SYS_MSG_TYPE_INTERACTIVE"] == "accept" + ) { - requestSubscribeButton.SetActive(false); + GameObject requestSubscribeButton = GameObject.Find( + "RequestSubscribeSystemMessage" + ); + if (requestSubscribeButton != null) + { + requestSubscribeButton.SetActive(false); + } } + }, + fail = (res) => + { + Debug.Log("GetSetting fail" + JsonUtility.ToJson(res)); } - }, - fail = (res) => - { - Debug.Log("GetSetting fail" + JsonUtility.ToJson(res)); } - }); + ); GameManager.Instance.detailsController.BindExtraButtonAction(0, FeedbackButtonSwitch); - GameManager.Instance.detailsController.BindExtraButtonAction(1, RequestSubscribeSystemMessage); + GameManager.Instance.detailsController.BindExtraButtonAction( + 1, + RequestSubscribeSystemMessage + ); GameManager.Instance.detailsController.BindExtraButtonAction(2, OpenCustomerServiceChat); } @@ -49,32 +60,35 @@ IEnumerator CreateFeedbackButton(float delay) Vector2 size = GameManager.Instance.detailsController.GetInitialButtonSize(); Vector2 position = GameManager.Instance.detailsController.GetButtonPosition(0); var systemInfo = WX.GetSystemInfoSync(); - _feedbackButton = WX.CreateFeedbackButton(new CreateOpenSettingButtonOption() - { - type = "text", - text = "", - style = new OptionStyle() + _feedbackButton = WX.CreateFeedbackButton( + new CreateOpenSettingButtonOption() { - left = Math.Abs((int)(position.x / systemInfo.pixelRatio)), - top = Math.Abs((int)(position.y / systemInfo.pixelRatio)), - width = (int)(size.x * systemInfo.screenWidth / 1080f), - height = (int)(size.y * systemInfo.screenWidth / 1080f), + type = "text", + text = "", + style = new OptionStyle() + { + left = Math.Abs((int)(position.x / systemInfo.pixelRatio)), + top = Math.Abs((int)(position.y / systemInfo.pixelRatio)), + width = (int)(size.x * systemInfo.screenWidth / 1080f), + height = (int)(size.y * systemInfo.screenWidth / 1080f), + } } - }); + ); } // 进入客服会话 protected override void TestAPI(string[] args) { - WX.OpenCustomerServiceConversation(new OpenCustomerServiceConversationOption - { - sessionFrom = "sessionFrom_test", - showMessageCard = true, - sendMessageTitle = "客服咨询", - }); + WX.OpenCustomerServiceConversation( + new OpenCustomerServiceConversationOption + { + sessionFrom = "sessionFrom_test", + showMessageCard = true, + sendMessageTitle = "客服咨询", + } + ); } - private bool _isFeedbackShow = true; // 切换意见反馈按钮显示/隐藏 @@ -98,40 +112,42 @@ private void FeedbackButtonSwitch() // 调起小游戏系统订阅消息界面 private void RequestSubscribeSystemMessage() { - WX.RequestSubscribeSystemMessage(new RequestSubscribeSystemMessageOption() - { - msgTypeList = new string[] { "SYS_MSG_TYPE_INTERACTIVE" }, - success = (res) => - { - Debug.Log(res); - }, - fail = (res) => + WX.RequestSubscribeSystemMessage( + new RequestSubscribeSystemMessageOption() { - Debug.Log(JsonUtility.ToJson(res)); + msgTypeList = new string[] { "SYS_MSG_TYPE_INTERACTIVE" }, + success = (res) => + { + Debug.Log(res); + }, + fail = (res) => + { + Debug.Log(JsonUtility.ToJson(res)); + } } - }); + ); } // 打开微信客服 private void OpenCustomerServiceChat() { - WX.OpenCustomerServiceChat(new OpenCustomerServiceChatOption() - { - extInfo = new ExtInfoOption() + WX.OpenCustomerServiceChat( + new OpenCustomerServiceChatOption() { - url = "https://www.qq.com/" - }, - corpId = "123", - }); + extInfo = new ExtInfoOption() { url = "https://www.qq.com/" }, + corpId = "123", + } + ); } - private void FeedbackButtonOnTap() { - _feedbackButton.OnTap((res) => - { - Debug.Log("FeedbackButton.OnTap"); - }); + _feedbackButton.OnTap( + (res) => + { + Debug.Log("FeedbackButton.OnTap"); + } + ); } private void FeedbackButtonOffTap() diff --git a/Demo/API_V2/Assets/API/OpenInterface/UserInfo/UserInfo.cs b/Demo/API_V2/Assets/API/OpenInterface/UserInfo/UserInfo.cs index 680b2900b..1cd9e79f8 100644 --- a/Demo/API_V2/Assets/API/OpenInterface/UserInfo/UserInfo.cs +++ b/Demo/API_V2/Assets/API/OpenInterface/UserInfo/UserInfo.cs @@ -1,9 +1,9 @@ using System; using System.Collections; +using System.Threading; using LitJson; using UnityEngine; using WeChatWASM; -using System.Threading; public class UserInfo : Details { @@ -12,13 +12,11 @@ public class UserInfo : Details private readonly Action _onTap = (res) => { var result = "onTap\n" + JsonMapper.ToJson(res); - GameManager.Instance.detailsController.AddResult(new ResultData() - { - initialContentText = result - }); + GameManager.Instance.detailsController.AddResult( + new ResultData() { initialContentText = result } + ); }; - private void Start() { StartCoroutine(SetTimeout(1.0f)); @@ -35,45 +33,57 @@ IEnumerator SetTimeout(float delay) var systemInfo = WX.GetSystemInfoSync(); var canvasWidth = (int)(systemInfo.screenWidth * systemInfo.pixelRatio); var canvasHeight = (int)(systemInfo.screenHeight * systemInfo.pixelRatio); - _button = WX.CreateUserInfoButton(Math.Abs((int)position.x), - Math.Abs((int)position.y), - (int)(size.x * canvasWidth / 1080f), - (int)(size.y * canvasWidth / 1080f), - "en", - true); + _button = WX.CreateUserInfoButton( + Math.Abs((int)position.x), + Math.Abs((int)position.y), + (int)(size.x * canvasWidth / 1080f), + (int)(size.y * canvasWidth / 1080f), + "en", + true + ); _button.OnTap(_onTap); } - // 测试 API protected override void TestAPI(string[] args) { } - // 微信小游戏示例 demo + // 微信小游戏示例 demo public void getUserInfo() { - WX.GetSetting(new GetSettingOption - { - success = (res) => + WX.GetSetting( + new GetSettingOption { - Debug.Log("GetSetting\n" + JsonMapper.ToJson(res)); - if (res.authSetting["scope.userInfo"]) + success = (res) => { - WX.GetUserInfo(new GetUserInfoOption + Debug.Log("GetSetting\n" + JsonMapper.ToJson(res)); + if (res.authSetting["scope.userInfo"]) { - success = (res) => - { - Debug.Log("getuserinfo\n" + JsonMapper.ToJson(res)); - } - }); - } - else - { - // 参数依次为 x, y, width, height, lang, withCredentials - WXUserInfoButton button = WX.CreateUserInfoButton(20, 20, 400, 200, "en", true); - button.OnTap(_onTap); + WX.GetUserInfo( + new GetUserInfoOption + { + success = (res) => + { + Debug.Log("getuserinfo\n" + JsonMapper.ToJson(res)); + } + } + ); + } + else + { + // 参数依次为 x, y, width, height, lang, withCredentials + WXUserInfoButton button = WX.CreateUserInfoButton( + 20, + 20, + 400, + 200, + "en", + true + ); + button.OnTap(_onTap); + } } } - }); + ); } private void OnDestroy() diff --git a/Demo/API_V2/Assets/API/Payment/requestMidasPayment/RequestMidasPayment.cs b/Demo/API_V2/Assets/API/Payment/requestMidasPayment/RequestMidasPayment.cs index 469396844..f05e8d4e9 100644 --- a/Demo/API_V2/Assets/API/Payment/requestMidasPayment/RequestMidasPayment.cs +++ b/Demo/API_V2/Assets/API/Payment/requestMidasPayment/RequestMidasPayment.cs @@ -1,6 +1,7 @@ -using System; -using WeChatWASM; +using System; using UnityEngine; +using WeChatWASM; + public class RequestMidasPayment : Details { // 测试 API @@ -8,29 +9,29 @@ protected override void TestAPI(string[] args) { pay(); } + public void pay() { // 补充自己的信息,才能使用 - WX.RequestMidasPayment(new RequestMidasPaymentOption() - { - mode = "game", - env = 0, - offerId = "xxxx", //在米大师侧申请的应用 id - currencyType = "CNY", - success = (res) => - { - Debug.Log("pay success!"); - }, - fail = (res) => + WX.RequestMidasPayment( + new RequestMidasPaymentOption() { - Debug.Log("pay fail:" + res.errMsg); + mode = "game", + env = 0, + offerId = "xxxx", //在米大师侧申请的应用 id + currencyType = "CNY", + success = (res) => + { + Debug.Log("pay success!"); + }, + fail = (res) => + { + Debug.Log("pay fail:" + res.errMsg); + } } - }); + ); // 显示成功的提示 - WX.ShowToast(new ShowToastOption() - { - title = "已调用虚拟支付" - }); + WX.ShowToast(new ShowToastOption() { title = "已调用虚拟支付" }); } } diff --git a/Demo/API_V2/Assets/API/PlayerPrefs/PlayerPrefsManager.cs b/Demo/API_V2/Assets/API/PlayerPrefs/PlayerPrefsManager.cs index 50bba1802..bcb829a22 100644 --- a/Demo/API_V2/Assets/API/PlayerPrefs/PlayerPrefsManager.cs +++ b/Demo/API_V2/Assets/API/PlayerPrefs/PlayerPrefsManager.cs @@ -1,4 +1,4 @@ -using UnityEngine; +using UnityEngine; using WeChatWASM; public class PlayerPrefsManager : MonoBehaviour @@ -10,13 +10,11 @@ public void RunPlayerPrefs() PlayerPrefs.SetInt("myintkey", 123); PlayerPrefs.SetFloat("myfloatkey", 1.23f); - var res = $"PlayerPrefs mystringkey:{PlayerPrefs.GetString("mystringkey")}" - + $"\nPlayerPrefs myintkey:{PlayerPrefs.GetInt("myintkey")}" - + $"\nPlayerPrefs myfloatkey:{PlayerPrefs.GetFloat("myfloatkey")}"; - - WX.ShowModal(new ShowModalOption() - { - content = res - }); + var res = + $"PlayerPrefs mystringkey:{PlayerPrefs.GetString("mystringkey")}" + + $"\nPlayerPrefs myintkey:{PlayerPrefs.GetInt("myintkey")}" + + $"\nPlayerPrefs myfloatkey:{PlayerPrefs.GetFloat("myfloatkey")}"; + + WX.ShowModal(new ShowModalOption() { content = res }); } } diff --git a/Demo/API_V2/Assets/API/Render/Render/Render.cs b/Demo/API_V2/Assets/API/Render/Render/Render.cs index ca7cfc9da..00a79e705 100644 --- a/Demo/API_V2/Assets/API/Render/Render/Render.cs +++ b/Demo/API_V2/Assets/API/Render/Render/Render.cs @@ -6,8 +6,7 @@ public class Render : Details { - - private void Start() + private void Start() { GameManager.Instance.detailsController.BindExtraButtonAction(0, loadFont); } @@ -18,16 +17,19 @@ protected override void TestAPI(string[] args) setPreferredFramesPerSecond(); } - public void setPreferredFramesPerSecond() { + public void setPreferredFramesPerSecond() + { WX.SetPreferredFramesPerSecond(50); } - public void loadFont() { + public void loadFont() + { var font = WX.LoadFont("TencentSans-W7.subset.ttf"); Debug.Log(font); } - public void Destroy() { + public void Destroy() + { WX.SetPreferredFramesPerSecond(60); } } diff --git a/Demo/API_V2/Assets/API/Report/ReportEvent/ReportEvent.cs b/Demo/API_V2/Assets/API/Report/ReportEvent/ReportEvent.cs index 037570db5..054c7cc34 100644 --- a/Demo/API_V2/Assets/API/Report/ReportEvent/ReportEvent.cs +++ b/Demo/API_V2/Assets/API/Report/ReportEvent/ReportEvent.cs @@ -1,5 +1,5 @@ -using System.Collections.Generic; using System; +using System.Collections.Generic; using Newtonsoft.Json; using UnityEngine; using WeChatWASM; @@ -23,18 +23,11 @@ protected override void TestAPI(string[] args) // 事件上报 private void Report(string stringdata, string intdata) { - EventData eventData = new EventData - { - data1 = stringdata, - data2 = int.Parse(intdata) - }; + EventData eventData = new EventData { data1 = stringdata, data2 = int.Parse(intdata) }; WX.ReportEvent("test", eventData); // 显示成功的提示 - WX.ShowToast(new ShowToastOption() - { - title = "事件已上传,可以到we分析平台中查看" - }); + WX.ShowToast(new ShowToastOption() { title = "事件已上传,可以到we分析平台中查看" }); } } diff --git a/Demo/API_V2/Assets/API/Share/ShareAppMessage/ShareAppMessage.cs b/Demo/API_V2/Assets/API/Share/ShareAppMessage/ShareAppMessage.cs index 29cb86ffc..710414858 100644 --- a/Demo/API_V2/Assets/API/Share/ShareAppMessage/ShareAppMessage.cs +++ b/Demo/API_V2/Assets/API/Share/ShareAppMessage/ShareAppMessage.cs @@ -1,18 +1,17 @@ -using UnityEngine; +using UnityEngine; using WeChatWASM; -public class ShareAppMessage: Details +public class ShareAppMessage : Details { // 测试 API - protected override void TestAPI(string[] args) { - Share(); + protected override void TestAPI(string[] args) + { + Share(); } // 分享 - private void Share() { - WX.ShareAppMessage(new ShareAppMessageOption() { - title = "小游戏分享" - }); + private void Share() + { + WX.ShareAppMessage(new ShareAppMessageOption() { title = "小游戏分享" }); } - } diff --git a/Demo/API_V2/Assets/API/Share/ShareEvent/ShareEvent.cs b/Demo/API_V2/Assets/API/Share/ShareEvent/ShareEvent.cs index 30bb432e7..60d4f1631 100644 --- a/Demo/API_V2/Assets/API/Share/ShareEvent/ShareEvent.cs +++ b/Demo/API_V2/Assets/API/Share/ShareEvent/ShareEvent.cs @@ -6,40 +6,48 @@ public class ShareEvent : Details { - private bool _isListeningShareTimeline = false; - private readonly Action> _onShareTimelineCallback = (callback) => { - callback(new OnShareTimelineListenerResult - { - imageUrl = "xxx", - imagePreviewUrl = "yy", - imagePreviewUrlId = "xx", - imageUrlId = "xxx", - path = "xx", - query = "xx", - title = "test", - }); + private readonly Action> _onShareTimelineCallback = ( + callback + ) => + { + callback( + new OnShareTimelineListenerResult + { + imageUrl = "xxx", + imagePreviewUrl = "yy", + imagePreviewUrlId = "xx", + imageUrlId = "xxx", + path = "xx", + query = "xx", + title = "test", + } + ); }; - private readonly Action _onShareMessageToFriend = (res) => { + private readonly Action _onShareMessageToFriend = (res) => + { var result = "onShareMessageToFriend\n" + JsonMapper.ToJson(res); - GameManager.Instance.detailsController.AddResult(new ResultData() - { - initialContentText = result - }); + GameManager.Instance.detailsController.AddResult( + new ResultData() { initialContentText = result } + ); }; - private readonly Action> _onShareAppMessageCallback = (callback) => { - callback(new WXShareAppMessageParam - { - title = "转发标题", - imageUrl = "xx", - query = "key1=val1&key2=val2" - }); + private readonly Action> _onShareAppMessageCallback = ( + callback + ) => + { + callback( + new WXShareAppMessageParam + { + title = "转发标题", + imageUrl = "xx", + query = "key1=val1&key2=val2" + } + ); }; - private void Start() { GameManager.Instance.detailsController.BindExtraButtonAction(0, showShareMenu); @@ -55,137 +63,157 @@ private void Start() // 测试 API protected override void TestAPI(string[] args) { - updateShareMenu(); + updateShareMenu(); } - public void updateShareMenu() { - var parameter = new UpdatableMessageFrontEndParameter[] { - new UpdatableMessageFrontEndParameter { - name = "xxx", - value = "yyy" - }, - new UpdatableMessageFrontEndParameter { - name = "zz", - value = "kk" - } + public void updateShareMenu() + { + var parameter = new UpdatableMessageFrontEndParameter[] + { + new UpdatableMessageFrontEndParameter { name = "xxx", value = "yyy" }, + new UpdatableMessageFrontEndParameter { name = "zz", value = "kk" } }; - var info = new UpdatableMessageFrontEndTemplateInfo{ - parameterList = parameter - }; + var info = new UpdatableMessageFrontEndTemplateInfo { parameterList = parameter }; - WX.UpdateShareMenu(new UpdateShareMenuOption - { - isPrivateMessage = true, - activityId = "xxx", - templateInfo = info, - success = (res) => { - WX.ShowToast(new ShowToastOption + WX.UpdateShareMenu( + new UpdateShareMenuOption + { + isPrivateMessage = true, + activityId = "xxx", + templateInfo = info, + success = (res) => + { + WX.ShowToast(new ShowToastOption { title = "设置成功" }); + }, + fail = (res) => { - title = "设置成功" - }); - }, - fail = (res) => { - Debug.Log("fail" + res.errMsg); - }, - complete = (res) => { - Debug.Log("complete"); + Debug.Log("fail" + res.errMsg); + }, + complete = (res) => + { + Debug.Log("complete"); + } } - }); + ); } - public void showShareMenu() { - WX.ShowShareMenu(new ShowShareMenuOption - { - withShareTicket = true, - menus = new string[] {"shareAppMessage", "shareTimeline"}, - success = (res) => { - Debug.Log("success"); - }, - fail = (res) => { - Debug.Log("fail" + res.errMsg); - }, - complete = (res) => { - Debug.Log("complete"); + public void showShareMenu() + { + WX.ShowShareMenu( + new ShowShareMenuOption + { + withShareTicket = true, + menus = new string[] { "shareAppMessage", "shareTimeline" }, + success = (res) => + { + Debug.Log("success"); + }, + fail = (res) => + { + Debug.Log("fail" + res.errMsg); + }, + complete = (res) => + { + Debug.Log("complete"); + } } - }); + ); } - public void hideShareMenu() { - WX.HideShareMenu(new HideShareMenuOption - { - menus = new string[] {"shareAppMessage", "shareTimeline"}, - success = (res) => { - Debug.Log("success"); - }, - fail = (res) => { - Debug.Log("fail" + res.errMsg); - }, - complete = (res) => { - Debug.Log("complete"); + public void hideShareMenu() + { + WX.HideShareMenu( + new HideShareMenuOption + { + menus = new string[] { "shareAppMessage", "shareTimeline" }, + success = (res) => + { + Debug.Log("success"); + }, + fail = (res) => + { + Debug.Log("fail" + res.errMsg); + }, + complete = (res) => + { + Debug.Log("complete"); + } } - }); + ); } - public void showShareImageMenu() { - WX.DownloadFile(new DownloadFileOption - { - url = "xxxxx", - success = (res) => { - WX.ShowShareImageMenu(new ShowShareImageMenuOption + public void showShareImageMenu() + { + WX.DownloadFile( + new DownloadFileOption + { + url = "xxxxx", + success = (res) => { - path = res.tempFilePath, - style = "default", - success = (res) => { - Debug.Log("success"); - }, - fail = (res) => { - Debug.Log("fail" + res.errMsg); - }, - complete = (res) => { - Debug.Log("complete"); - } - }); + WX.ShowShareImageMenu( + new ShowShareImageMenuOption + { + path = res.tempFilePath, + style = "default", + success = (res) => + { + Debug.Log("success"); + }, + fail = (res) => + { + Debug.Log("fail" + res.errMsg); + }, + complete = (res) => + { + Debug.Log("complete"); + } + } + ); + } } - }); + ); } - public void setMessageToFriendQuery() { - var isSuccess = WX.SetMessageToFriendQuery(new SetMessageToFriendQueryOption - { - shareMessageToFriendScene = 1, - query = "abcd" - }); - WX.ShowToast(new ShowToastOption - { - title = isSuccess ? "true" : "false" - }); + public void setMessageToFriendQuery() + { + var isSuccess = WX.SetMessageToFriendQuery( + new SetMessageToFriendQueryOption { shareMessageToFriendScene = 1, query = "abcd" } + ); + WX.ShowToast(new ShowToastOption { title = isSuccess ? "true" : "false" }); } - public void setHandoffQuery() { + public void setHandoffQuery() + { var isSuccess = WX.SetHandoffQuery("xxx"); - WX.ShowToast(new ShowToastOption - { - title = isSuccess ? "true" : "false" - }); + WX.ShowToast(new ShowToastOption { title = isSuccess ? "true" : "false" }); } - public void onShareTimeline() { - if (!_isListeningShareTimeline) { + public void onShareTimeline() + { + if (!_isListeningShareTimeline) + { WX.OnShareTimeline(_onShareTimelineCallback); - } else { + } + else + { WX.OffShareTimeline(_onShareTimelineCallback); } _isListeningShareTimeline = !_isListeningShareTimeline; - GameManager.Instance.detailsController.ChangeExtraButtonText(5, _isListeningShareTimeline ? "取消监听分享到朋友圈" : "开始监听分享到朋友圈"); + GameManager.Instance.detailsController.ChangeExtraButtonText( + 5, + _isListeningShareTimeline ? "取消监听分享到朋友圈" : "开始监听分享到朋友圈" + ); } - public void onShareMessageToFriend() { + public void onShareMessageToFriend() + { WX.OnShareMessageToFriend(_onShareMessageToFriend); } - public void onShareAppMessage() { - var defaultParam = new WXShareAppMessageParam + public void onShareAppMessage() + { + var defaultParam = new WXShareAppMessageParam { title = "转发标题", imageUrl = "xx", @@ -194,8 +222,8 @@ public void onShareAppMessage() { WX.OnShareAppMessage(defaultParam, _onShareAppMessageCallback); } - private void OnDestroy() { + private void OnDestroy() + { WX.OffShareTimeline(_onShareTimelineCallback); } } - diff --git a/Demo/API_V2/Assets/API/Share/ShareEvent2/ShareEvent2.cs b/Demo/API_V2/Assets/API/Share/ShareEvent2/ShareEvent2.cs index 722d93c76..12ce36102 100644 --- a/Demo/API_V2/Assets/API/Share/ShareEvent2/ShareEvent2.cs +++ b/Demo/API_V2/Assets/API/Share/ShareEvent2/ShareEvent2.cs @@ -6,33 +6,33 @@ public class ShareEvent2 : Details { - private bool _isListeningHandoff = false; private bool _isListeningCopyUrl = false; private bool _isListeningAddToFavorites = false; - private readonly Action> _onHandoff = (callback) => { - callback(new OnHandoffListenerResult - { - query = "xxxx" - }); + private readonly Action> _onHandoff = (callback) => + { + callback(new OnHandoffListenerResult { query = "xxxx" }); }; - private readonly Action> _onCopyUrl = (callback) => { - callback(new OnCopyUrlListenerResult - { - query = "xx" - }); + private readonly Action> _onCopyUrl = (callback) => + { + callback(new OnCopyUrlListenerResult { query = "xx" }); }; - private readonly Action> _onAddToFavorites = (callback) => { - callback(new OnAddToFavoritesListenerResult - { - title = "收藏标题", - imageUrl = "xx", - query = "key1=val1&key2=val2", - disableForward = false - }); + private readonly Action> _onAddToFavorites = ( + callback + ) => + { + callback( + new OnAddToFavoritesListenerResult + { + title = "收藏标题", + imageUrl = "xx", + query = "key1=val1&key2=val2", + disableForward = false + } + ); }; private void Start() @@ -46,80 +46,111 @@ private void Start() // 测试 API protected override void TestAPI(string[] args) { - onHandoff(); + onHandoff(); } - public void onHandoff() { - if (!_isListeningHandoff) { + public void onHandoff() + { + if (!_isListeningHandoff) + { WX.OnHandoff(_onHandoff); - } else { + } + else + { WX.OffHandoff(_onHandoff); } _isListeningHandoff = !_isListeningHandoff; - GameManager.Instance.detailsController.ChangeInitialButtonText(_isListeningHandoff ? "取消监听在电脑上打开" : "开始监听在电脑上打开"); + GameManager.Instance.detailsController.ChangeInitialButtonText( + _isListeningHandoff ? "取消监听在电脑上打开" : "开始监听在电脑上打开" + ); } - public void onCopyUrl() { - if (!_isListeningCopyUrl) { + public void onCopyUrl() + { + if (!_isListeningCopyUrl) + { WX.OnCopyUrl(_onCopyUrl); - } else { + } + else + { WX.OffCopyUrl(_onCopyUrl); } _isListeningCopyUrl = !_isListeningCopyUrl; - GameManager.Instance.detailsController.ChangeExtraButtonText(0, _isListeningCopyUrl ? "取消监听复制链接" : "开始监听复制链接"); - } - - public void onAddToFavorites() { - if (!_isListeningAddToFavorites) { + GameManager.Instance.detailsController.ChangeExtraButtonText( + 0, + _isListeningCopyUrl ? "取消监听复制链接" : "开始监听复制链接" + ); + } + + public void onAddToFavorites() + { + if (!_isListeningAddToFavorites) + { WX.OnAddToFavorites(_onAddToFavorites); - } else { + } + else + { WX.OffAddToFavorites(_onAddToFavorites); } _isListeningAddToFavorites = !_isListeningAddToFavorites; - GameManager.Instance.detailsController.ChangeExtraButtonText(1, _isListeningAddToFavorites ? "取消监听收藏" : "开始监听收藏"); + GameManager.Instance.detailsController.ChangeExtraButtonText( + 1, + _isListeningAddToFavorites ? "取消监听收藏" : "开始监听收藏" + ); } - public void getShareInfo() { - WX.GetShareInfo(new GetShareInfoOption - { - shareTicket = "xxx", - timeout = 2000, - success = (res) => { - Debug.Log("success"); - }, - fail = (res) => { - Debug.Log("fail" + res.errMsg); - }, - complete = (res) => { - Debug.Log("complete"); + public void getShareInfo() + { + WX.GetShareInfo( + new GetShareInfoOption + { + shareTicket = "xxx", + timeout = 2000, + success = (res) => + { + Debug.Log("success"); + }, + fail = (res) => + { + Debug.Log("fail" + res.errMsg); + }, + complete = (res) => + { + Debug.Log("complete"); + } } - }); + ); } - public void authPrivateMessage() { - WX.AuthPrivateMessage(new AuthPrivateMessageOption - { - shareTicket = "xxxxxx", - success = (res) => { - Debug.Log("authPrivateMessage success" + JsonMapper.ToJson(res)); - // res - // { - // errMsg: 'authPrivateMessage:ok' - // valid: true - // iv: 'xxxx', - // encryptedData: 'xxxxxx' - // } - }, - fail = (res) => { - Debug.Log("authPrivateMessage fail" + res.errMsg); + public void authPrivateMessage() + { + WX.AuthPrivateMessage( + new AuthPrivateMessageOption + { + shareTicket = "xxxxxx", + success = (res) => + { + Debug.Log("authPrivateMessage success" + JsonMapper.ToJson(res)); + // res + // { + // errMsg: 'authPrivateMessage:ok' + // valid: true + // iv: 'xxxx', + // encryptedData: 'xxxxxx' + // } + }, + fail = (res) => + { + Debug.Log("authPrivateMessage fail" + res.errMsg); + } } - }); + ); } - private void OnDestroy() { + private void OnDestroy() + { WX.OffHandoff(_onHandoff); WX.OffCopyUrl(_onCopyUrl); WX.OffAddToFavorites(_onAddToFavorites); } } - diff --git a/Demo/API_V2/Assets/API/UnityWebSocket/UnityWebSocket.cs b/Demo/API_V2/Assets/API/UnityWebSocket/UnityWebSocket.cs index c9f29e5a1..c594b1267 100644 --- a/Demo/API_V2/Assets/API/UnityWebSocket/UnityWebSocket.cs +++ b/Demo/API_V2/Assets/API/UnityWebSocket/UnityWebSocket.cs @@ -21,7 +21,11 @@ public class UnityWebSocket : MonoBehaviour private void OnGUI() { var scale = UnityEngine.Screen.width / 800f; - GUI.matrix = Matrix4x4.TRS(new Vector3(0, 0, 0), Quaternion.identity, new Vector3(scale, scale, 1)); + GUI.matrix = Matrix4x4.TRS( + new Vector3(0, 0, 0), + Quaternion.identity, + new Vector3(scale, scale, 1) + ); var width = GUILayout.Width(UnityEngine.Screen.width / scale - 10); var w = UnityEngine.Screen.width / scale - 10; WebSocketState state = socket == null ? WebSocketState.Closed : socket.ReadyState; @@ -30,11 +34,19 @@ private void OnGUI() style.fontSize = 26; GUILayout.BeginHorizontal(); - GUILayout.Label("", GUILayout.Width(UnityEngine.Screen.width / scale - 100), GUILayout.Height(250)); + GUILayout.Label( + "", + GUILayout.Width(UnityEngine.Screen.width / scale - 100), + GUILayout.Height(250) + ); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); - GUILayout.Label("SDK Version: " + Settings.VERSION, style, GUILayout.Width(UnityEngine.Screen.width / scale - 300)); + GUILayout.Label( + "SDK Version: " + Settings.VERSION, + style, + GUILayout.Width(UnityEngine.Screen.width / scale - 300) + ); GUI.color = green; GUILayout.Label($"FPS: {fps:F2}", style, GUILayout.Width(300)); GUI.color = Color.white; @@ -42,7 +54,12 @@ private void OnGUI() GUILayout.BeginHorizontal(); GUILayout.Label("State: ", style, GUILayout.Width(70)); - GUI.color = WebSocketState.Closed == state ? red : WebSocketState.Open == state ? green : wait; + GUI.color = + WebSocketState.Closed == state + ? red + : WebSocketState.Open == state + ? green + : wait; GUILayout.Label($"{state}", style, GUILayout.Width(300)); GUI.color = Color.white; GUILayout.EndHorizontal(); @@ -57,7 +74,14 @@ private void OnGUI() style.normal.background = MakeTex(2, 2, Color.grey); GUI.enabled = state == WebSocketState.Closed; - if (GUILayout.Button(state == WebSocketState.Connecting ? "Connecting..." : "Connect", style, GUILayout.Width(w / 2), GUILayout.Height(45))) + if ( + GUILayout.Button( + state == WebSocketState.Connecting ? "Connecting..." : "Connect", + style, + GUILayout.Width(w / 2), + GUILayout.Height(45) + ) + ) { if (WebSocketState.Connecting != 0) { @@ -73,7 +97,14 @@ private void OnGUI() } GUI.enabled = state == WebSocketState.Open; - if (GUILayout.Button(state == WebSocketState.Closing ? "Closing..." : "Close", style, GUILayout.Width(w / 2), GUILayout.Height(45))) + if ( + GUILayout.Button( + state == WebSocketState.Closing ? "Closing..." : "Close", + style, + GUILayout.Width(w / 2), + GUILayout.Height(45) + ) + ) { AddLog(string.Format("Closing...")); socket.CloseAsync(); @@ -93,13 +124,19 @@ private void OnGUI() GUILayout.BeginHorizontal(); style.alignment = TextAnchor.MiddleCenter; - if (GUILayout.Button("Send", style, GUILayout.Width(w / 2), GUILayout.Height(45)) && !string.IsNullOrEmpty(sendText)) + if ( + GUILayout.Button("Send", style, GUILayout.Width(w / 2), GUILayout.Height(45)) + && !string.IsNullOrEmpty(sendText) + ) { socket.SendAsync(sendText); AddLog(string.Format("Send: {0}", sendText)); sendCount += 1; } - if (GUILayout.Button("Send Bytes", style, GUILayout.Width(w / 2), GUILayout.Height(45)) && !string.IsNullOrEmpty(sendText)) + if ( + GUILayout.Button("Send Bytes", style, GUILayout.Width(w / 2), GUILayout.Height(45)) + && !string.IsNullOrEmpty(sendText) + ) { var bytes = System.Text.Encoding.UTF8.GetBytes(sendText); socket.SendAsync(bytes); @@ -109,7 +146,10 @@ private void OnGUI() GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); - if (GUILayout.Button("Send x100", style, GUILayout.Width(w / 2), GUILayout.Height(45)) && !string.IsNullOrEmpty(sendText)) + if ( + GUILayout.Button("Send x100", style, GUILayout.Width(w / 2), GUILayout.Height(45)) + && !string.IsNullOrEmpty(sendText) + ) { for (int i = 0; i < 100; i++) { @@ -119,7 +159,14 @@ private void OnGUI() sendCount += 1; } } - if (GUILayout.Button("Send Bytes x100", style, GUILayout.Width(w / 2), GUILayout.Height(45)) && !string.IsNullOrEmpty(sendText)) + if ( + GUILayout.Button( + "Send Bytes x100", + style, + GUILayout.Width(w / 2), + GUILayout.Height(45) + ) && !string.IsNullOrEmpty(sendText) + ) { for (int i = 0; i < 100; i++) { @@ -150,7 +197,11 @@ private void OnGUI() sendCount = 0; } style.alignment = TextAnchor.UpperLeft; - scrollPos = GUILayout.BeginScrollView(scrollPos, GUILayout.MaxHeight(UnityEngine.Screen.height / scale - 270), width); + scrollPos = GUILayout.BeginScrollView( + scrollPos, + GUILayout.MaxHeight(UnityEngine.Screen.height / scale - 270), + width + ); style.normal.background = null; GUILayout.Label(log, style); GUILayout.EndScrollView(); @@ -158,8 +209,10 @@ private void OnGUI() private void AddLog(string str) { - if (!logMessage) return; - if (str.Length > 100) str = str.Substring(0, 100) + "..."; + if (!logMessage) + return; + if (str.Length > 100) + str = str.Substring(0, 100) + "..."; log += str + "\n"; if (log.Length > 22 * 1024) { @@ -221,6 +274,7 @@ private void OnApplicationQuit() private int frame = 0; private float time = 0; private float fps = 0; + private void Update() { frame += 1; diff --git a/Demo/API_V2/Assets/Scripts/APIController.cs b/Demo/API_V2/Assets/Scripts/APIController.cs index d51557f9b..ec9ad2a36 100644 --- a/Demo/API_V2/Assets/Scripts/APIController.cs +++ b/Demo/API_V2/Assets/Scripts/APIController.cs @@ -3,22 +3,34 @@ public class APIController : MonoBehaviour { [Header("API Data")] - [SerializeField] private APISO apiSO; - + [SerializeField] + private APISO apiSO; + [Header("Elements")] - [SerializeField] private GameObject categoryPrefab; - [SerializeField] private Transform apiCategoriesTransform; - [SerializeField] private GameObject abilityPrefab; - [SerializeField] private Transform abilitiesTransform; - + [SerializeField] + private GameObject categoryPrefab; + + [SerializeField] + private Transform apiCategoriesTransform; + + [SerializeField] + private GameObject abilityPrefab; + + [SerializeField] + private Transform abilitiesTransform; + [Header("Title Transform")] - [SerializeField] private RectTransform title; - + [SerializeField] + private RectTransform title; + private void Start() { Init(); // 根据系统安全区域调整标题的位置 - title.anchoredPosition = new Vector2(title.anchoredPosition.x, -125f - (float)GameManager.Instance.systemInfo.safeArea.top); + title.anchoredPosition = new Vector2( + title.anchoredPosition.x, + -125f - (float)GameManager.Instance.systemInfo.safeArea.top + ); } // 清除所有分类 @@ -32,7 +44,7 @@ private void ClearCategories() DestroyImmediate(child.gameObject); } } - + // 清除所有能力 private void ClearAbilities() { @@ -44,13 +56,13 @@ private void ClearAbilities() DestroyImmediate(child.gameObject); } } - + // 初始化 APIController,创建分类和能力 public void Init() { ClearCategories(); ClearAbilities(); - + // 为每个分类实例化一个预制体并初始化 foreach (var category in apiSO.categoryList) { @@ -65,4 +77,4 @@ public void Init() abilityObj.GetComponent().Init(ability); } } -} \ No newline at end of file +} diff --git a/Demo/API_V2/Assets/Scripts/Ability.cs b/Demo/API_V2/Assets/Scripts/Ability.cs index 14db32ddc..95d404084 100644 --- a/Demo/API_V2/Assets/Scripts/Ability.cs +++ b/Demo/API_V2/Assets/Scripts/Ability.cs @@ -1,18 +1,23 @@ -using System; +using System; using UnityEngine; using UnityEngine.UI; public class Ability : MonoBehaviour { [Header("Ability Data")] - [SerializeField] private AbilitySO abilitySO; - + [SerializeField] + private AbilitySO abilitySO; + [Header("References")] - [SerializeField] private Text abilityText; - [SerializeField] private Image abilityImage; - + [SerializeField] + private Text abilityText; + + [SerializeField] + private Image abilityImage; + [Header("Button")] - [SerializeField] private Button button; + [SerializeField] + private Button button; private void Start() { @@ -23,7 +28,7 @@ private void Start() public void Init(AbilitySO so) { abilitySO = so; - + gameObject.name = abilitySO.abilityName; abilityText.text = abilitySO.abilityName; abilityImage.sprite = abilitySO.abilitySprite; @@ -35,4 +40,4 @@ public void OnClick() // 加载对应的场景 GameManager.Instance.LoadScene(abilitySO.AbilitySceneName); } -} \ No newline at end of file +} diff --git a/Demo/API_V2/Assets/Scripts/BackToMainCanvasButton.cs b/Demo/API_V2/Assets/Scripts/BackToMainCanvasButton.cs index d8953bef9..f9354f6d3 100644 --- a/Demo/API_V2/Assets/Scripts/BackToMainCanvasButton.cs +++ b/Demo/API_V2/Assets/Scripts/BackToMainCanvasButton.cs @@ -1,7 +1,7 @@ -using UnityEngine; -using UnityEngine.UI; -using UnityEngine.SceneManagement; using System.Reflection; +using UnityEngine; +using UnityEngine.SceneManagement; +using UnityEngine.UI; // 添加 Button 组件的依赖 [RequireComponent(typeof(Button))] @@ -10,7 +10,8 @@ public class BackToMainCanvasButton : MonoBehaviour private void Awake() { // 为按钮添加点击事件监听器 - GetComponent