|
|
@ -1,14 +1,16 @@ |
|
|
|
// This code is part of the Fungus library (https://github.com/snozbot/fungus) |
|
|
|
// This code is part of the Fungus library (https://github.com/snozbot/fungus) |
|
|
|
// It is released for free under the MIT open source license (https://github.com/snozbot/fungus/blob/master/LICENSE) |
|
|
|
// It is released for free under the MIT open source license (https://github.com/snozbot/fungus/blob/master/LICENSE) |
|
|
|
|
|
|
|
|
|
|
|
using UnityEngine; |
|
|
|
|
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Collections.Generic; |
|
|
|
|
|
|
|
using UnityEngine; |
|
|
|
|
|
|
|
|
|
|
|
namespace Fungus |
|
|
|
namespace Fungus |
|
|
|
{ |
|
|
|
{ |
|
|
|
/// <summary> |
|
|
|
/// <summary> |
|
|
|
/// The block will execute when the player drags an object and successfully drops it on a target object. |
|
|
|
/// The block will execute when the player drags an object and successfully drops it on a target object. |
|
|
|
|
|
|
|
/// |
|
|
|
|
|
|
|
/// ExecuteAlways used to get the Compatibility that we need, use of ISerializationCallbackReceiver is error prone |
|
|
|
|
|
|
|
/// when used on Unity controlled objects as it runs on threads other than main thread. |
|
|
|
/// </summary> |
|
|
|
/// </summary> |
|
|
|
[EventHandlerInfo("Sprite", |
|
|
|
[EventHandlerInfo("Sprite", |
|
|
|
"Drag Completed", |
|
|
|
"Drag Completed", |
|
|
@ -20,18 +22,19 @@ namespace Fungus |
|
|
|
public class DragCompletedEvent |
|
|
|
public class DragCompletedEvent |
|
|
|
{ |
|
|
|
{ |
|
|
|
public Draggable2D DraggableObject; |
|
|
|
public Draggable2D DraggableObject; |
|
|
|
|
|
|
|
|
|
|
|
public DragCompletedEvent(Draggable2D draggableObject) |
|
|
|
public DragCompletedEvent(Draggable2D draggableObject) |
|
|
|
{ |
|
|
|
{ |
|
|
|
DraggableObject = draggableObject; |
|
|
|
DraggableObject = draggableObject; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
[VariableProperty(typeof(GameObjectVariable))] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[VariableProperty(typeof(GameObjectVariable))] |
|
|
|
[SerializeField] protected GameObjectVariable draggableRef; |
|
|
|
[SerializeField] protected GameObjectVariable draggableRef; |
|
|
|
|
|
|
|
|
|
|
|
[VariableProperty(typeof(GameObjectVariable))] |
|
|
|
[VariableProperty(typeof(GameObjectVariable))] |
|
|
|
[SerializeField] protected GameObjectVariable targetRef; |
|
|
|
[SerializeField] protected GameObjectVariable targetRef; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Tooltip("Draggable object to listen for drag events on")] |
|
|
|
[Tooltip("Draggable object to listen for drag events on")] |
|
|
|
[HideInInspector] |
|
|
|
[HideInInspector] |
|
|
|
[SerializeField] protected Draggable2D draggableObject; |
|
|
|
[SerializeField] protected Draggable2D draggableObject; |
|
|
@ -41,12 +44,8 @@ namespace Fungus |
|
|
|
[Tooltip("Drag target object to listen for drag events on")] |
|
|
|
[Tooltip("Drag target object to listen for drag events on")] |
|
|
|
[HideInInspector] |
|
|
|
[HideInInspector] |
|
|
|
[SerializeField] protected Collider2D targetObject; |
|
|
|
[SerializeField] protected Collider2D targetObject; |
|
|
|
[SerializeField] protected List<Collider2D> targetObjects; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[SerializeField] protected List<Collider2D> targetObjects; |
|
|
|
|
|
|
|
|
|
|
|
// There's no way to poll if an object is touching another object, so |
|
|
|
// There's no way to poll if an object is touching another object, so |
|
|
|
// we have to listen to the callbacks and track the touching state ourselves. |
|
|
|
// we have to listen to the callbacks and track the touching state ourselves. |
|
|
@ -56,36 +55,10 @@ namespace Fungus |
|
|
|
|
|
|
|
|
|
|
|
protected EventDispatcher eventDispatcher; |
|
|
|
protected EventDispatcher eventDispatcher; |
|
|
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
|
|
|
/// Awake is called when the script instance is being loaded. |
|
|
|
|
|
|
|
/// </summary> |
|
|
|
|
|
|
|
void Awake() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
//add any dragableobject already present to list for backwards compatability |
|
|
|
|
|
|
|
if (draggableObject != null) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (!draggableObjects.Contains(draggableObject)) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
draggableObjects.Add(draggableObject); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (targetObject != null) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (!targetObjects.Contains(targetObject)) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
targetObjects.Add(targetObject); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
draggableObject = null; |
|
|
|
|
|
|
|
targetObject = null; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected virtual void OnEnable() |
|
|
|
protected virtual void OnEnable() |
|
|
|
{ |
|
|
|
{ |
|
|
|
if(Application.IsPlaying(this)){ |
|
|
|
if (Application.IsPlaying(this)) |
|
|
|
|
|
|
|
{ |
|
|
|
eventDispatcher = FungusManager.Instance.EventDispatcher; |
|
|
|
eventDispatcher = FungusManager.Instance.EventDispatcher; |
|
|
|
|
|
|
|
|
|
|
|
eventDispatcher.AddListener<DragCompletedEvent>(OnDragCompletedEvent); |
|
|
|
eventDispatcher.AddListener<DragCompletedEvent>(OnDragCompletedEvent); |
|
|
@ -97,7 +70,6 @@ namespace Fungus |
|
|
|
dragObj.RegisterHandler(this); |
|
|
|
dragObj.RegisterHandler(this); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected virtual void OnDisable() |
|
|
|
protected virtual void OnDisable() |
|
|
@ -117,30 +89,56 @@ namespace Fungus |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void OnDragCompletedEvent(DragCompletedEvent evt) |
|
|
|
private void OnDragCompletedEvent(DragCompletedEvent evt) |
|
|
|
{ |
|
|
|
{ |
|
|
|
OnDragCompleted(evt.DraggableObject); |
|
|
|
OnDragCompleted(evt.DraggableObject); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void OnDragEnteredEvent(DragEntered.DragEnteredEvent evt) |
|
|
|
private void OnDragEnteredEvent(DragEntered.DragEnteredEvent evt) |
|
|
|
{ |
|
|
|
{ |
|
|
|
OnDragEntered(evt.DraggableObject, evt.TargetCollider); |
|
|
|
OnDragEntered(evt.DraggableObject, evt.TargetCollider); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void OnDragExitedEvent(DragExited.DragExitedEvent evt) |
|
|
|
private void OnDragExitedEvent(DragExited.DragExitedEvent evt) |
|
|
|
{ |
|
|
|
{ |
|
|
|
OnDragExited(evt.DraggableObject, evt.TargetCollider); |
|
|
|
OnDragExited(evt.DraggableObject, evt.TargetCollider); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region Compatibility |
|
|
|
|
|
|
|
|
|
|
|
void ISerializationCallbackReceiver.OnAfterDeserialize() |
|
|
|
void ISerializationCallbackReceiver.OnAfterDeserialize() |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
//presentl using awake due to errors on non main thread access of targetCollider |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void ISerializationCallbackReceiver.OnBeforeSerialize() |
|
|
|
void ISerializationCallbackReceiver.OnBeforeSerialize() |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void Awake() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
//add any dragableobject already present to list for backwards compatability |
|
|
|
|
|
|
|
if (draggableObject != null) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (!draggableObjects.Contains(draggableObject)) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
draggableObjects.Add(draggableObject); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (targetObject != null) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (!targetObjects.Contains(targetObject)) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
targetObjects.Add(targetObject); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
draggableObject = null; |
|
|
|
|
|
|
|
targetObject = null; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endregion Compatibility |
|
|
|
|
|
|
|
|
|
|
|
#region Public members |
|
|
|
#region Public members |
|
|
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
/// <summary> |
|
|
@ -181,7 +179,6 @@ namespace Fungus |
|
|
|
{ |
|
|
|
{ |
|
|
|
overTarget = false; |
|
|
|
overTarget = false; |
|
|
|
targetCollider = null; |
|
|
|
targetCollider = null; |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -212,7 +209,6 @@ namespace Fungus |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public override string GetSummary() |
|
|
|
public override string GetSummary() |
|
|
|
{ |
|
|
|
{ |
|
|
|
string summary = "Draggable: "; |
|
|
|
string summary = "Draggable: "; |
|
|
@ -247,6 +243,6 @@ namespace Fungus |
|
|
|
return summary; |
|
|
|
return summary; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#endregion |
|
|
|
#endregion Public members |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |