Tanoda
PasteManager.cs
Go to the documentation of this file.
1using UnityEngine;
3using UnityEngine.UI;
4using System.Runtime.InteropServices;
5
6namespace TriLibCore.Samples
7{
9 public class PasteManager : MonoBehaviour
10 {
11#if UNITY_WEBGL && !UNITY_EDITOR
12 [DllImport("__Internal")]
13 private static extern void PasteManagerSetup();
14#endif
15
17 public static PasteManager Instance { get; private set; }
18
20 public static void CheckInstance()
21 {
22 if (Instance == null) Instance = new GameObject("PasteManager").AddComponent<PasteManager>();
23 }
24
25#if UNITY_WEBGL && !UNITY_EDITOR
26 private void Start()
27 {
28 PasteManagerSetup();
29 }
30#endif
31
34 public void Paste(string value)
35 {
36 var currentCurrentSelectedGameObject = EventSystem.current.currentSelectedGameObject;
37 if (currentCurrentSelectedGameObject != null)
38 {
39 var inputField = currentCurrentSelectedGameObject.GetComponentInChildren<InputField>();
40 if (inputField != null)
41 {
42 var newText =
43 $"{inputField.text.Substring(0, inputField.selectionAnchorPosition)}{value}{inputField.text.Substring(inputField.selectionFocusPosition)}";
44 inputField.text = newText;
45 }
46 }
47 }
48 }
49}
Represents a Class used to add paste capabilities to WebGL projects.
Definition: PasteManager.cs:10
static PasteManager Instance
The Paste Manager Singleton instance.
Definition: PasteManager.cs:17
static void CheckInstance()
Checks if the Singleton instance exists.
Definition: PasteManager.cs:20
void Paste(string value)
Called when the user pastes the given value in the Web-Browser.
Definition: PasteManager.cs:34