Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using Toolz;
- using UnityEngine;
- using UnityEngine.EventSystems;
- using UnityEngine.Rendering.PostProcessing;
- using UnityEngine.UI;
- namespace UI_controls {
- [RequireComponent(typeof(Image))]
- public class ControlSizable : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler, IDragHandler, IBeginDragHandler, IEndDragHandler {
- [SerializeField]
- private PanelMoveSize control;
- [SerializeField]
- private PanelMoveSize.SizableType type;
- private Vector2 startPos;
- private Vector2 startSize;
- private Image image;
- private void Start() {
- if (type == PanelMoveSize.SizableType.HorizontalRight && control.minWidth <= 0) control.minWidth += ((RectTransform) transform).sizeDelta.x;
- if (type == PanelMoveSize.SizableType.HorizontalLeft && control.minWidth <= 0) control.minWidth += ((RectTransform) transform).sizeDelta.x;
- if (type == PanelMoveSize.SizableType.VerticalTop && control.minHeight <= 0) control.minHeight += ((RectTransform) transform).sizeDelta.y;
- if (type == PanelMoveSize.SizableType.VerticalBottom && control.minHeight <= 0) control.minHeight += ((RectTransform) transform).sizeDelta.y;
- }
- public void OnPointerEnter(PointerEventData eventData) {
- //
- }
- public void OnPointerExit(PointerEventData eventData) {
- //
- }
- public void OnDrag(PointerEventData eventData) {
- var p = eventData.position;
- p.x /= control.scale.x;
- p.y /= control.scale.y;
- control.Resize(startSize + p - startPos, type);
- }
- public void OnBeginDrag(PointerEventData eventData) {
- startPos = eventData.position;
- startPos.x /= control.scale.x;
- startPos.y /= control.scale.y;
- startSize = control.rTr.sizeDelta;
- }
- public void OnEndDrag(PointerEventData eventData) {
- }
- }
- }
Add Comment
Please, Sign In to add comment