Browse Source

[Bugfix] Drag Event Handlers Executing for Draggables not Really Being Dragged (#968)

* Draggables are now only treated as dragged based on the state of a bool

Before, when a draggable is being moved even in the editor (or by other things like scroll rects), they can still invoke events. With this fix, we can have the events only execute when they actually are being dragged, be it by the user or some code meant to do said dragging

* Moved Drag event handlers to their own folder
master
CG-Tespy 3 years ago committed by Steve Halliwell
parent
commit
cb21f31f9e
  1. 1
      Assets/Fungus/Docs/CHANGELOG.txt
  2. 12
      Assets/Fungus/Scripts/Components/Draggable2D.cs
  3. 8
      Assets/Fungus/Scripts/EventHandlers/Drag.meta
  4. 0
      Assets/Fungus/Scripts/EventHandlers/Drag/DragCancelled.cs
  5. 0
      Assets/Fungus/Scripts/EventHandlers/Drag/DragCancelled.cs.meta
  6. 6
      Assets/Fungus/Scripts/EventHandlers/Drag/DragCompleted.cs
  7. 0
      Assets/Fungus/Scripts/EventHandlers/Drag/DragCompleted.cs.meta
  8. 3
      Assets/Fungus/Scripts/EventHandlers/Drag/DragEntered.cs
  9. 0
      Assets/Fungus/Scripts/EventHandlers/Drag/DragEntered.cs.meta
  10. 3
      Assets/Fungus/Scripts/EventHandlers/Drag/DragExited.cs
  11. 0
      Assets/Fungus/Scripts/EventHandlers/Drag/DragExited.cs.meta
  12. 0
      Assets/Fungus/Scripts/EventHandlers/Drag/DragStarted.cs
  13. 0
      Assets/Fungus/Scripts/EventHandlers/Drag/DragStarted.cs.meta

1
Assets/Fungus/Docs/CHANGELOG.txt

@ -16,6 +16,7 @@ Unreleased
- WriterAudio.GetSecondsRemaining reports 0 if not playing. Thanks to KVinS.
- Add special case that skips variation logic for sequences that contains no elements, making no change.
- Add NotifyEnd to Writer WaitForInputAndClear logic. Thanks to wolfrug.
- Drag event handlers now only trigger from direct drags, not just movement. Thanks to CG-Tespy.
v3.13.6
======

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

@ -36,6 +36,14 @@ namespace Fungus
[Tooltip("Use the UI Event System to check for drag events. Clicks that hit an overlapping UI object will be ignored. Camera must have a PhysicsRaycaster component, or a Physics2DRaycaster for 2D colliders.")]
[SerializeField] protected bool useEventSystem;
[SerializeField] protected bool beingDragged;
public virtual bool BeingDragged
{
get { return beingDragged; }
set { beingDragged = value; }
}
protected Vector3 startingPosition;
protected bool updatePosition = false;
protected Vector3 newPosition;
@ -95,6 +103,8 @@ namespace Fungus
protected virtual void DoBeginDrag()
{
beingDragged = true;
// Offset the object so that the drag is anchored to the exact point where the user clicked it
float x = Input.mousePosition.x;
float y = Input.mousePosition.y;
@ -161,6 +171,8 @@ namespace Fungus
{
LeanTween.move(gameObject, startingPosition, returnDuration).setEase(LeanTweenType.easeOutExpo);
}
beingDragged = false;
}
protected virtual void DoPointerEnter()

8
Assets/Fungus/Scripts/EventHandlers/Drag.meta

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 21248040e66eae44e925a1352ef3add9
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

0
Assets/Fungus/Scripts/EventHandlers/DragCancelled.cs → Assets/Fungus/Scripts/EventHandlers/Drag/DragCancelled.cs

0
Assets/Fungus/Scripts/EventHandlers/DragCancelled.cs.meta → Assets/Fungus/Scripts/EventHandlers/Drag/DragCancelled.cs.meta

6
Assets/Fungus/Scripts/EventHandlers/DragCompleted.cs → Assets/Fungus/Scripts/EventHandlers/Drag/DragCompleted.cs

@ -159,7 +159,8 @@ namespace Fungus
/// </summary>
public virtual void OnDragEntered(Draggable2D draggableObject, Collider2D targetObject)
{
if (this.targetObjects != null && this.draggableObjects != null &&
if (draggableObject.BeingDragged &&
this.targetObjects != null && this.draggableObjects != null &&
this.draggableObjects.Contains(draggableObject) &&
this.targetObjects.Contains(targetObject))
{
@ -173,7 +174,8 @@ namespace Fungus
/// </summary>
public virtual void OnDragExited(Draggable2D draggableObject, Collider2D targetObject)
{
if (this.targetObjects != null && this.draggableObjects != null &&
if (draggableObject.BeingDragged &&
this.targetObjects != null && this.draggableObjects != null &&
this.draggableObjects.Contains(draggableObject) &&
this.targetObjects.Contains(targetObject))
{

0
Assets/Fungus/Scripts/EventHandlers/DragCompleted.cs.meta → Assets/Fungus/Scripts/EventHandlers/Drag/DragCompleted.cs.meta

3
Assets/Fungus/Scripts/EventHandlers/DragEntered.cs → Assets/Fungus/Scripts/EventHandlers/Drag/DragEntered.cs

@ -117,7 +117,8 @@ namespace Fungus
/// </summary>
public virtual void OnDragEntered(Draggable2D draggableObject, Collider2D targetObject)
{
if (this.targetObjects != null && this.draggableObjects != null &&
if (draggableObject.BeingDragged &&
this.targetObjects != null && this.draggableObjects != null &&
this.draggableObjects.Contains(draggableObject) &&
this.targetObjects.Contains(targetObject))
{

0
Assets/Fungus/Scripts/EventHandlers/DragEntered.cs.meta → Assets/Fungus/Scripts/EventHandlers/Drag/DragEntered.cs.meta

3
Assets/Fungus/Scripts/EventHandlers/DragExited.cs → Assets/Fungus/Scripts/EventHandlers/Drag/DragExited.cs

@ -117,7 +117,8 @@ namespace Fungus
/// </summary>
public virtual void OnDragExited(Draggable2D draggableObject, Collider2D targetObject)
{
if (this.targetObjects != null && this.draggableObjects != null &&
if (draggableObject.BeingDragged &&
this.targetObjects != null && this.draggableObjects != null &&
this.draggableObjects.Contains(draggableObject) &&
this.targetObjects.Contains(targetObject))
{

0
Assets/Fungus/Scripts/EventHandlers/DragExited.cs.meta → Assets/Fungus/Scripts/EventHandlers/Drag/DragExited.cs.meta

0
Assets/Fungus/Scripts/EventHandlers/DragStarted.cs → Assets/Fungus/Scripts/EventHandlers/Drag/DragStarted.cs

0
Assets/Fungus/Scripts/EventHandlers/DragStarted.cs.meta → Assets/Fungus/Scripts/EventHandlers/Drag/DragStarted.cs.meta

Loading…
Cancel
Save