2
2
using System . Collections . Generic ;
3
3
using UnityEngine ;
4
4
using WeChatWASM ;
5
+ using LitJson ;
5
6
6
7
public class ToTempFilePath : Details
7
8
{
8
9
protected override void TestAPI ( string [ ] args )
9
10
{
10
- LoadCanvasToTempFilePath ( ) ;
11
+ if ( args [ 8 ] == "同步执行" )
12
+ {
13
+ LoadCanvasToTempFilePathSync ( ) ;
14
+ }
15
+ else
16
+ {
17
+ LoadCanvasToTempFilePath ( ) ;
18
+ }
11
19
}
20
+
21
+ // 异步
12
22
private void LoadCanvasToTempFilePath ( )
13
23
{ // 根据options数组的索引获取值
14
24
float x = GetOptionValue ( 0 ) ;
@@ -37,7 +47,7 @@ private void LoadCanvasToTempFilePath()
37
47
{
38
48
WX . ShowModal ( new ShowModalOption ( )
39
49
{
40
- title = "截图成功" ,
50
+ title = "截图成功(异步) " ,
41
51
content = $ "{ optionsInfo } \n \n 临时文件路径:{ result . tempFilePath } ",
42
52
showCancel = false ,
43
53
success = ( res ) =>
@@ -55,19 +65,6 @@ private void LoadCanvasToTempFilePath()
55
65
Debug . Log ( "预览失败" ) ;
56
66
}
57
67
} ) ;
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
- } ) ;
71
68
}
72
69
} ) ;
73
70
} ,
@@ -86,4 +83,56 @@ private void LoadCanvasToTempFilePath()
86
83
} ,
87
84
} ) ;
88
85
}
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 = $ "当前参数值:\n x={ x } \n y={ y } \n width={ width } \n height={ height } \n destWidth={ destWidth } \n destHeight={ destHeight } \n fileType={ fileType } \n quality={ 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
+ }
89
138
}
0 commit comments