Skip to content

Commit d75f462

Browse files
committed
fix: 为WebGL平台添加剪贴板支持
为抖音小游戏环境下的WebGL平台添加剪贴板读取和写入功能,使用TTSDK的API。同时为编辑器和独立平台使用TextEditor实现剪贴板操作,以扩展跨平台兼容性。
1 parent 6d2c092 commit d75f462

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

Runtime/BlankOperationClipboard.cs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,25 @@ public static class BlankOperationClipboard
2323
/// <returns></returns>
2424
public static string GetValue()
2525
{
26-
#if UNITY_ANDROID
26+
#if UNITY_EDITOR || UNITY_STANDALONE
27+
TextEditor textEditor = new TextEditor();
28+
textEditor.OnFocus();
29+
textEditor.Paste();
30+
var content = textEditor.text;
31+
return content;
32+
#elif UNITY_WEBGL
33+
#if ENABLE_DOUYIN_MINI_GAME
34+
string content = string.Empty;
35+
TTSDK.TT.GetClipboardData((b, text) =>
36+
{
37+
if (b)
38+
{
39+
content = text;
40+
}
41+
});
42+
return content;
43+
#endif
44+
#elif UNITY_ANDROID
2745
using (AndroidJavaClass androidJavaClass = new AndroidJavaClass("com.alianhome.operationclipboard.MainActivity"))
2846
{
2947
return androidJavaClass.CallStatic<string>("GetClipBoard");
@@ -46,6 +64,10 @@ public static void SetValue(string text)
4664
textEditor.text = text;
4765
textEditor.OnFocus();
4866
textEditor.Copy();
67+
#elif UNITY_WEBGL
68+
#if ENABLE_DOUYIN_MINI_GAME
69+
TTSDK.TT.SetClipboardData(text);
70+
#endif
4971
#elif UNITY_ANDROID
5072
using (AndroidJavaClass androidJavaClass = new AndroidJavaClass("com.alianhome.operationclipboard.MainActivity"))
5173
{

0 commit comments

Comments
 (0)