From 4b50ab40a6011688c02d37049a95b285e990405f Mon Sep 17 00:00:00 2001 From: fjruizpo Date: Sat, 7 Jan 2017 08:48:59 +0100 Subject: [PATCH] Change Draggable2D and Clickable2D to use the new EventDispatcher calls for events. --- .../Fungus/Scripts/Components/Clickable2D.cs | 8 +--- .../Fungus/Scripts/Components/Draggable2D.cs | 46 ++----------------- 2 files changed, 6 insertions(+), 48 deletions(-) diff --git a/Assets/Fungus/Scripts/Components/Clickable2D.cs b/Assets/Fungus/Scripts/Components/Clickable2D.cs index 93c56112..e36d2434 100644 --- a/Assets/Fungus/Scripts/Components/Clickable2D.cs +++ b/Assets/Fungus/Scripts/Components/Clickable2D.cs @@ -39,13 +39,7 @@ namespace Fungus return; } - // TODO: Cache these objects for faster lookup - var handlers = GameObject.FindObjectsOfType(); - 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() diff --git a/Assets/Fungus/Scripts/Components/Draggable2D.cs b/Assets/Fungus/Scripts/Components/Draggable2D.cs index 68c661ec..8917fd4b 100644 --- a/Assets/Fungus/Scripts/Components/Draggable2D.cs +++ b/Assets/Fungus/Scripts/Components/Draggable2D.cs @@ -57,20 +57,7 @@ namespace Fungus { return; } - - var dragEnteredHandlers = GetHandlers(); - for (int i = 0; i < dragEnteredHandlers.Length; i++) - { - var handler = dragEnteredHandlers[i]; - handler.OnDragEntered(this, other); - } - - var dragCompletedHandlers = GetHandlers(); - 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(); - for (int i = 0; i < dragExitedHandlers.Length; i++) - { - var handler = dragExitedHandlers[i]; - handler.OnDragExited(this, other); - } - - var dragCompletedHandlers = GetHandlers(); - 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() where T : EventHandler @@ -111,12 +85,7 @@ namespace Fungus startingPosition = transform.position; - var dragStartedHandlers = GetHandlers(); - 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(); - for (int i = 0; i < dragCancelledHandlers.Length; i++) - { - var handler = dragCancelledHandlers[i]; - handler.OnDragCancelled(this); - } + EventDispatcher.Raise(new DragCancelled.DragCancelledEvent(this)); if (returnOnCancelled) {