| | 1 | | using System; |
| | 2 | | using DCL.NotificationModel; |
| | 3 | | using UnityEngine; |
| | 4 | | using UnityEngine.UI; |
| | 5 | | using Environment = DCL.Environment; |
| | 6 | | using Type = DCL.NotificationModel.Type; |
| | 7 | |
|
| | 8 | | [RequireComponent(typeof(Button))] |
| | 9 | | public class CopyToClipboardButton : MonoBehaviour |
| | 10 | | { |
| | 11 | |
|
| | 12 | | [SerializeField] private string groupID; |
| | 13 | | [SerializeField] private string message; |
| 0 | 14 | | [SerializeField] private float timer = 1.5f; |
| | 15 | |
|
| | 16 | | private Func<string> funcToGetContent; |
| | 17 | | private Model copyToast; |
| | 18 | | private Button button; |
| | 19 | |
|
| | 20 | | private void Start() |
| | 21 | | { |
| 0 | 22 | | copyToast = new Model() |
| | 23 | | { |
| | 24 | | type = Type.WARNING_NO_ICON, |
| | 25 | | groupID = groupID, |
| | 26 | | message = message, |
| | 27 | | timer = timer |
| | 28 | | }; |
| 0 | 29 | | button = GetComponent<Button>(); |
| 0 | 30 | | button.onClick.AddListener(CopySceneNameToClipboard); |
| 0 | 31 | | } |
| | 32 | | public void SetFuncToCopy(Func<string> newFunc) |
| | 33 | | { |
| 0 | 34 | | funcToGetContent = null; |
| 0 | 35 | | funcToGetContent += newFunc; |
| 0 | 36 | | } |
| | 37 | |
|
| | 38 | | private void CopySceneNameToClipboard() |
| | 39 | | { |
| 0 | 40 | | string activeSceneName = funcToGetContent?.Invoke(); |
| 0 | 41 | | Environment.i.platform.clipboard.WriteText(activeSceneName); |
| | 42 | |
|
| 0 | 43 | | var notificationController = NotificationsController.i; |
| 0 | 44 | | if (notificationController != null) |
| | 45 | | { |
| 0 | 46 | | notificationController.DismissAllNotifications(copyToast.groupID); |
| 0 | 47 | | notificationController.ShowNotification(copyToast); |
| | 48 | | } |
| 0 | 49 | | } |
| | 50 | |
|
| | 51 | | private void OnDestroy() |
| | 52 | | { |
| 0 | 53 | | button.onClick.RemoveAllListeners(); |
| 0 | 54 | | } |
| | 55 | |
|
| | 56 | | } |