KpoKec

Panel move (child control)

Jul 11th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.31 KB | None | 0 0
  1. using Toolz;
  2. using UnityEngine;
  3. using UnityEngine.EventSystems;
  4. using UnityEngine.UI;
  5.  
  6. namespace UI_controls {
  7.     [RequireComponent(typeof(Image))]
  8.     public class ControlMovable : MonoBehaviour, IDragHandler, IBeginDragHandler, IEndDragHandler {
  9.         [SerializeField]
  10.         private PanelMoveSize control;
  11.         private Image               image;
  12.         private Vector2             offset = Vector2.zero;
  13.         private RectTransform       rtr;
  14.         private Win32Internal.POINT startPos;
  15.         [SerializeField]
  16.         private PanelMoveSize.MovableType type;
  17.  
  18.         private void Start() {
  19.             rtr          = (RectTransform) transform;
  20.         }
  21.  
  22.         public void OnDrag(PointerEventData eventData) {
  23.             var p = eventData.position;
  24.             p.y = -(Screen.height - p.y);
  25.             p.x /= control.scale.x;
  26.             p.y /= control.scale.y;
  27.             control.Move(p        + offset);
  28.         }
  29.  
  30.         public void OnBeginDrag(PointerEventData eventData) {
  31.             var p = eventData.position;
  32.             p.y = -(Screen.height - p.y);
  33.             p.x /= control.scale.x;
  34.             p.y /= control.scale.y;
  35.             offset = control.rTr.anchoredPosition - p;
  36.         }
  37.  
  38.         public void OnEndDrag(PointerEventData eventData) {
  39.         }
  40.     }
  41. }
Add Comment
Please, Sign In to add comment