Browse Source

Change Draggable2D and Clickable2D to use the new EventDispatcher calls for events.

master
fjruizpo 8 years ago
parent
commit
4b50ab40a6
  1. 8
      Assets/Fungus/Scripts/Components/Clickable2D.cs
  2. 46
      Assets/Fungus/Scripts/Components/Draggable2D.cs

8
Assets/Fungus/Scripts/Components/Clickable2D.cs

@ -39,13 +39,7 @@ namespace Fungus
return;
}
// TODO: Cache these objects for faster lookup
var handlers = GameObject.FindObjectsOfType<ObjectClicked>();
for (int i = 0; i < handlers.Length; i++)
{
var handler = handlers[i];
handler.OnObjectClicked(this);
}
EventDispatcher.Raise(new ObjectClicked.ObjectClickedEvent(this));
}
protected virtual void DoPointerEnter()

46
Assets/Fungus/Scripts/Components/Draggable2D.cs

@ -57,20 +57,7 @@ namespace Fungus
{
return;
}
var dragEnteredHandlers = GetHandlers<DragEntered>();
for (int i = 0; i < dragEnteredHandlers.Length; i++)
{
var handler = dragEnteredHandlers[i];
handler.OnDragEntered(this, other);
}
var dragCompletedHandlers = GetHandlers<DragCompleted>();
for (int i = 0; i < dragCompletedHandlers.Length; i++)
{
var handler = dragCompletedHandlers[i];
handler.OnDragEntered(this, other);
}
EventDispatcher.Raise(new DragEntered.DragEnteredEvent(this, other));
}
protected virtual void OnTriggerExit2D(Collider2D other)
@ -79,20 +66,7 @@ namespace Fungus
{
return;
}
var dragExitedHandlers = GetHandlers<DragExited>();
for (int i = 0; i < dragExitedHandlers.Length; i++)
{
var handler = dragExitedHandlers[i];
handler.OnDragExited(this, other);
}
var dragCompletedHandlers = GetHandlers<DragCompleted>();
for (int i = 0; i < dragCompletedHandlers.Length; i++)
{
var handler = dragCompletedHandlers[i];
handler.OnDragExited(this, other);
}
EventDispatcher.Raise(new DragExited.DragExitedEvent(this, other));
}
protected virtual T[] GetHandlers<T>() where T : EventHandler
@ -111,12 +85,7 @@ namespace Fungus
startingPosition = transform.position;
var dragStartedHandlers = GetHandlers<DragStarted>();
for (int i = 0; i < dragStartedHandlers.Length; i++)
{
var handler = dragStartedHandlers[i];
handler.OnDragStarted(this);
}
EventDispatcher.Raise(new DragStarted.DragStartedEvent(this));
}
protected virtual void DoDrag()
@ -152,7 +121,7 @@ namespace Fungus
{
if (handler.IsOverTarget())
{
handler.OnDragCompleted(this);
EventDispatcher.Raise(new DragCompleted.DragCompletedEvent(this));
dragCompleted = true;
if (returnOnCompleted)
{
@ -164,12 +133,7 @@ namespace Fungus
if (!dragCompleted)
{
var dragCancelledHandlers = GetHandlers<DragCancelled>();
for (int i = 0; i < dragCancelledHandlers.Length; i++)
{
var handler = dragCancelledHandlers[i];
handler.OnDragCancelled(this);
}
EventDispatcher.Raise(new DragCancelled.DragCancelledEvent(this));
if (returnOnCancelled)
{

Loading…
Cancel
Save