42 lines
676 B
C#
42 lines
676 B
C#
using UnityEngine;
|
|
|
|
namespace UIWidgets
|
|
{
|
|
[RequireComponent(typeof(RectTransform))]
|
|
public class Draggable : MonoBehaviour
|
|
{
|
|
[SerializeField]
|
|
private GameObject handle;
|
|
|
|
private DraggableHandle handleScript;
|
|
|
|
public GameObject Handle
|
|
{
|
|
get
|
|
{
|
|
return handle;
|
|
}
|
|
set
|
|
{
|
|
SetHandle(value);
|
|
}
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
SetHandle(handle ?? base.gameObject);
|
|
}
|
|
|
|
protected virtual void SetHandle(GameObject value)
|
|
{
|
|
if ((bool)handle)
|
|
{
|
|
Object.Destroy(handleScript);
|
|
}
|
|
handle = value;
|
|
handleScript = handle.AddComponent<DraggableHandle>();
|
|
handleScript.Drag(base.gameObject.transform as RectTransform);
|
|
}
|
|
}
|
|
}
|