Browse Source

Add support to the EventDispatcher in drag and click event handlers.

master
fjruizpo 8 years ago
parent
commit
569389e807
  1. 25
      Assets/Fungus/Scripts/EventHandlers/DragCancelled.cs
  2. 39
      Assets/Fungus/Scripts/EventHandlers/DragCompleted.cs
  3. 26
      Assets/Fungus/Scripts/EventHandlers/DragEntered.cs
  4. 28
      Assets/Fungus/Scripts/EventHandlers/DragExited.cs
  5. 26
      Assets/Fungus/Scripts/EventHandlers/DragStarted.cs
  6. 27
      Assets/Fungus/Scripts/EventHandlers/ObjectClicked.cs

25
Assets/Fungus/Scripts/EventHandlers/DragCancelled.cs

@ -14,9 +14,34 @@ namespace Fungus
[AddComponentMenu("")]
public class DragCancelled : EventHandler
{
public class DragCancelledEvent
{
public Draggable2D DraggableObject;
public DragCancelledEvent(Draggable2D draggableObject)
{
DraggableObject = draggableObject;
}
}
[Tooltip("Draggable object to listen for drag events on")]
[SerializeField] protected Draggable2D draggableObject;
protected override void UnityOnEnable()
{
base.UnityOnEnable();
EventDispatcher.AddListener<DragCancelledEvent>(OnDragCancelledEvent);
}
protected override void UnityOnDisable()
{
base.UnityOnDisable();
EventDispatcher.RemoveListener<DragCancelledEvent>(OnDragCancelledEvent);
}
void OnDragCancelledEvent(DragCancelledEvent evt)
{
OnDragCancelled(evt.DraggableObject);
}
#region Public members
public virtual void OnDragCancelled(Draggable2D draggableObject)

39
Assets/Fungus/Scripts/EventHandlers/DragCompleted.cs

@ -14,6 +14,14 @@ namespace Fungus
[AddComponentMenu("")]
public class DragCompleted : EventHandler
{
public class DragCompletedEvent
{
public Draggable2D DraggableObject;
public DragCompletedEvent(Draggable2D draggableObject)
{
DraggableObject = draggableObject;
}
}
[Tooltip("Draggable object to listen for drag events on")]
[SerializeField] protected Draggable2D draggableObject;
@ -24,6 +32,37 @@ namespace Fungus
// we have to listen to the callbacks and track the touching state ourselves.
protected bool overTarget = false;
protected override void UnityOnEnable()
{
base.UnityOnEnable();
EventDispatcher.AddListener<DragCompletedEvent>(OnDragCompletedEvent);
EventDispatcher.AddListener<DragEntered.DragEnteredEvent>(OnDragEnteredEvent);
EventDispatcher.AddListener<DragExited.DragExitedEvent>(OnDragExitedEvent);
}
protected override void UnityOnDisable()
{
base.UnityOnDisable();
EventDispatcher.RemoveListener<DragCompletedEvent>(OnDragCompletedEvent);
EventDispatcher.RemoveListener<DragEntered.DragEnteredEvent>(OnDragEnteredEvent);
EventDispatcher.RemoveListener<DragExited.DragExitedEvent>(OnDragExitedEvent);
}
void OnDragCompletedEvent(DragCompletedEvent evt)
{
OnDragCompleted(evt.DraggableObject);
}
void OnDragEnteredEvent(DragEntered.DragEnteredEvent evt)
{
OnDragEntered(evt.DraggableObject, evt.TargetCollider);
}
void OnDragExitedEvent(DragExited.DragExitedEvent evt)
{
OnDragExited(evt.DraggableObject, evt.TargetCollider);
}
#region Public members
/// <summary>

26
Assets/Fungus/Scripts/EventHandlers/DragEntered.cs

@ -17,12 +17,38 @@ namespace Fungus
[AddComponentMenu("")]
public class DragEntered : EventHandler
{
public class DragEnteredEvent
{
public Draggable2D DraggableObject;
public Collider2D TargetCollider;
public DragEnteredEvent(Draggable2D draggableObject, Collider2D targetCollider)
{
DraggableObject = draggableObject;
TargetCollider = targetCollider;
}
}
[Tooltip("Draggable object to listen for drag events on")]
[SerializeField] protected Draggable2D draggableObject;
[Tooltip("Drag target object to listen for drag events on")]
[SerializeField] protected Collider2D targetObject;
protected override void UnityOnEnable()
{
base.UnityOnEnable();
EventDispatcher.AddListener<DragEnteredEvent>(OnDragEnteredEvent);
}
protected override void UnityOnDisable()
{
base.UnityOnDisable();
EventDispatcher.RemoveListener<DragEnteredEvent>(OnDragEnteredEvent);
}
void OnDragEnteredEvent(DragEnteredEvent evt)
{
OnDragEntered(evt.DraggableObject, evt.TargetCollider);
}
#region Public members
/// <summary>

28
Assets/Fungus/Scripts/EventHandlers/DragExited.cs

@ -17,12 +17,40 @@ namespace Fungus
[AddComponentMenu("")]
public class DragExited : EventHandler
{
public class DragExitedEvent
{
public Draggable2D DraggableObject;
public Collider2D TargetCollider;
public DragExitedEvent(Draggable2D draggableObject, Collider2D targetCollider)
{
DraggableObject = draggableObject;
TargetCollider = targetCollider;
}
}
[Tooltip("Draggable object to listen for drag events on")]
[SerializeField] protected Draggable2D draggableObject;
[Tooltip("Drag target object to listen for drag events on")]
[SerializeField] protected Collider2D targetObject;
protected override void UnityOnEnable()
{
base.UnityOnEnable();
EventDispatcher.AddListener<DragExitedEvent>(OnDragEnteredEvent);
}
protected override void UnityOnDisable()
{
base.UnityOnDisable();
EventDispatcher.RemoveListener<DragExitedEvent>(OnDragEnteredEvent);
}
void OnDragEnteredEvent(DragExitedEvent evt)
{
OnDragExited(evt.DraggableObject, evt.TargetCollider);
}
#region Public members
/// <summary>

26
Assets/Fungus/Scripts/EventHandlers/DragStarted.cs

@ -14,8 +14,34 @@ namespace Fungus
[AddComponentMenu("")]
public class DragStarted : EventHandler
{
public class DragStartedEvent
{
public Draggable2D DraggableObject;
public DragStartedEvent(Draggable2D draggableObject)
{
DraggableObject = draggableObject;
}
}
[SerializeField] protected Draggable2D draggableObject;
protected override void UnityOnEnable()
{
base.UnityOnEnable();
EventDispatcher.AddListener<DragStartedEvent>(OnDragStartedEvent);
}
protected override void UnityOnDisable()
{
base.UnityOnDisable();
EventDispatcher.RemoveListener<DragStartedEvent>(OnDragStartedEvent);
}
void OnDragStartedEvent(DragStartedEvent evt)
{
OnDragStarted(evt.DraggableObject);
}
#region Public members
/// <summary>

27
Assets/Fungus/Scripts/EventHandlers/ObjectClicked.cs

@ -15,12 +15,39 @@ namespace Fungus
[AddComponentMenu("")]
public class ObjectClicked : EventHandler
{
public class ObjectClickedEvent
{
public Clickable2D ClickableObject;
public ObjectClickedEvent(Clickable2D clickableObject)
{
ClickableObject = clickableObject;
}
}
[Tooltip("Object that the user can click or tap on")]
[SerializeField] protected Clickable2D clickableObject;
[Tooltip("Wait for a number of frames before executing the block.")]
[SerializeField] protected int waitFrames = 1;
protected override void UnityOnEnable()
{
base.UnityOnEnable();
EventDispatcher.AddListener<ObjectClickedEvent>(OnObjectClickedEvent);
}
protected override void UnityOnDisable()
{
base.UnityOnDisable();
EventDispatcher.RemoveListener<ObjectClickedEvent>(OnObjectClickedEvent);
}
void OnObjectClickedEvent(ObjectClickedEvent evt)
{
OnObjectClicked(evt.ClickableObject);
}
/// <summary>
/// Executing a block on the same frame that the object is clicked can cause
/// input problems (e.g. auto completing Say Dialog text). A single frame delay

Loading…
Cancel
Save