using UnityEngine;
using UnityEngine.EventSystems;
using System.Collections;
namespace UIWidgets {
///
/// TreeViewNode drop support.
/// Receive drops from TreeView and ListViewIcons.
///
[AddComponentMenu("UI/UIWidgets/TreeViewNodeDropSupport")]
[RequireComponent(typeof(TreeViewComponent))]
public class TreeViewNodeDropSupport : MonoBehaviour, IDropSupport>, IDropSupport {
TreeViewComponent source;
///
/// Gets the current TreeViewComponent.
///
/// Current TreeViewComponent.
public TreeViewComponent Source {
get {
if (source==null)
{
source = GetComponent();
}
return source;
}
}
#region IDropSupport>
///
/// Determines whether this instance can receive drop with the specified data and eventData.
///
/// true if this instance can receive drop with the specified data and eventData; otherwise, false.
/// Data.
/// Event data.
public bool CanReceiveDrop(TreeNode data, PointerEventData eventData)
{
return data.CanBeParent(Source.Node);
}
///
/// Process dropped data.
///
/// Data.
/// Event data.
public void Drop(TreeNode data, PointerEventData eventData)
{
data.Parent = Source.Node;
}
///
/// Process canceled drop.
///
/// Data.
/// Event data.
public void DropCanceled(TreeNode data, PointerEventData eventData)
{
}
#endregion
#region IDropSupport
///
/// Determines whether this instance can receive drop with the specified data and eventData.
///
/// true if this instance can receive drop with the specified data and eventData; otherwise, false.
/// Data.
/// Event data.
public bool CanReceiveDrop(ListViewIconsItemDescription data, PointerEventData eventData)
{
return true;
}
///
/// Process dropped data.
///
/// Data.
/// Event data.
public void Drop(ListViewIconsItemDescription data, PointerEventData eventData)
{
var node = Source.Node;
if (node.Nodes==null)
{
node.Nodes = new ObservableList>();
}
var newItem = new TreeViewItem(data.Name) {
LocalizedName = data.LocalizedName,
Icon = data.Icon,
Value = data.Value
};
var newNode = new TreeNode(newItem);
node.Nodes.Add(newNode);
}
///
/// Process canceled drop.
///
/// Data.
/// Event data.
public void DropCanceled(ListViewIconsItemDescription data, PointerEventData eventData)
{
}
#endregion
}
}