46 lines
1.1 KiB
C#
46 lines
1.1 KiB
C#
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
namespace UIWidgets
|
|
{
|
|
public abstract class BaseDragSupport : MonoBehaviour
|
|
{
|
|
protected static Dictionary<Transform, RectTransform> DragPoints;
|
|
|
|
private Transform canvasTransform;
|
|
|
|
protected Transform CanvasTransform
|
|
{
|
|
get
|
|
{
|
|
if (canvasTransform == null)
|
|
{
|
|
canvasTransform = Utilites.FindCanvas(base.transform);
|
|
}
|
|
return canvasTransform;
|
|
}
|
|
}
|
|
|
|
public RectTransform DragPoint
|
|
{
|
|
get
|
|
{
|
|
if (DragPoints == null)
|
|
{
|
|
DragPoints = new Dictionary<Transform, RectTransform>();
|
|
}
|
|
if (!DragPoints.ContainsKey(CanvasTransform))
|
|
{
|
|
GameObject gameObject = new GameObject("DragPoint");
|
|
RectTransform rectTransform = gameObject.AddComponent<RectTransform>();
|
|
rectTransform.SetParent(CanvasTransform, false);
|
|
rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 0f);
|
|
rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 0f);
|
|
DragPoints.Add(CanvasTransform, rectTransform);
|
|
}
|
|
return DragPoints[CanvasTransform];
|
|
}
|
|
}
|
|
}
|
|
}
|