| | 1 | | using TMPro; |
| | 2 | | using UnityEngine; |
| | 3 | | using UnityEngine.UI; |
| | 4 | | using UnityEngine.EventSystems; |
| | 5 | |
|
| | 6 | | namespace DCL.Components |
| | 7 | | { |
| | 8 | | public class UIInputTextRefContainer : UIReferencesContainer |
| | 9 | | { |
| | 10 | | [Header("Input Text Fields")] |
| | 11 | | public RawImage bgImage; |
| | 12 | |
|
| | 13 | | public TMP_Text text; |
| | 14 | | public TMP_InputField inputField; |
| | 15 | |
|
| | 16 | | [System.NonSerialized] |
| | 17 | | public MouseCatcher mouseCatcher; |
| | 18 | |
|
| | 19 | | [System.NonSerialized] |
| | 20 | | public int inputDetectionPausedFrames = 0; |
| | 21 | |
|
| | 22 | | void Start() |
| | 23 | | { |
| 10 | 24 | | mouseCatcher = FindObjectOfType<MouseCatcher>(); |
| | 25 | |
|
| 10 | 26 | | inputField.onSelect.AddListener(OnSelect); |
| 10 | 27 | | } |
| | 28 | |
|
| | 29 | | void OnSelect(string str) |
| | 30 | | { |
| 1 | 31 | | PointerEventData pointerEventData = new PointerEventData(EventSystem.current); |
| 1 | 32 | | RaycastResult raycastResult = new RaycastResult(); |
| 1 | 33 | | raycastResult.gameObject = text.gameObject; |
| 1 | 34 | | pointerEventData.pointerPressRaycast = raycastResult; |
| | 35 | |
|
| 1 | 36 | | OnPointerDown(pointerEventData); |
| 1 | 37 | | } |
| | 38 | |
|
| | 39 | | void Update() |
| | 40 | | { |
| 63 | 41 | | if (inputDetectionPausedFrames > 0) |
| | 42 | | { |
| 0 | 43 | | inputDetectionPausedFrames--; |
| | 44 | |
|
| 0 | 45 | | return; |
| | 46 | | } |
| | 47 | |
|
| 63 | 48 | | if (Input.GetKeyDown(KeyCode.Return)) |
| | 49 | | { |
| 0 | 50 | | if (owner != null && owner.scene != null && owner.scene.isPersistent && !inputField.isFocused) |
| | 51 | | { |
| 0 | 52 | | inputField.Select(); |
| 0 | 53 | | mouseCatcher.UnlockCursor(); |
| | 54 | | } |
| | 55 | | } |
| 63 | 56 | | } |
| | 57 | | } |
| | 58 | | } |