Skip to content

Trisibo/unity-webgl-copy-and-paste

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Unity WebGL Copy and Paste

For some reason Unity decided not to support copy and paste in WebGL. Here is an attempt to add it back in. No promises that it's perfect 😅

screenshot

At the moment there is only support for InputField and TMPro.TMP_InputField.

Instructions

  1. Download and add in this unity package into your project.

  2. If you are using TMPro.TMP_InputField then edit Assets/WebGLCopyAndPaste/Scripts/WebGLCopyAndPaste.cs and uncomment this line:

// #define WEBGL_COPY_AND_PASTE_SUPPORT_TEXTMESH_PRO
  1. Copying and pasting should work automatically when the user tries to copy/cut/paste from legacy and TextMesh Pro (if enabled) input fields. You can also copy text to the clipboard from script with WebGLCopyAndPaste.WebGLCopyAndPasteAPI.CopyToClipboard(text).

Alternatives

This might be better?: https://github.com/kou-yeung/WebGLInput

Browsers tested

The plugin has been tested an confirmed working on:

  • Edge 120.0.2210.61 (Chromium) on Windows 10, Unity 2022.3.10, 2021.3.25 and 2020.3.18.
  • Firefox 120.0.1 to 134.0.2 on Windows 10, Unity 6.0.34, 2022.3.22, 2022.3.10, 2021.3.25, 2020.3.18.
  • Safari 16.6 on macOS Ventura 13.6, Unity 2022.3.10.
  • Chrome 118.0.5993.70 on macOS Ventura 13.6, Unity 2022.3.10.
  • Firefox 120.0.1 on macOS Ventura 13.6, Unity 2022.3.10.

Issues

  • Non Alphabetic characters:

    See this thread. You apparently need to include the fonts in your Unity project.

  • Ctrl-A/⌘-A selects other HTML on the page:

    1. Make your own WebGL template that doesn't have anything to select. Maybe this one though I didn't try it.

    2. Make your own WebGL template and use user-select: none; in your CSS to make whatever parts of the page you want to prevent from being selected.

Changelog

  • 1.0.1

    • Fixed CopyToClipboard not working in insecure pages (non-https), or iframes without clipboard permissions, now it should work in most situations (as long as the obsolete JavaScript workaround is not removed from browsers).
  • 1.0.0

    • Added public CopyToClipboard method.
    • The WebGLCopyAndPasteAPI class is now in the WebGLCopyAndPaste namespace.
    • The WebGLCopyAndPasteAPI class won't be added (empty) to non-WebGL builds anymore.
    • Improved the sample, and moved it out of the plugin itself.
  • 0.4.0

    • Made the plugin work when the "WebAssembly.Table" build option is enabled.
  • 0.3.0

    • Added Preserve attribute to WebGLCopyAndPasteAPI class, and AlwaysLinkAssembly to the assembly, so Unity doesn't strip the code if the plugin is moved to a package.
  • 0.2.1

    • Fixed paste not working on some browsers.
    • Fixed labels not being visually updated on some browsers.
    • Fixed potential null reference exception when EventSystem.current is null.
    • Substituted deprecated JavaScript Window.event.
  • 0.2.0

    • Fixes for Unity 2021.2.
  • 0.1.0

    • Removed the need for MonoBehaviours.
    • Replaced messages with proper callbacks.
    • Fixed data storing in window.
  • 0.0.2

    • Support cut.
    • Support Safari.
  • 0.0.1

    • Initial Release.

License: BSD-3-Clause

About

Support Copy and Paste in Unity WebGL

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • ShaderLab 70.9%
  • HLSL 12.3%
  • C# 10.8%
  • JavaScript 6.0%