Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- using UnityEngine.EventSystems;
- using UnityEngine.UI;
- public class ItemData : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler, IPointerDownHandler {
- public Item item;
- public int amount;
- public int slot;
- private Inventory inv;
- private Tooltip tooltip;
- private Vector2 offset;
- void Start() {
- inv = GameObject.Find("Inventory").GetComponent<Inventory>();
- tooltip = inv.GetComponent<Tooltip> ();
- }
- public void OnPointerDown (PointerEventData eventData) {
- if (item != null) {
- offset = eventData.position - new Vector2 (this.transform.position.x, this.transform.position.y);
- tooltip.Activate (item);
- }
- }
- public void OnBeginDrag (PointerEventData eventData) {
- if (item != null) {
- if (Input.GetMouseButton (0) && !Input.GetMouseButton (1) && !Input.GetMouseButton (2)) {
- Debug.Log ("Left Mouse Button Down");
- this.transform.SetParent (this.transform.parent.parent.parent);
- this.transform.position = eventData.position - offset;
- GetComponent<CanvasGroup> ().blocksRaycasts = false;
- }
- else if (!Input.GetMouseButton (0) && Input.GetMouseButton (1) && !Input.GetMouseButton (2)) {
- Debug.Log ("Right Mouse Button Down");
- this.transform.SetParent (this.transform.parent.parent.parent);
- this.transform.position = eventData.position - offset;
- GetComponent<CanvasGroup> ().blocksRaycasts = false;
- }
- else if (!Input.GetMouseButton (0) && !Input.GetMouseButton (1) && Input.GetMouseButton (2)) {
- Debug.Log ("Middle Mouse Button Down");
- this.transform.SetParent (this.transform.parent.parent.parent);
- this.transform.position = eventData.position - offset;
- GetComponent<CanvasGroup> ().blocksRaycasts = false;
- }
- }
- }
- public void OnDrag (PointerEventData eventData) {
- if (item != null) {
- this.transform.position = eventData.position - offset;
- }
- }
- public void OnEndDrag (PointerEventData eventData) {
- this.transform.SetParent(inv.inventorySlots[slot].transform);
- this.transform.position = inv.inventorySlots[slot].transform.position;
- GetComponent<CanvasGroup>().blocksRaycasts = true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement