neuecc / UniRx

Reactive Extensions for Unity
MIT License
7.01k stars 895 forks source link

OnPointerBeginDragHandler() should automatically add ObservableDragTrigger automatically otherwise events will not work #473

Open doctorpangloss opened 3 years ago

doctorpangloss commented 3 years ago

From EventSystem docs:

 /// <summary>
    /// Interface to implement if you wish to receive OnBeginDrag callbacks.
    /// Note: You need to implement IDragHandler in addition to IBeginDragHandler.
    /// </summary>
    /// <remarks>
    /// Criteria for this event is implementation dependent. For example see StandAloneInputModule.
    /// </remarks>
    public interface IBeginDragHandler : IEventSystemHandler
    {
        /// <summary>
        /// Called by a BaseInputModule before a drag is started.
        /// </summary>
        void OnBeginDrag(PointerEventData eventData);
    }

You need to implement IDragHandler in addition to IBeginDragHandler.

This means OnBeginDragAsObservable should also just add the ObservableDragTrigger.

        public static IObservable<PointerEventData> OnBeginDragAsObservable(this Component component)
        {
            if (component == null || component.gameObject == null) return Observable.Empty<PointerEventData>();
            // Requires drag handler
            GetOrAddComponent<ObservableDragTrigger>(component.gameObject);
            return GetOrAddComponent<ObservableBeginDragTrigger>(component.gameObject).OnBeginDragAsObservable();
        }
doctorpangloss commented 2 years ago

this is still burning people every day