Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using UnityEngine;
- using UnityEngine.EventSystems;
- public class Draggable : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler
- {
- public ActionButton parentActionButton;
- public static Draggable itemBeingDragged;
- public static Vector3 startPosition;
- void IBeginDragHandler.OnBeginDrag( PointerEventData eventData )
- {
- itemBeingDragged = this;
- startPosition = transform.position;
- transform.SetParent( DragPanel.s.transform, true );
- GetComponent<CanvasGroup>( ).blocksRaycasts = false;
- }
- void IDragHandler.OnDrag( PointerEventData eventData )
- {
- transform.position = eventData.position;
- }
- // OnDrop occurs before OnEndDrag and is handled in Droppable.cs
- void IEndDragHandler.OnEndDrag( PointerEventData eventData )
- {
- transform.SetParent( parentActionButton.transform, true );
- parentActionButton.hotkeyText.transform.SetAsLastSibling( );
- transform.position = startPosition;
- GetComponent<CanvasGroup>( ).blocksRaycasts = true;
- if ( itemBeingDragged != null && itemBeingDragged.parentActionButton.buttonType == ActionButton.ButtonType.actionBars )
- {
- parentActionButton.assignSpell( null );
- }
- else if ( itemBeingDragged != null && itemBeingDragged.parentActionButton.buttonType == ActionButton.ButtonType.inventory )
- {
- // TODO prompt to destroy item
- }
- itemBeingDragged = null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement