using System; // require keep for Windows Universal App
using UnityEngine;
#if !(UNITY_4_0 || UNITY_4_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_4 || UNITY_4_5)
using UnityEngine.EventSystems;
#endif
namespace UniRx.Triggers
{
// for Component
public static partial class ObservableTriggerExtensions
{
#region ObservableAnimatorTrigger
/// Callback for setting up animation IK (inverse kinematics).
public static IObservable OnAnimatorIKAsObservable(this Component component)
{
if (component == null || component.gameObject == null) return Observable.Empty();
return GetOrAddComponent(component.gameObject).OnAnimatorIKAsObservable();
}
/// Callback for processing animation movements for modifying root motion.
public static IObservable OnAnimatorMoveAsObservable(this Component component)
{
if (component == null || component.gameObject == null) return Observable.Empty();
return GetOrAddComponent(component.gameObject).OnAnimatorMoveAsObservable();
}
#endregion
#region ObservableCollision2DTrigger
/// Sent when an incoming collider makes contact with this object's collider (2D physics only).
public static IObservable OnCollisionEnter2DAsObservable(this Component component)
{
if (component == null || component.gameObject == null) return Observable.Empty();
return GetOrAddComponent(component.gameObject).OnCollisionEnter2DAsObservable();
}
/// Sent when a collider on another object stops touching this object's collider (2D physics only).
public static IObservable OnCollisionExit2DAsObservable(this Component component)
{
if (component == null || component.gameObject == null) return Observable.Empty();
return GetOrAddComponent(component.gameObject).OnCollisionExit2DAsObservable();
}
/// Sent each frame where a collider on another object is touching this object's collider (2D physics only).
public static IObservable OnCollisionStay2DAsObservable(this Component component)
{
if (component == null || component.gameObject == null) return Observable.Empty();
return GetOrAddComponent(component.gameObject).OnCollisionStay2DAsObservable();
}
#endregion
#region ObservableCollisionTrigger
/// OnCollisionEnter is called when this collider/rigidbody has begun touching another rigidbody/collider.
public static IObservable OnCollisionEnterAsObservable(this Component component)
{
if (component == null || component.gameObject == null) return Observable.Empty();
return GetOrAddComponent(component.gameObject).OnCollisionEnterAsObservable();
}
/// OnCollisionExit is called when this collider/rigidbody has stopped touching another rigidbody/collider.
public static IObservable OnCollisionExitAsObservable(this Component component)
{
if (component == null || component.gameObject == null) return Observable.Empty();
return GetOrAddComponent(component.gameObject).OnCollisionExitAsObservable();
}
/// OnCollisionStay is called once per frame for every collider/rigidbody that is touching rigidbody/collider.
public static IObservable OnCollisionStayAsObservable(this Component component)
{
if (component == null || component.gameObject == null) return Observable.Empty();
return GetOrAddComponent(component.gameObject).OnCollisionStayAsObservable();
}
#endregion
#region ObservableDestroyTrigger
/// This function is called when the MonoBehaviour will be destroyed.
public static IObservable OnDestroyAsObservable(this Component component)
{
if (component == null || component.gameObject == null) return Observable.Return(Unit.Default); // send destroy message
return GetOrAddComponent(component.gameObject).OnDestroyAsObservable();
}
#endregion
#region ObservableEnableTrigger
/// This function is called when the object becomes enabled and active.
public static IObservable OnEnableAsObservable(this Component component)
{
if (component == null || component.gameObject == null) return Observable.Empty();
return GetOrAddComponent(component.gameObject).OnEnableAsObservable();
}
/// This function is called when the behaviour becomes disabled () or inactive.
public static IObservable OnDisableAsObservable(this Component component)
{
if (component == null || component.gameObject == null) return Observable.Empty();
return GetOrAddComponent(component.gameObject).OnDisableAsObservable();
}
#endregion
#region ObservableFixedUpdateTrigger
/// This function is called every fixed framerate frame, if the MonoBehaviour is enabled.
public static IObservable FixedUpdateAsObservable(this Component component)
{
if (component == null || component.gameObject == null) return Observable.Empty();
return GetOrAddComponent(component.gameObject).FixedUpdateAsObservable();
}
#endregion
#region ObservableLateUpdateTrigger
/// LateUpdate is called every frame, if the Behaviour is enabled.
public static IObservable LateUpdateAsObservable(this Component component)
{
if (component == null || component.gameObject == null) return Observable.Empty();
return GetOrAddComponent(component.gameObject).LateUpdateAsObservable();
}
#endregion
#if !(UNITY_IPHONE || UNITY_ANDROID || UNITY_METRO)
#region ObservableMouseTrigger
/// OnMouseDown is called when the user has pressed the mouse button while over the GUIElement or Collider.
public static IObservable OnMouseDownAsObservable(this Component component)
{
if (component == null || component.gameObject == null) return Observable.Empty();
return GetOrAddComponent(component.gameObject).OnMouseDownAsObservable();
}
/// OnMouseDrag is called when the user has clicked on a GUIElement or Collider and is still holding down the mouse.
public static IObservable OnMouseDragAsObservable(this Component component)
{
if (component == null || component.gameObject == null) return Observable.Empty();
return GetOrAddComponent(component.gameObject).OnMouseDragAsObservable();
}
/// OnMouseEnter is called when the mouse entered the GUIElement or Collider.
public static IObservable OnMouseEnterAsObservable(this Component component)
{
if (component == null || component.gameObject == null) return Observable.Empty();
return GetOrAddComponent(component.gameObject).OnMouseEnterAsObservable();
}
/// OnMouseExit is called when the mouse is not any longer over the GUIElement or Collider.
public static IObservable OnMouseExitAsObservable(this Component component)
{
if (component == null || component.gameObject == null) return Observable.Empty();
return GetOrAddComponent(component.gameObject).OnMouseExitAsObservable();
}
/// OnMouseOver is called every frame while the mouse is over the GUIElement or Collider.
public static IObservable OnMouseOverAsObservable(this Component component)
{
if (component == null || component.gameObject == null) return Observable.Empty();
return GetOrAddComponent(component.gameObject).OnMouseOverAsObservable();
}
/// OnMouseUp is called when the user has released the mouse button.
public static IObservable OnMouseUpAsObservable(this Component component)
{
if (component == null || component.gameObject == null) return Observable.Empty();
return GetOrAddComponent(component.gameObject).OnMouseUpAsObservable();
}
/// OnMouseUpAsButton is only called when the mouse is released over the same GUIElement or Collider as it was pressed.
public static IObservable OnMouseUpAsButtonAsObservable(this Component component)
{
if (component == null || component.gameObject == null) return Observable.Empty();
return GetOrAddComponent(component.gameObject).OnMouseUpAsButtonAsObservable();
}
#endregion
#endif
#region ObservableTrigger2DTrigger
/// Sent when another object enters a trigger collider attached to this object (2D physics only).
public static IObservable OnTriggerEnter2DAsObservable(this Component component)
{
if (component == null || component.gameObject == null) return Observable.Empty();
return GetOrAddComponent(component.gameObject).OnTriggerEnter2DAsObservable();
}
/// Sent when another object leaves a trigger collider attached to this object (2D physics only).
public static IObservable OnTriggerExit2DAsObservable(this Component component)
{
if (component == null || component.gameObject == null) return Observable.Empty();
return GetOrAddComponent(component.gameObject).OnTriggerExit2DAsObservable();
}
/// Sent each frame where another object is within a trigger collider attached to this object (2D physics only).
public static IObservable OnTriggerStay2DAsObservable(this Component component)
{
if (component == null || component.gameObject == null) return Observable.Empty();
return GetOrAddComponent(component.gameObject).OnTriggerStay2DAsObservable();
}
#endregion
#region ObservableTriggerTrigger
/// OnTriggerEnter is called when the Collider other enters the trigger.
public static IObservable OnTriggerEnterAsObservable(this Component component)
{
if (component == null || component.gameObject == null) return Observable.Empty();
return GetOrAddComponent(component.gameObject).OnTriggerEnterAsObservable();
}
/// OnTriggerExit is called when the Collider other has stopped touching the trigger.
public static IObservable OnTriggerExitAsObservable(this Component component)
{
if (component == null || component.gameObject == null) return Observable.Empty();
return GetOrAddComponent(component.gameObject).OnTriggerExitAsObservable();
}
/// OnTriggerStay is called once per frame for every Collider other that is touching the trigger.
public static IObservable OnTriggerStayAsObservable(this Component component)
{
if (component == null || component.gameObject == null) return Observable.Empty();
return GetOrAddComponent(component.gameObject).OnTriggerStayAsObservable();
}
#endregion
#region ObservableUpdateTrigger
/// Update is called every frame, if the MonoBehaviour is enabled.
public static IObservable UpdateAsObservable(this Component component)
{
if (component == null || component.gameObject == null) return Observable.Empty();
return GetOrAddComponent(component.gameObject).UpdateAsObservable();
}
#endregion
#region ObservableVisibleTrigger
/// OnBecameInvisible is called when the renderer is no longer visible by any camera.
public static IObservable OnBecameInvisibleAsObservable(this Component component)
{
if (component == null || component.gameObject == null) return Observable.Empty();
return GetOrAddComponent(component.gameObject).OnBecameInvisibleAsObservable();
}
/// OnBecameVisible is called when the renderer became visible by any camera.
public static IObservable OnBecameVisibleAsObservable(this Component component)
{
if (component == null || component.gameObject == null) return Observable.Empty();
return GetOrAddComponent(component.gameObject).OnBecameVisibleAsObservable();
}
#endregion
#if !(UNITY_4_0 || UNITY_4_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_4 || UNITY_4_5)
#region ObservableTransformChangedTrigger
/// Callback sent to the graphic before a Transform parent change occurs.
public static IObservable OnBeforeTransformParentChangedAsObservable(this Component component)
{
if (component == null || component.gameObject == null) return Observable.Empty();
return GetOrAddComponent(component.gameObject).OnBeforeTransformParentChangedAsObservable();
}
/// This function is called when the parent property of the transform of the GameObject has changed.
public static IObservable OnTransformParentChangedAsObservable(this Component component)
{
if (component == null || component.gameObject == null) return Observable.Empty();
return GetOrAddComponent(component.gameObject).OnTransformParentChangedAsObservable();
}
/// This function is called when the list of children of the transform of the GameObject has changed.
public static IObservable OnTransformChildrenChangedAsObservable(this Component component)
{
if (component == null || component.gameObject == null) return Observable.Empty();
return GetOrAddComponent(component.gameObject).OnTransformChildrenChangedAsObservable();
}
#endregion
#region ObservableCanvasGroupChangedTrigger
/// Callback that is sent if the canvas group is changed.
public static IObservable OnCanvasGroupChangedAsObservable(this Component component)
{
if (component == null || component.gameObject == null) return Observable.Empty();
return GetOrAddComponent(component.gameObject).OnCanvasGroupChangedAsObservable();
}
#endregion
#region ObservableRectTransformTrigger
/// Callback that is sent if an associated RectTransform has it's dimensions changed.
public static IObservable OnRectTransformDimensionsChangeAsObservable(this Component component)
{
if (component == null || component.gameObject == null) return Observable.Empty();
return GetOrAddComponent(component.gameObject).OnRectTransformDimensionsChangeAsObservable();
}
/// Callback that is sent if an associated RectTransform is removed.
public static IObservable OnRectTransformRemovedAsObservable(this Component component)
{
if (component == null || component.gameObject == null) return Observable.Empty();
return GetOrAddComponent(component.gameObject).OnRectTransformRemovedAsObservable();
}
#endregion
// uGUI
#region ObservableEventTrigger classes
public static IObservable OnDeselectAsObservable(this UIBehaviour component)
{
if (component == null || component.gameObject == null) return Observable.Empty();
return GetOrAddComponent(component.gameObject).OnDeselectAsObservable();
}
public static IObservable OnMoveAsObservable(this UIBehaviour component)
{
if (component == null || component.gameObject == null) return Observable.Empty();
return GetOrAddComponent(component.gameObject).OnMoveAsObservable();
}
public static IObservable OnPointerDownAsObservable(this UIBehaviour component)
{
if (component == null || component.gameObject == null) return Observable.Empty();
return GetOrAddComponent(component.gameObject).OnPointerDownAsObservable();
}
public static IObservable OnPointerEnterAsObservable(this UIBehaviour component)
{
if (component == null || component.gameObject == null) return Observable.Empty();
return GetOrAddComponent(component.gameObject).OnPointerEnterAsObservable();
}
public static IObservable OnPointerExitAsObservable(this UIBehaviour component)
{
if (component == null || component.gameObject == null) return Observable.Empty();
return GetOrAddComponent(component.gameObject).OnPointerExitAsObservable();
}
public static IObservable OnPointerUpAsObservable(this UIBehaviour component)
{
if (component == null || component.gameObject == null) return Observable.Empty();
return GetOrAddComponent(component.gameObject).OnPointerUpAsObservable();
}
public static IObservable OnSelectAsObservable(this UIBehaviour component)
{
if (component == null || component.gameObject == null) return Observable.Empty();
return GetOrAddComponent(component.gameObject).OnSelectAsObservable();
}
public static IObservable OnPointerClickAsObservable(this UIBehaviour component)
{
if (component == null || component.gameObject == null) return Observable.Empty();
return GetOrAddComponent(component.gameObject).OnPointerClickAsObservable();
}
public static IObservable OnSubmitAsObservable(this UIBehaviour component)
{
if (component == null || component.gameObject == null) return Observable.Empty();
return GetOrAddComponent(component.gameObject).OnSubmitAsObservable();
}
public static IObservable OnDragAsObservable(this UIBehaviour component)
{
if (component == null || component.gameObject == null) return Observable.Empty();
return GetOrAddComponent(component.gameObject).OnDragAsObservable();
}
public static IObservable OnBeginDragAsObservable(this UIBehaviour component)
{
if (component == null || component.gameObject == null) return Observable.Empty();
return GetOrAddComponent(component.gameObject).OnBeginDragAsObservable();
}
public static IObservable OnEndDragAsObservable(this UIBehaviour component)
{
if (component == null || component.gameObject == null) return Observable.Empty();
return GetOrAddComponent(component.gameObject).OnEndDragAsObservable();
}
public static IObservable OnDropAsObservable(this UIBehaviour component)
{
if (component == null || component.gameObject == null) return Observable.Empty();
return GetOrAddComponent(component.gameObject).OnDropAsObservable();
}
public static IObservable OnUpdateSelectedAsObservable(this UIBehaviour component)
{
if (component == null || component.gameObject == null) return Observable.Empty();
return GetOrAddComponent(component.gameObject).OnUpdateSelectedAsObservable();
}
public static IObservable OnInitializePotentialDragAsObservable(this UIBehaviour component)
{
if (component == null || component.gameObject == null) return Observable.Empty();
return GetOrAddComponent(component.gameObject).OnInitializePotentialDragAsObservable();
}
public static IObservable OnCancelAsObservable(this UIBehaviour component)
{
if (component == null || component.gameObject == null) return Observable.Empty();
return GetOrAddComponent(component.gameObject).OnCancelAsObservable();
}
public static IObservable OnScrollAsObservable(this UIBehaviour component)
{
if (component == null || component.gameObject == null) return Observable.Empty();
return GetOrAddComponent(component.gameObject).OnScrollAsObservable();
}
#endregion
#endif
#region ObservableParticleTrigger
/// OnParticleCollision is called when a particle hits a collider.
public static IObservable OnParticleCollisionAsObservable(this Component component)
{
if (component == null || component.gameObject == null) return Observable.Empty();
return GetOrAddComponent(component.gameObject).OnParticleCollisionAsObservable();
}
#if UNITY_5_4_OR_NEWER
/// OnParticleTrigger is called when any particles in a particle system meet the conditions in the trigger module.
public static IObservable OnParticleTriggerAsObservable(this Component component)
{
if (component == null || component.gameObject == null) return Observable.Empty();
return GetOrAddComponent(component.gameObject).OnParticleTriggerAsObservable();
}
#endif
#endregion
}
}