| | 1 | | using System; |
| | 2 | | using UnityEngine; |
| | 3 | | using UnityEngine.EventSystems; |
| | 4 | | using UnityEngine.UI; |
| | 5 | |
|
| | 6 | | public interface IPublishBtnView |
| | 7 | | { |
| | 8 | | event Action OnHideTooltip; |
| | 9 | | event Action OnPublishButtonClick; |
| | 10 | | event Action<BaseEventData, string> OnShowTooltip; |
| | 11 | |
|
| | 12 | | void OnPointerClick(); |
| | 13 | | void OnPointerEnter(PointerEventData eventData); |
| | 14 | | void OnPointerExit(); |
| | 15 | | void SetInteractable(bool isInteractable); |
| | 16 | | } |
| | 17 | |
|
| | 18 | | public class PublishBtnView : MonoBehaviour, IPublishBtnView |
| | 19 | | { |
| | 20 | | public event Action OnPublishButtonClick; |
| | 21 | | public event Action<BaseEventData, string> OnShowTooltip; |
| | 22 | | public event Action OnHideTooltip; |
| | 23 | |
|
| | 24 | | [SerializeField] internal Button mainButton; |
| 26 | 25 | | [SerializeField] internal string tooltipText = "Publish Scene"; |
| | 26 | | [SerializeField] internal EventTrigger publishButtonEventTrigger; |
| | 27 | |
|
| | 28 | | private const string VIEW_PATH = "GodMode/PublishBtnView"; |
| | 29 | |
|
| | 30 | | internal static PublishBtnView Create() |
| | 31 | | { |
| 5 | 32 | | var view = Instantiate(Resources.Load<GameObject>(VIEW_PATH)).GetComponent<PublishBtnView>(); |
| 5 | 33 | | view.gameObject.name = "_PublishBtnView"; |
| | 34 | |
|
| 5 | 35 | | return view; |
| | 36 | | } |
| | 37 | |
|
| | 38 | | private void Awake() |
| | 39 | | { |
| 24 | 40 | | mainButton.onClick.AddListener(OnPointerClick); |
| 24 | 41 | | BIWUtils.ConfigureEventTrigger(publishButtonEventTrigger, EventTriggerType.PointerEnter, (eventData) => OnPointe |
| 24 | 42 | | BIWUtils.ConfigureEventTrigger(publishButtonEventTrigger, EventTriggerType.PointerExit, (eventData) => OnPointer |
| 24 | 43 | | } |
| | 44 | |
|
| | 45 | | private void OnDestroy() |
| | 46 | | { |
| 24 | 47 | | mainButton.onClick.RemoveListener(OnPointerClick); |
| 24 | 48 | | BIWUtils.RemoveEventTrigger(publishButtonEventTrigger, EventTriggerType.PointerEnter); |
| 24 | 49 | | BIWUtils.RemoveEventTrigger(publishButtonEventTrigger, EventTriggerType.PointerExit); |
| 24 | 50 | | } |
| | 51 | |
|
| 2 | 52 | | public void OnPointerClick() { OnPublishButtonClick?.Invoke(); } |
| | 53 | |
|
| 2 | 54 | | public void OnPointerEnter(PointerEventData eventData) { OnShowTooltip?.Invoke(eventData, tooltipText); } |
| | 55 | |
|
| 2 | 56 | | public void OnPointerExit() { OnHideTooltip?.Invoke(); } |
| | 57 | |
|
| 4 | 58 | | public void SetInteractable(bool isInteractable) { mainButton.interactable = isInteractable; } |
| | 59 | | } |