using UnityEngine;
using UnityEngine.EventSystems;
using System.Collections;
namespace UIWidgets {
///
/// TreeViewNode drag support.
///
[AddComponentMenu("UI/UIWidgets/TreeViewNodeDragSupport")]
[RequireComponent(typeof(TreeViewComponent))]
public class TreeViewNodeDragSupport : DragSupport> {
///
/// The drag info.
///
[SerializeField]
public ListViewIconsItemComponent DragInfo;
///
/// Start this instance.
///
protected virtual void Start()
{
if (DragInfo!=null)
{
DragInfo.gameObject.SetActive(false);
}
}
///
/// Set Data, which will be passed to Drop component.
///
/// Current event data.
protected override void InitDrag(PointerEventData eventData)
{
Data = GetComponent().Node;
ShowDragInfo();
}
///
/// Shows the drag info.
///
protected virtual void ShowDragInfo()
{
if (DragInfo==null)
{
return ;
}
DragInfo.transform.SetParent(DragPoint, false);
DragInfo.transform.localPosition = new Vector3(-5, 5, 0);
DragInfo.SetData(new ListViewIconsItemDescription() {
Name = Data.Item.Name,
LocalizedName = Data.Item.LocalizedName,
Icon = Data.Item.Icon,
Value = Data.Item.Value
});
DragInfo.gameObject.SetActive(true);
}
///
/// Hides the drag info.
///
protected virtual void HideDragInfo()
{
if (DragInfo==null)
{
return ;
}
DragInfo.gameObject.SetActive(false);
}
///
/// Called when drop completed.
///
/// true if Drop component received data; otherwise, false.
public override void Dropped(bool success)
{
HideDragInfo();
base.Dropped(success);
}
}
}