123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359 |
- // for uGUI(from 4.6)
- #if !(UNITY_4_0 || UNITY_4_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_4 || UNITY_4_5)
- using System; // require keep for Windows Universal App
- using UnityEngine;
- using UnityEngine.EventSystems;
- namespace UniRx.Triggers
- {
- [DisallowMultipleComponent]
- public class ObservableEventTrigger : ObservableTriggerBase, IEventSystemHandler, IPointerEnterHandler, IPointerExitHandler, IPointerDownHandler, IPointerUpHandler, IPointerClickHandler, IBeginDragHandler, IInitializePotentialDragHandler, IDragHandler, IEndDragHandler, IDropHandler, IScrollHandler, IUpdateSelectedHandler, ISelectHandler, IDeselectHandler, IMoveHandler, ISubmitHandler, ICancelHandler
- {
- #region IDeselectHandler
- Subject<BaseEventData> onDeselect;
- void IDeselectHandler.OnDeselect(BaseEventData eventData)
- {
- if (onDeselect != null) onDeselect.OnNext(eventData);
- }
- public IObservable<BaseEventData> OnDeselectAsObservable()
- {
- return onDeselect ?? (onDeselect = new Subject<BaseEventData>());
- }
- #endregion
- #region IMoveHandler
- Subject<AxisEventData> onMove;
- void IMoveHandler.OnMove(AxisEventData eventData)
- {
- if (onMove != null) onMove.OnNext(eventData);
- }
- public IObservable<AxisEventData> OnMoveAsObservable()
- {
- return onMove ?? (onMove = new Subject<AxisEventData>());
- }
- #endregion
- #region IPointerDownHandler
- Subject<PointerEventData> onPointerDown;
- void IPointerDownHandler.OnPointerDown(PointerEventData eventData)
- {
- if (onPointerDown != null) onPointerDown.OnNext(eventData);
- }
- public IObservable<PointerEventData> OnPointerDownAsObservable()
- {
- return onPointerDown ?? (onPointerDown = new Subject<PointerEventData>());
- }
- #endregion
- #region IPointerEnterHandler
- Subject<PointerEventData> onPointerEnter;
- void IPointerEnterHandler.OnPointerEnter(PointerEventData eventData)
- {
- if (onPointerEnter != null) onPointerEnter.OnNext(eventData);
- }
- public IObservable<PointerEventData> OnPointerEnterAsObservable()
- {
- return onPointerEnter ?? (onPointerEnter = new Subject<PointerEventData>());
- }
- #endregion
- #region IPointerExitHandler
- Subject<PointerEventData> onPointerExit;
- void IPointerExitHandler.OnPointerExit(PointerEventData eventData)
- {
- if (onPointerExit != null) onPointerExit.OnNext(eventData);
- }
- public IObservable<PointerEventData> OnPointerExitAsObservable()
- {
- return onPointerExit ?? (onPointerExit = new Subject<PointerEventData>());
- }
- #endregion
- #region IPointerUpHandler
- Subject<PointerEventData> onPointerUp;
- void IPointerUpHandler.OnPointerUp(PointerEventData eventData)
- {
- if (onPointerUp != null) onPointerUp.OnNext(eventData);
- }
- public IObservable<PointerEventData> OnPointerUpAsObservable()
- {
- return onPointerUp ?? (onPointerUp = new Subject<PointerEventData>());
- }
- #endregion
- #region ISelectHandler
- Subject<BaseEventData> onSelect;
- void ISelectHandler.OnSelect(BaseEventData eventData)
- {
- if (onSelect != null) onSelect.OnNext(eventData);
- }
- public IObservable<BaseEventData> OnSelectAsObservable()
- {
- return onSelect ?? (onSelect = new Subject<BaseEventData>());
- }
- #endregion
- #region IPointerClickHandler
- Subject<PointerEventData> onPointerClick;
- void IPointerClickHandler.OnPointerClick(PointerEventData eventData)
- {
- if (onPointerClick != null) onPointerClick.OnNext(eventData);
- }
- public IObservable<PointerEventData> OnPointerClickAsObservable()
- {
- return onPointerClick ?? (onPointerClick = new Subject<PointerEventData>());
- }
- #endregion
- #region ISubmitHandler
- Subject<BaseEventData> onSubmit;
- void ISubmitHandler.OnSubmit(BaseEventData eventData)
- {
- if (onSubmit != null) onSubmit.OnNext(eventData);
- }
- public IObservable<BaseEventData> OnSubmitAsObservable()
- {
- return onSubmit ?? (onSubmit = new Subject<BaseEventData>());
- }
- #endregion
- #region IDragHandler
- Subject<PointerEventData> onDrag;
- void IDragHandler.OnDrag(PointerEventData eventData)
- {
- if (onDrag != null) onDrag.OnNext(eventData);
- }
- public IObservable<PointerEventData> OnDragAsObservable()
- {
- return onDrag ?? (onDrag = new Subject<PointerEventData>());
- }
- #endregion
- #region IBeginDragHandler
- Subject<PointerEventData> onBeginDrag;
- void IBeginDragHandler.OnBeginDrag(PointerEventData eventData)
- {
- if (onBeginDrag != null) onBeginDrag.OnNext(eventData);
- }
- public IObservable<PointerEventData> OnBeginDragAsObservable()
- {
- return onBeginDrag ?? (onBeginDrag = new Subject<PointerEventData>());
- }
- #endregion
- #region IEndDragHandler
- Subject<PointerEventData> onEndDrag;
- void IEndDragHandler.OnEndDrag(PointerEventData eventData)
- {
- if (onEndDrag != null) onEndDrag.OnNext(eventData);
- }
- public IObservable<PointerEventData> OnEndDragAsObservable()
- {
- return onEndDrag ?? (onEndDrag = new Subject<PointerEventData>());
- }
- #endregion
- #region IDropHandler
- Subject<PointerEventData> onDrop;
- void IDropHandler.OnDrop(PointerEventData eventData)
- {
- if (onDrop != null) onDrop.OnNext(eventData);
- }
- public IObservable<PointerEventData> OnDropAsObservable()
- {
- return onDrop ?? (onDrop = new Subject<PointerEventData>());
- }
- #endregion
- #region IUpdateSelectedHandler
- Subject<BaseEventData> onUpdateSelected;
- void IUpdateSelectedHandler.OnUpdateSelected(BaseEventData eventData)
- {
- if (onUpdateSelected != null) onUpdateSelected.OnNext(eventData);
- }
- public IObservable<BaseEventData> OnUpdateSelectedAsObservable()
- {
- return onUpdateSelected ?? (onUpdateSelected = new Subject<BaseEventData>());
- }
- #endregion
- #region IInitializePotentialDragHandler
- Subject<PointerEventData> onInitializePotentialDrag;
- void IInitializePotentialDragHandler.OnInitializePotentialDrag(PointerEventData eventData)
- {
- if (onInitializePotentialDrag != null) onInitializePotentialDrag.OnNext(eventData);
- }
- public IObservable<PointerEventData> OnInitializePotentialDragAsObservable()
- {
- return onInitializePotentialDrag ?? (onInitializePotentialDrag = new Subject<PointerEventData>());
- }
- #endregion
- #region ICancelHandler
- Subject<BaseEventData> onCancel;
- void ICancelHandler.OnCancel(BaseEventData eventData)
- {
- if (onCancel != null) onCancel.OnNext(eventData);
- }
- public IObservable<BaseEventData> OnCancelAsObservable()
- {
- return onCancel ?? (onCancel = new Subject<BaseEventData>());
- }
- #endregion
- #region IScrollHandler
- Subject<PointerEventData> onScroll;
- void IScrollHandler.OnScroll(PointerEventData eventData)
- {
- if (onScroll != null) onScroll.OnNext(eventData);
- }
- public IObservable<PointerEventData> OnScrollAsObservable()
- {
- return onScroll ?? (onScroll = new Subject<PointerEventData>());
- }
- #endregion
- protected override void RaiseOnCompletedOnDestroy()
- {
- if (onDeselect != null)
- {
- onDeselect.OnCompleted();
- }
- if (onMove != null)
- {
- onMove.OnCompleted();
- }
- if (onPointerDown != null)
- {
- onPointerDown.OnCompleted();
- }
- if (onPointerEnter != null)
- {
- onPointerEnter.OnCompleted();
- }
- if (onPointerExit != null)
- {
- onPointerExit.OnCompleted();
- }
- if (onPointerUp != null)
- {
- onPointerUp.OnCompleted();
- }
- if (onSelect != null)
- {
- onSelect.OnCompleted();
- }
- if (onPointerClick != null)
- {
- onPointerClick.OnCompleted();
- }
- if (onSubmit != null)
- {
- onSubmit.OnCompleted();
- }
- if (onDrag != null)
- {
- onDrag.OnCompleted();
- }
- if (onBeginDrag != null)
- {
- onBeginDrag.OnCompleted();
- }
- if (onEndDrag != null)
- {
- onEndDrag.OnCompleted();
- }
- if (onDrop != null)
- {
- onDrop.OnCompleted();
- }
- if (onUpdateSelected != null)
- {
- onUpdateSelected.OnCompleted();
- }
- if (onInitializePotentialDrag != null)
- {
- onInitializePotentialDrag.OnCompleted();
- }
- if (onCancel != null)
- {
- onCancel.OnCompleted();
- }
- if (onScroll != null)
- {
- onScroll.OnCompleted();
- }
- }
- }
- }
- #endif
|