You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
119 lines
3.4 KiB
119 lines
3.4 KiB
5 years ago
|
// This code is part of the Fungus library (https://github.com/snozbot/fungus)
|
||
9 years ago
|
// It is released for free under the MIT open source license (https://github.com/snozbot/fungus/blob/master/LICENSE)
|
||
9 years ago
|
|
||
5 years ago
|
using System.Collections.Generic;
|
||
5 years ago
|
using UnityEngine;
|
||
10 years ago
|
|
||
8 years ago
|
namespace Fungus
|
||
10 years ago
|
{
|
||
9 years ago
|
/// <summary>
|
||
|
/// The block will execute when the player starts dragging an object.
|
||
|
/// </summary>
|
||
9 years ago
|
[EventHandlerInfo("Sprite",
|
||
|
"Drag Started",
|
||
|
"The block will execute when the player starts dragging an object.")]
|
||
|
[AddComponentMenu("")]
|
||
5 years ago
|
public class DragStarted : EventHandler, ISerializationCallbackReceiver
|
||
5 years ago
|
{
|
||
8 years ago
|
public class DragStartedEvent
|
||
|
{
|
||
|
public Draggable2D DraggableObject;
|
||
5 years ago
|
|
||
8 years ago
|
public DragStartedEvent(Draggable2D draggableObject)
|
||
|
{
|
||
|
DraggableObject = draggableObject;
|
||
|
}
|
||
|
}
|
||
5 years ago
|
|
||
5 years ago
|
[VariableProperty(typeof(GameObjectVariable))]
|
||
|
[SerializeField] protected GameObjectVariable draggableRef;
|
||
5 years ago
|
|
||
5 years ago
|
[SerializeField] protected List<Draggable2D> draggableObjects;
|
||
10 years ago
|
|
||
5 years ago
|
[HideInInspector]
|
||
|
[SerializeField] protected Draggable2D draggableObject;
|
||
|
|
||
8 years ago
|
protected EventDispatcher eventDispatcher;
|
||
|
|
||
|
protected virtual void OnEnable()
|
||
8 years ago
|
{
|
||
8 years ago
|
eventDispatcher = FungusManager.Instance.EventDispatcher;
|
||
|
|
||
|
eventDispatcher.AddListener<DragStartedEvent>(OnDragStartedEvent);
|
||
8 years ago
|
}
|
||
|
|
||
8 years ago
|
protected virtual void OnDisable()
|
||
8 years ago
|
{
|
||
8 years ago
|
eventDispatcher.RemoveListener<DragStartedEvent>(OnDragStartedEvent);
|
||
|
|
||
|
eventDispatcher = null;
|
||
8 years ago
|
}
|
||
|
|
||
5 years ago
|
private void OnDragStartedEvent(DragStartedEvent evt)
|
||
8 years ago
|
{
|
||
|
OnDragStarted(evt.DraggableObject);
|
||
|
}
|
||
|
|
||
5 years ago
|
#region Compatibility
|
||
|
|
||
5 years ago
|
void ISerializationCallbackReceiver.OnAfterDeserialize()
|
||
|
{
|
||
|
//add any dragableobject already present to list for backwards compatability
|
||
|
if (draggableObject != null)
|
||
|
{
|
||
|
if (!draggableObjects.Contains(draggableObject))
|
||
|
{
|
||
|
draggableObjects.Add(draggableObject);
|
||
|
}
|
||
|
draggableObject = null;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void ISerializationCallbackReceiver.OnBeforeSerialize()
|
||
|
{
|
||
|
}
|
||
|
|
||
5 years ago
|
#endregion Compatibility
|
||
|
|
||
8 years ago
|
#region Public members
|
||
|
|
||
|
/// <summary>
|
||
|
/// Called by the Draggable2D object when the drag starts.
|
||
|
/// </summary>
|
||
9 years ago
|
public virtual void OnDragStarted(Draggable2D draggableObject)
|
||
|
{
|
||
5 years ago
|
if (draggableObjects.Contains(draggableObject))
|
||
9 years ago
|
{
|
||
5 years ago
|
if (draggableRef != null)
|
||
5 years ago
|
{
|
||
|
draggableRef.Value = draggableObject.gameObject;
|
||
|
}
|
||
5 years ago
|
ExecuteBlock();
|
||
5 years ago
|
}
|
||
9 years ago
|
}
|
||
10 years ago
|
|
||
9 years ago
|
public override string GetSummary()
|
||
|
{
|
||
5 years ago
|
string summary = "Draggable: ";
|
||
5 years ago
|
if (this.draggableObjects != null && this.draggableObjects.Count != 0)
|
||
|
{
|
||
|
for (int i = 0; i < this.draggableObjects.Count; i++)
|
||
|
{
|
||
|
if (draggableObjects[i] != null)
|
||
|
{
|
||
|
summary += draggableObjects[i].name + ",";
|
||
5 years ago
|
}
|
||
5 years ago
|
}
|
||
|
}
|
||
5 years ago
|
|
||
|
if (summary.Length == 0)
|
||
9 years ago
|
{
|
||
5 years ago
|
return "None";
|
||
9 years ago
|
}
|
||
5 years ago
|
|
||
5 years ago
|
return summary;
|
||
9 years ago
|
}
|
||
8 years ago
|
|
||
5 years ago
|
#endregion Public members
|
||
9 years ago
|
}
|
||
5 years ago
|
}
|