| | 1 | | using System; |
| | 2 | | using UnityEngine; |
| | 3 | | using UnityEngine.UI; |
| | 4 | |
|
| | 5 | | public class ExternalUrlPromptView : MonoBehaviour |
| | 6 | | { |
| | 7 | | [SerializeField] internal GameObject content; |
| | 8 | | [SerializeField] internal Button closeButton; |
| | 9 | | [SerializeField] internal Button continueButton; |
| | 10 | | [SerializeField] internal Button cancelButton; |
| | 11 | | [SerializeField] internal TMPro.TextMeshProUGUI domainText; |
| | 12 | | [SerializeField] internal TMPro.TextMeshProUGUI urlText; |
| | 13 | | [SerializeField] internal Toggle trustToggle; |
| | 14 | | [SerializeField] internal ShowHideAnimator showHideAnimator; |
| | 15 | |
|
| | 16 | | internal enum ResultType { CANCELED, APPROVED, APPROVED_TRUSTED } |
| | 17 | |
|
| | 18 | | Action<ResultType> resultCallback = null; |
| | 19 | |
|
| | 20 | | void Awake() |
| | 21 | | { |
| 5 | 22 | | closeButton.onClick.AddListener(Dismiss); |
| 5 | 23 | | cancelButton.onClick.AddListener(Dismiss); |
| 5 | 24 | | continueButton.onClick.AddListener(Approve); |
| 5 | 25 | | } |
| | 26 | |
|
| | 27 | | internal void RequestOpenUrl(Uri uri, Action<ResultType> result) |
| | 28 | | { |
| 5 | 29 | | resultCallback = result; |
| 5 | 30 | | domainText.text = uri.Host; |
| 5 | 31 | | urlText.text = uri.OriginalString; |
| 5 | 32 | | trustToggle.isOn = false; |
| 5 | 33 | | } |
| | 34 | |
|
| 4 | 35 | | private void Dismiss() { resultCallback?.Invoke(ResultType.CANCELED); } |
| | 36 | |
|
| 4 | 37 | | private void Approve() { resultCallback?.Invoke(trustToggle.isOn ? ResultType.APPROVED_TRUSTED : ResultType.APPROVED |
| | 38 | | } |