using UnityEngine;
using System.Collections;
namespace UIWidgets {
///
/// Draggable UI object..
///
[AddComponentMenu("UI/UIWidgets/Draggable")]
[RequireComponent(typeof(RectTransform))]
public class Draggable : MonoBehaviour {
///
/// The handle.
///
[SerializeField]
GameObject handle;
DraggableHandle handleScript;
///
/// If specified, restricts dragging from starting unless the pointerdown occurs on the specified element.
///
/// The handler.
public GameObject Handle {
get {
return handle;
}
set {
SetHandle(value);
}
}
void Start()
{
SetHandle(handle!=null ? handle : gameObject);
}
///
/// Sets the handle.
///
/// Value.
protected virtual void SetHandle(GameObject value)
{
if (handle)
{
Destroy(handleScript);
}
handle = value;
handleScript = handle.AddComponent();
handleScript.Drag(gameObject.transform as RectTransform);
}
}
}