Skip to content

Instantly share code, notes, and snippets.

@divide-by-zero
Created July 19, 2015 14:34
Show Gist options
  • Save divide-by-zero/b1509ef5f4b9a2ddea88 to your computer and use it in GitHub Desktop.
Save divide-by-zero/b1509ef5f4b9a2ddea88 to your computer and use it in GitHub Desktop.
uGUIが押されている間はtrue,離されている間はfalseをStreamに流し続けるTrigger
using UniRx;
using UniRx.Triggers;
using UnityEngine.EventSystems;
public class ObservableButtonDownTrigger : ObservableTriggerBase, IPointerDownHandler, IPointerUpHandler{
private bool isPointerDown;
private Subject<bool> onButtonDown;
public IObservable<bool> OnButtonDown
{
get { return onButtonDown ?? (onButtonDown = new Subject<bool>()); }
}
private void Update() {
if (onButtonDown != null) onButtonDown.OnNext(isPointerDown);
}
public void OnPointerDown(PointerEventData eventData){
isPointerDown = true;
}
public void OnPointerUp(PointerEventData eventData){
isPointerDown = false;
}
protected override void RaiseOnCompletedOnDestroy(){
if (onButtonDown != null){
onButtonDown.OnCompleted();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment