| | 1 | | using System; |
| | 2 | | using System.Threading.Tasks; |
| | 3 | | using UnityEngine; |
| | 4 | |
|
| | 5 | | internal class ClipboardHandler_Mock : IClipboardHandler |
| | 6 | | { |
| | 7 | | private Action<string, bool> OnRead; |
| 0 | 8 | | public string textInClipboard { private set; get; } |
| | 9 | |
|
| | 10 | | private float delayForReadRequest = 0; |
| 0 | 11 | | private string errorInReadRequest = ""; |
| 2 | 12 | | void IClipboardHandler.Initialize(Action<string, bool> onRead) { OnRead = onRead; } |
| | 13 | |
|
| 0 | 14 | | void IClipboardHandler.RequestWriteText(string text) { textInClipboard = text; } |
| | 15 | |
|
| | 16 | | void IClipboardHandler.RequestGetText() |
| | 17 | | { |
| 2 | 18 | | bool isError = !string.IsNullOrEmpty(errorInReadRequest); |
| | 19 | |
|
| 2 | 20 | | if (delayForReadRequest > 0) |
| | 21 | | { |
| 1 | 22 | | Task.Delay(Mathf.FloorToInt(delayForReadRequest * 1000)) |
| | 23 | | .ContinueWith((task) => |
| | 24 | | { |
| 1 | 25 | | OnRead?.Invoke(isError ? errorInReadRequest : textInClipboard, isError); |
| 1 | 26 | | }); |
| 1 | 27 | | } |
| | 28 | | else |
| | 29 | | { |
| 1 | 30 | | OnRead?.Invoke(isError ? errorInReadRequest : textInClipboard, isError); |
| | 31 | | } |
| 1 | 32 | | } |
| | 33 | |
|
| | 34 | | public void MockReadTextRequestResult(float delay, string resultValue, bool error) |
| | 35 | | { |
| 2 | 36 | | textInClipboard = resultValue; |
| 2 | 37 | | delayForReadRequest = delay; |
| 2 | 38 | | errorInReadRequest = error ? resultValue : string.Empty; |
| 2 | 39 | | } |
| | 40 | | } |