| | 1 | | using System; |
| | 2 | | using DCL; |
| | 3 | | using DCL.NotificationModel; |
| | 4 | | using TMPro; |
| | 5 | | using UnityEngine; |
| | 6 | | using UnityEngine.UI; |
| | 7 | | using Environment = DCL.Environment; |
| | 8 | | using Type = DCL.NotificationModel.Type; |
| | 9 | |
|
| | 10 | | public class PreviewMenuPositionView : MonoBehaviour, IDisposable |
| | 11 | | { |
| | 12 | | private const string NOTIFICATION_GROUP = "PositionCopiedToClipboard"; |
| | 13 | | private const string NOTIFICATION_MESSAGE = "Position copied to clipboard ({0})"; |
| | 14 | |
|
| | 15 | | [SerializeField] internal TMP_InputField xValueInputField; |
| | 16 | | [SerializeField] internal TMP_InputField yValueInputField; |
| | 17 | | [SerializeField] internal TMP_InputField zValueInputField; |
| | 18 | | [SerializeField] internal Button buttonReference; |
| | 19 | |
|
| | 20 | | private bool isDestroyed; |
| | 21 | |
|
| 1 | 22 | | private static readonly Model copyPositionToast = new Model() |
| | 23 | | { |
| | 24 | | type = Type.WARNING, |
| | 25 | | groupID = NOTIFICATION_GROUP, |
| | 26 | | message = NOTIFICATION_MESSAGE, |
| | 27 | | timer = 1.5f |
| | 28 | | }; |
| | 29 | |
|
| | 30 | | public void Dispose() |
| | 31 | | { |
| 5 | 32 | | if (!isDestroyed) |
| | 33 | | { |
| 5 | 34 | | Destroy(gameObject); |
| | 35 | | } |
| 5 | 36 | | } |
| | 37 | |
|
| | 38 | | private void OnDestroy() |
| | 39 | | { |
| 7 | 40 | | isDestroyed = true; |
| 7 | 41 | | } |
| | 42 | |
|
| | 43 | | private void Awake() |
| | 44 | | { |
| 7 | 45 | | buttonReference.onClick.AddListener(() => |
| | 46 | | { |
| 1 | 47 | | var positionString = $"{xValueInputField.text},{yValueInputField.text},{zValueInputField.text}"; |
| 1 | 48 | | Environment.i.platform.clipboard |
| | 49 | | .WriteText(positionString); |
| | 50 | |
|
| 1 | 51 | | var notificationController = NotificationsController.i; |
| 1 | 52 | | if (notificationController != null) |
| | 53 | | { |
| 0 | 54 | | copyPositionToast.message = string.Format(NOTIFICATION_MESSAGE, positionString); |
| 0 | 55 | | notificationController.DismissAllNotifications(copyPositionToast.groupID); |
| 0 | 56 | | notificationController.ShowNotification(copyPositionToast); |
| | 57 | | } |
| 1 | 58 | | }); |
| 7 | 59 | | } |
| | 60 | |
|
| | 61 | | internal static string FormatFloatValue(float value) |
| | 62 | | { |
| 12 | 63 | | return $"{value:0.00}"; |
| | 64 | | } |
| | 65 | |
|
| | 66 | | internal void LateUpdate() |
| | 67 | | { |
| 2 | 68 | | Vector3 position = WorldStateUtils.ConvertUnityToScenePosition(CommonScriptableObjects.playerUnityPosition.Get() |
| 2 | 69 | | xValueInputField.text = FormatFloatValue(position.x); |
| 2 | 70 | | yValueInputField.text = FormatFloatValue(position.y); |
| 2 | 71 | | zValueInputField.text = FormatFloatValue(position.z); |
| 2 | 72 | | } |
| | 73 | | } |