#if !(UNITY_IPHONE || UNITY_ANDROID || UNITY_METRO) using System; // require keep for Windows Universal App using UnityEngine; namespace UniRx.Triggers { [DisallowMultipleComponent] public class ObservableMouseTrigger : ObservableTriggerBase { Subject onMouseDown; /// OnMouseDown is called when the user has pressed the mouse button while over the GUIElement or Collider. void OnMouseDown() { if (onMouseDown != null) onMouseDown.OnNext(Unit.Default); } /// OnMouseDown is called when the user has pressed the mouse button while over the GUIElement or Collider. public IObservable OnMouseDownAsObservable() { return onMouseDown ?? (onMouseDown = new Subject()); } Subject onMouseDrag; /// OnMouseDrag is called when the user has clicked on a GUIElement or Collider and is still holding down the mouse. void OnMouseDrag() { if (onMouseDrag != null) onMouseDrag.OnNext(Unit.Default); } /// OnMouseDrag is called when the user has clicked on a GUIElement or Collider and is still holding down the mouse. public IObservable OnMouseDragAsObservable() { return onMouseDrag ?? (onMouseDrag = new Subject()); } Subject onMouseEnter; /// OnMouseEnter is called when the mouse entered the GUIElement or Collider. void OnMouseEnter() { if (onMouseEnter != null) onMouseEnter.OnNext(Unit.Default); } /// OnMouseEnter is called when the mouse entered the GUIElement or Collider. public IObservable OnMouseEnterAsObservable() { return onMouseEnter ?? (onMouseEnter = new Subject()); } Subject onMouseExit; /// OnMouseExit is called when the mouse is not any longer over the GUIElement or Collider. void OnMouseExit() { if (onMouseExit != null) onMouseExit.OnNext(Unit.Default); } /// OnMouseExit is called when the mouse is not any longer over the GUIElement or Collider. public IObservable OnMouseExitAsObservable() { return onMouseExit ?? (onMouseExit = new Subject()); } Subject onMouseOver; /// OnMouseOver is called every frame while the mouse is over the GUIElement or Collider. void OnMouseOver() { if (onMouseOver != null) onMouseOver.OnNext(Unit.Default); } /// OnMouseOver is called every frame while the mouse is over the GUIElement or Collider. public IObservable OnMouseOverAsObservable() { return onMouseOver ?? (onMouseOver = new Subject()); } Subject onMouseUp; /// OnMouseUp is called when the user has released the mouse button. void OnMouseUp() { if (onMouseUp != null) onMouseUp.OnNext(Unit.Default); } /// OnMouseUp is called when the user has released the mouse button. public IObservable OnMouseUpAsObservable() { return onMouseUp ?? (onMouseUp = new Subject()); } Subject onMouseUpAsButton; /// OnMouseUpAsButton is only called when the mouse is released over the same GUIElement or Collider as it was pressed. void OnMouseUpAsButton() { if (onMouseUpAsButton != null) onMouseUpAsButton.OnNext(Unit.Default); } /// OnMouseUpAsButton is only called when the mouse is released over the same GUIElement or Collider as it was pressed. public IObservable OnMouseUpAsButtonAsObservable() { return onMouseUpAsButton ?? (onMouseUpAsButton = new Subject()); } protected override void RaiseOnCompletedOnDestroy() { if (onMouseDown != null) { onMouseDown.OnCompleted(); } if (onMouseDrag != null) { onMouseDrag.OnCompleted(); } if (onMouseEnter != null) { onMouseEnter.OnCompleted(); } if (onMouseExit != null) { onMouseExit.OnCompleted(); } if (onMouseOver != null) { onMouseOver.OnCompleted(); } if (onMouseUp != null) { onMouseUp.OnCompleted(); } if (onMouseUpAsButton != null) { onMouseUpAsButton.OnCompleted(); } } } } #endif