Advertisement
Guest User

Untitled

a guest
Jul 26th, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using UnityEngine.UI;
  4. using UnityEngine.EventSystems;
  5.  
  6. public class CraftingClickAndDrag : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler {
  7.  
  8. public static Vector3 startPosition;
  9. public static GameObject itemBeingDragged;
  10. Transform startParent;
  11.  
  12. public int slotNumber;
  13.  
  14. public static int currentSlotNumber;
  15.  
  16. Camera camera;
  17.  
  18. void Start()
  19. {
  20. camera = GameObject.Find("Main Camera").GetComponent<Camera>();
  21. }
  22.  
  23.  
  24. #region IBeginDragHandler implementation
  25.  
  26. public void OnBeginDrag(PointerEventData eventData)
  27. {
  28. itemBeingDragged = gameObject;//(GameObject)Instantiate(gameObject, transform.position, transform.rotation);
  29. startPosition = transform.position;
  30. startParent = transform.parent;
  31. GetComponent<CanvasGroup>().blocksRaycasts = false;
  32. currentSlotNumber = slotNumber;
  33. GameObject.Find("craftingCanvas").GetComponent<ExplorationCraftingUI>().dragItemViewOn(slotNumber);
  34. }
  35.  
  36. #endregion
  37.  
  38. #region IDragHandler implementation
  39.  
  40. public void OnDrag(PointerEventData eventData)
  41. {
  42. Vector3 position = camera.ScreenToWorldPoint(Input.mousePosition);
  43. transform.position = new Vector3 (position.x, position.y, 0);
  44. }
  45.  
  46. #endregion
  47.  
  48. #region IEndDragHandler implementation
  49.  
  50. public void OnEndDrag(PointerEventData eventData)
  51. {
  52. Debug.Log("END DRAG");
  53. itemBeingDragged = null;
  54. transform.position = startPosition;
  55. GetComponent<CanvasGroup>().blocksRaycasts = true;
  56. }
  57.  
  58. #endregion
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement