using System.Collections.Generic; using UnityEngine; namespace UIWidgets { public abstract class BaseDragSupport : MonoBehaviour { protected static Dictionary 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(); } if (!DragPoints.ContainsKey(CanvasTransform)) { GameObject gameObject = new GameObject("DragPoint"); RectTransform rectTransform = gameObject.AddComponent(); rectTransform.SetParent(CanvasTransform, false); rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 0f); rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 0f); DragPoints.Add(CanvasTransform, rectTransform); } return DragPoints[CanvasTransform]; } } } }