using UnityEngine; using UnityEngine.EventSystems; using System.Collections; namespace UIWidgets { /// /// TreeView drop support. /// Receive drops from TreeView and ListViewIcons. /// [AddComponentMenu("UI/UIWidgets/TreeViewDropSupport")] [RequireComponent(typeof(TreeView))] public class TreeViewDropSupport : MonoBehaviour, IDropSupport>, IDropSupport { TreeView source; /// /// Gets the current TreeView. /// /// Current TreeView. public TreeView 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 Source.Nodes==null || !Source.Nodes.Contains(data); } /// /// Process dropped data. /// /// Data. /// Event data. public void Drop(TreeNode data, PointerEventData eventData) { if (Source.Nodes==null) { Source.Nodes = new ObservableList>(); } Source.Nodes.Add(data); } /// /// 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) { if (Source.Nodes==null) { Source.Nodes = new ObservableList>(); } var newItem = new TreeViewItem(data.Name) { LocalizedName = data.LocalizedName, Icon = data.Icon, Value = data.Value }; var newNode = new TreeNode(newItem); Source.Nodes.Add(newNode); } /// /// Process canceled drop. /// /// Data. /// Event data. public void DropCanceled(ListViewIconsItemDescription data, PointerEventData eventData) { } #endregion } }