浏览代码

SUPPORT WEBGL COPY-PASTE

/main
xingwei.zhu 6 年前
当前提交
c5bfc1b0
共有 3 个文件被更改,包括 26 次插入1 次删除
  1. 14
      Runtime/Plugins/platform/webgl/webgl.jslib
  2. 11
      Runtime/service/clipboard.cs
  3. 2
      Samples/UIWidgetSample/HoverRecognizerSample.cs

14
Runtime/Plugins/platform/webgl/webgl.jslib


UIWidgetsMessageSetObjectName: function (name) {
UIWidgetsPlugin.getMessageManager().setObjectName(Pointer_stringify(name));
},
UIWidgetsCopyTextToClipboard: function (text) {
var el = document.createElement('input');
el.value = Pointer_stringify(text);
el.setAttribute('readonly', '');
el.style = {
position: 'fixed',
left: '-9999px',
};
document.body.appendChild(el);
el.select();
document.execCommand('copy');
document.body.removeChild(el);
}
};

11
Runtime/service/clipboard.cs


using System.Runtime.InteropServices;
using RSG;
using UnityEngine;

public class UnityGUIClipboard : Clipboard {
protected override IPromise setClipboardData(ClipboardData data) {
#if UNITY_WEBGL
UIWidgetsCopyTextToClipboard(data.text);
#else
#endif
return Promise.Resolved();
}

}
#if UNITY_WEBGL
[DllImport ("__Internal")]
internal static extern void UIWidgetsCopyTextToClipboard(string text);
#endif
}
}

2
Samples/UIWidgetSample/HoverRecognizerSample.cs


return new Scaffold(
appBar: new AppBar(
title: new Center(
child: new Text("Test Hover Widget")
child: new SelectableText("Test Hover Widget")
)
),
body: new Card(

正在加载...
取消
保存