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