我尝试将Unity外部复制的文本粘贴到WebGL构建中的InputField中,但文本未被粘贴到输入字段中。 有什么方法可以实现这一点?请提出任何想法。 谢谢提前。
例如,在Windows上打开记事本或Mac上的TextEdit,选择一些文本,复制,然后在运行在浏览器中的Unity WebGL应用程序中的InputField中单击。 粘贴(ctrl-v/cmd-v),但没有任何反应。
我尝试将Unity外部复制的文本粘贴到WebGL构建中的InputField中,但文本未被粘贴到输入字段中。 有什么方法可以实现这一点?请提出任何想法。 谢谢提前。
例如,在Windows上打开记事本或Mac上的TextEdit,选择一些文本,复制,然后在运行在浏览器中的Unity WebGL应用程序中的InputField中单击。 粘贴(ctrl-v/cmd-v),但没有任何反应。
InputField
。在剪切/复制时,它调用 Unity 来告诉当前的InputField
执行剪切/复制操作,然后获取 Unity 的剪贴板并将其放入浏览器的剪贴板中。目前,使用Unity的WebGL时,您无法复制和粘贴。
这是由于浏览器安全限制造成的。尽管Unity一直在努力工作通过使用键盘快捷键来执行复制和粘贴操作来开发WebGL的复制和粘贴机制,现在已经在某些Web浏览器上得到支持,但尚未发布。它还没有完成,所以您必须等待。
您可以在此线程中找到此解决方案的完整说明:https://forum.unity.com/threads/webgl-copy-paste-for-input-field-not-working.494765/
I was facing the same issue while developing paste functionality into my Unity project.
The requirement was user can paste the copied data into the InputFiled.
I follow these steps: -
1. Create a javascript plugin for the same with the .jslib file extension.
2. Paste this code into the created file.
mergeInto(LibraryManager.library, {
CopyPasteReader: function(gObj, vName) {
var gameObjectName = UTF8ToString(gObj);
var voidName = UTF8ToString(vName);
console.log(gameObjectName, "gameObjectName");
console.log(voidName, "voidName");
navigator.clipboard.readText().then(function(data) {
SendMessage(gameObjectName,"Paste", data);
}, function() {
SendMessage(gameObjectName, "Paste", "no text available in clipboard");
})
}
});
3. Import this plugin into the script top.
[DllImport("__Internal")]
public static extern void CopyPasteReader(string gObj, string vName);
2. Use the Update function so it will call automatically after the frame change.
void Update()
{
if (Input.GetKeyDown(KeyCode.V) && (Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl)))
{
CopyPasteReader("KYCDigilockerurlPanel","Paste");
}
}
// here KYCDigilockerurlPanel is a top parent of inputfield and Pase is a function
4. This function will check if the ctrl+v action has performed the run the "CopyPasteReader("KYCDigilockerurlPanel", "Paste");" function.
5. Crate a Paste function in your script file
private void Paste(string pasteValue)
{
Debug.Log(pasteValue + " pasteValue");
enterDigiLockerCode.text = pasteValue;
}
// here enterDigiLockerCode is an input field name
6. Attach the script on the panel "KYCDigilockerurlPanel" and create a GameObject of that Input field where you want to paste.