Skip to content

Commit 507180c

Browse files
authored
Merge pull request #925 from VincentWSZ/Canvas
feat(API_V2): 添加渲染-截屏条目
2 parents d37a69a + 3798de9 commit 507180c

File tree

9 files changed

+668
-1
lines changed

9 files changed

+668
-1
lines changed

Demo/API_V2/Assets/API/Media/VideoDecoder/VideoDecoderSO.asset

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@ MonoBehaviour:
2323
- buttonText: "\u8DF3\u8F6C"
2424
- buttonText: "\u83B7\u5F97\u4E0B\u4E00\u5E27"
2525
initialResultList: []
26+
entryOrder: 0

Demo/API_V2/Assets/API/Render/RenderSO.asset

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@ MonoBehaviour:
1717
entryList:
1818
- {fileID: 11400000, guid: 3742edf3f50854504ba8632134064e94, type: 2}
1919
- {fileID: 11400000, guid: c185ac653050d49608ea734a26e8dbaa, type: 2}
20+
- {fileID: 11400000, guid: f9a70ffa3b7f4db40b550f6b153c4ed2, type: 2}
2021
categoryOrder: 8

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

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
using UnityEngine;
4+
using WeChatWASM;
5+
using LitJson;
6+
7+
public class ToTempFilePath : Details
8+
{
9+
protected override void TestAPI(string[] args)
10+
{
11+
if (args[0] == "同步执行")
12+
{
13+
LoadCanvasToTempFilePathSync();
14+
}
15+
else
16+
{
17+
LoadCanvasToTempFilePath();
18+
}
19+
}
20+
21+
// 异步
22+
private void LoadCanvasToTempFilePath()
23+
{// 根据options数组的索引获取值
24+
float x = GetOptionValue(1);
25+
float y = GetOptionValue(2);
26+
float width = GetOptionValue(3);
27+
float height = GetOptionValue(4);
28+
float destWidth = GetOptionValue(5);
29+
float destHeight = GetOptionValue(6);
30+
string fileType = GetOptionString(7, "png");
31+
float quality = GetOptionValue(8);
32+
33+
string optionsInfo = $"当前参数值:\nx={x}\ny={y}\nwidth={width}\nheight={height}\ndestWidth={destWidth}\ndestHeight={destHeight}\nfileType={fileType}\nquality={quality}";
34+
35+
WXCanvas.ToTempFilePath(new WXToTempFilePathParam()
36+
{
37+
x = (int)x,
38+
y = (int)y,
39+
width = (int)width,
40+
height = (int)height,
41+
destWidth = (int)destWidth,
42+
destHeight = (int)destHeight,
43+
fileType = fileType,
44+
quality = (int)quality,
45+
46+
success = (result) =>
47+
{
48+
WX.ShowModal(new ShowModalOption()
49+
{
50+
title = "截图成功(异步)",
51+
content = $"{optionsInfo}\n\n临时文件路径:\n{result.tempFilePath}",
52+
showCancel = false,
53+
confirmText = "展示截图",
54+
success = (res) =>
55+
{
56+
WX.PreviewMedia(new PreviewMediaOption()
57+
{
58+
sources = new[] { new MediaSource { url = result.tempFilePath, type = "image" } },
59+
current = 0,
60+
success = (res) =>
61+
{
62+
Debug.Log("预览成功");
63+
},
64+
fail = (res) =>
65+
{
66+
Debug.Log("预览失败");
67+
}
68+
});
69+
}
70+
});
71+
},
72+
fail = (result) =>
73+
{
74+
WX.ShowModal(new ShowModalOption()
75+
{
76+
title = "截图失败",
77+
content = JsonUtility.ToJson(result),
78+
showCancel = false
79+
});
80+
},
81+
complete = (result) =>
82+
{
83+
Debug.Log("complete");
84+
},
85+
});
86+
}
87+
88+
// 同步
89+
private void LoadCanvasToTempFilePathSync()
90+
{
91+
92+
// 根据options数组的索引获取值
93+
float x = GetOptionValue(1);
94+
float y = GetOptionValue(2);
95+
float width = GetOptionValue(3);
96+
float height = GetOptionValue(4);
97+
float destWidth = GetOptionValue(5);
98+
float destHeight = GetOptionValue(6);
99+
string fileType = GetOptionString(7, "png");
100+
float quality = GetOptionValue(8);
101+
102+
string optionsInfo = $"当前参数值:\nx={x}\ny={y}\nwidth={width}\nheight={height}\ndestWidth={destWidth}\ndestHeight={destHeight}\nfileType={fileType}\nquality={quality}";
103+
104+
var tempFilePath = WXCanvas.ToTempFilePathSync(new WXToTempFilePathSyncParam()
105+
{
106+
x = (int)x,
107+
y = (int)y,
108+
width = (int)width,
109+
height = (int)height,
110+
destWidth = (int)destWidth,
111+
destHeight = (int)destHeight,
112+
fileType = fileType,
113+
quality = (int)quality,
114+
});
115+
// 显示同步访问的结果
116+
WX.ShowModal(new ShowModalOption()
117+
{
118+
title = "截图成功(同步)",
119+
content = $"{optionsInfo}\n\n临时文件路径:\n{tempFilePath}",
120+
showCancel = false,
121+
confirmText = "展示截图",
122+
success = (res) =>
123+
{
124+
WX.PreviewMedia(new PreviewMediaOption()
125+
{
126+
sources = new[] { new MediaSource { url = tempFilePath, type = "image" } },
127+
current = 0,
128+
success = (res) =>
129+
{
130+
Debug.Log("预览成功");
131+
},
132+
fail = (res) =>
133+
{
134+
Debug.Log("预览失败");
135+
}
136+
});
137+
}
138+
});
139+
}
140+
}

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

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
%YAML 1.1
2+
%TAG !u! tag:unity3d.com,2011:
3+
--- !u!114 &11400000
4+
MonoBehaviour:
5+
m_ObjectHideFlags: 0
6+
m_CorrespondingSourceObject: {fileID: 0}
7+
m_PrefabInstance: {fileID: 0}
8+
m_PrefabAsset: {fileID: 0}
9+
m_GameObject: {fileID: 0}
10+
m_Enabled: 1
11+
m_EditorHideFlags: 0
12+
m_Script: {fileID: 11500000, guid: fb48e4613a53bb941a20036d7c08fefb, type: 3}
13+
m_Name: ToTempFilePathSO
14+
m_EditorClassIdentifier:
15+
entryScriptTypeName: ToTempFilePath
16+
entryName: "\u622A\u5C4F"
17+
entryAPI: Canvas.toTempFilePath
18+
entryDescription: "\u5C06\u5F53\u524D Canvas \u4FDD\u5B58\u4E3A\u4E00\u4E2A\u4E34\u65F6\u6587\u4EF6\u3002"
19+
optionList:
20+
- optionName: "\u6267\u884C\u65B9\u5F0F"
21+
availableOptions:
22+
- "\u540C\u6B65\u6267\u884C"
23+
- "\u5F02\u6B65\u6267\u884C"
24+
- optionName: x
25+
availableOptions:
26+
- 0
27+
- 500
28+
- optionName: y
29+
availableOptions:
30+
- 0
31+
- 500
32+
- optionName: width
33+
availableOptions:
34+
- 0
35+
- 400
36+
- optionName: height
37+
availableOptions:
38+
- 0
39+
- 800
40+
- optionName: destWidth
41+
availableOptions:
42+
- 0
43+
- 800
44+
- optionName: destHeight
45+
availableOptions:
46+
- 0
47+
- 800
48+
- optionName: fileType
49+
availableOptions:
50+
- png
51+
- jpg
52+
- optionName: quality
53+
availableOptions:
54+
- 1.0
55+
initialButtonText: "\u8FD0\u884C\u622A\u56FE"
56+
extraButtonList: []
57+
initialResultList: []
58+
entryOrder: 0

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

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)