Skip to content

Commit 9a8ef78

Browse files
committed
add ToTempFilePathSync
1 parent f77b23d commit 9a8ef78

File tree

2 files changed

+68
-15
lines changed

2 files changed

+68
-15
lines changed

Demo/API_V2/Assets/API/Render/ToTempFilePath/ToTempFilePath.cs

Lines changed: 64 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,23 @@
22
using System.Collections.Generic;
33
using UnityEngine;
44
using WeChatWASM;
5+
using LitJson;
56

67
public class ToTempFilePath : Details
78
{
89
protected override void TestAPI(string[] args)
910
{
10-
LoadCanvasToTempFilePath();
11+
if (args[8] == "同步执行")
12+
{
13+
LoadCanvasToTempFilePathSync();
14+
}
15+
else
16+
{
17+
LoadCanvasToTempFilePath();
18+
}
1119
}
20+
21+
// 异步
1222
private void LoadCanvasToTempFilePath()
1323
{// 根据options数组的索引获取值
1424
float x = GetOptionValue(0);
@@ -37,7 +47,7 @@ private void LoadCanvasToTempFilePath()
3747
{
3848
WX.ShowModal(new ShowModalOption()
3949
{
40-
title = "截图成功",
50+
title = "截图成功(异步)",
4151
content = $"{optionsInfo}\n\n临时文件路径:{result.tempFilePath}",
4252
showCancel = false,
4353
success = (res) =>
@@ -55,19 +65,6 @@ private void LoadCanvasToTempFilePath()
5565
Debug.Log("预览失败");
5666
}
5767
});
58-
var fileManager = WX.GetFileSystemManager();
59-
fileManager.Access(new AccessParam()
60-
{
61-
path = result.tempFilePath,
62-
success = (res) =>
63-
{
64-
Debug.Log("文件存在");
65-
},
66-
fail = (res) =>
67-
{
68-
Debug.Log("文件不存在");
69-
}
70-
});
7168
}
7269
});
7370
},
@@ -86,4 +83,56 @@ private void LoadCanvasToTempFilePath()
8683
},
8784
});
8885
}
86+
87+
// 同步
88+
private void LoadCanvasToTempFilePathSync()
89+
{
90+
91+
// 根据options数组的索引获取值
92+
float x = GetOptionValue(0);
93+
float y = GetOptionValue(1);
94+
float width = GetOptionValue(2);
95+
float height = GetOptionValue(3);
96+
float destWidth = GetOptionValue(4);
97+
float destHeight = GetOptionValue(5);
98+
string fileType = GetOptionString(6, "png");
99+
float quality = GetOptionValue(7);
100+
101+
string optionsInfo = $"当前参数值:\nx={x}\ny={y}\nwidth={width}\nheight={height}\ndestWidth={destWidth}\ndestHeight={destHeight}\nfileType={fileType}\nquality={quality}";
102+
103+
var tempFilePath = WXCanvas.ToTempFilePathSync(new WXToTempFilePathSyncParam()
104+
{
105+
x = (int)x,
106+
y = (int)y,
107+
width = (int)width,
108+
height = (int)height,
109+
destWidth = (int)destWidth,
110+
destHeight = (int)destHeight,
111+
fileType = fileType,
112+
quality = (int)quality,
113+
});
114+
// 显示同步访问的结果
115+
WX.ShowModal(new ShowModalOption()
116+
{
117+
title = "截图成功(同步)",
118+
content = $"{optionsInfo}\n\n临时文件路径:{tempFilePath}",
119+
showCancel = false,
120+
success = (res) =>
121+
{
122+
WX.PreviewMedia(new PreviewMediaOption()
123+
{
124+
sources = new[] { new MediaSource { url = tempFilePath, type = "image" } },
125+
current = 0,
126+
success = (res) =>
127+
{
128+
Debug.Log("预览成功");
129+
},
130+
fail = (res) =>
131+
{
132+
Debug.Log("预览失败");
133+
}
134+
});
135+
}
136+
});
137+
}
89138
}

Demo/API_V2/Assets/API/Render/ToTempFilePath/ToTempFilePathSO.asset

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ MonoBehaviour:
4848
- optionName: quality
4949
availableOptions:
5050
- 1.0
51+
- optionName: "\u6267\u884C\u65B9\u5F0F"
52+
availableOptions:
53+
- "\u540C\u6B65\u6267\u884C"
54+
- "\u5F02\u6B65\u6267\u884C"
5155
initialButtonText: "\u8FD0\u884C\u622A\u56FE"
5256
extraButtonList: []
5357
initialResultList: []

0 commit comments

Comments
 (0)