Advertisement
Guest User

Untitled

a guest
Jun 11th, 2015
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.38 KB | None | 0 0
  1. using System.Collections;
  2. using UnityEngine;
  3. using UnityEngine.EventSystems;
  4.  
  5. public class Draggable : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler
  6. {
  7.     public ActionButton parentActionButton;
  8.  
  9.     public static Draggable itemBeingDragged;
  10.     public static Vector3 startPosition;
  11.  
  12.     void IBeginDragHandler.OnBeginDrag( PointerEventData eventData )
  13.     {
  14.         itemBeingDragged = this;
  15.         startPosition = transform.position;
  16.         transform.SetParent( DragPanel.s.transform, true );
  17.         GetComponent<CanvasGroup>( ).blocksRaycasts = false;
  18.     }
  19.  
  20.     void IDragHandler.OnDrag( PointerEventData eventData )
  21.     {
  22.         transform.position = eventData.position;
  23.     }
  24.  
  25.     // OnDrop occurs before OnEndDrag and is handled in Droppable.cs
  26.  
  27.     void IEndDragHandler.OnEndDrag( PointerEventData eventData )
  28.     {
  29.         transform.SetParent( parentActionButton.transform, true );
  30.         parentActionButton.hotkeyText.transform.SetAsLastSibling( );
  31.         transform.position = startPosition;
  32.         GetComponent<CanvasGroup>( ).blocksRaycasts = true;
  33.  
  34.         if ( itemBeingDragged != null && itemBeingDragged.parentActionButton.buttonType == ActionButton.ButtonType.actionBars )
  35.         {
  36.             parentActionButton.assignSpell( null );
  37.         }
  38.         else if ( itemBeingDragged != null && itemBeingDragged.parentActionButton.buttonType == ActionButton.ButtonType.inventory )
  39.         {
  40.             // TODO prompt to destroy item
  41.         }
  42.         itemBeingDragged = null;
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement