-
Notifications
You must be signed in to change notification settings - Fork 0
/
DragHandeler.cs
60 lines (49 loc) · 2.55 KB
/
DragHandeler.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
using UnityEngine;
using System.Collections;
using UnityEngine.EventSystems;
using UnityEngine.UI;
public class DragHandeler : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler
{
public static GameObject itemBeingDragged;
public Vector3 OffsetVector;
Vector3 startPosition;
Transform startParent;
Transform canvas;
#region IBeginDragHandler implementation
public void OnBeginDrag(PointerEventData eventData)
{
itemBeingDragged = gameObject;
startPosition = transform.position;
startParent = transform.parent;
GetComponent<CanvasGroup>().blocksRaycasts = false;
if (itemBeingDragged.GetComponent<ItemCollisionDetection>().CharCont.GetComponent<Stats>() == null)
{
itemBeingDragged.transform.SetParent(itemBeingDragged.GetComponent<ItemCollisionDetection>().SlotOn.GetComponent<SlotHolder>().SlotsMain.GetComponent<StorageDistanceDetection>().Belonger.GetComponent<Storage>().currentlyInteractingInstance.GetComponent<Stats>().UnReadyItemsUI.transform);
itemBeingDragged.GetComponent<ItemCollisionDetection>().Inv = itemBeingDragged.GetComponent<ItemCollisionDetection>().SlotOn.GetComponent<SlotHolder>().SlotsMain.GetComponent<StorageDistanceDetection>().Belonger.GetComponent<Storage>().currentlyInteractingInstance.GetComponent<Stats>().UnReadyItemsUI;
itemBeingDragged.GetComponent<ItemCollisionDetection>().CharCont = itemBeingDragged.GetComponent<ItemCollisionDetection>().SlotOn.GetComponent<SlotHolder>().SlotsMain.GetComponent<StorageDistanceDetection>().Belonger.GetComponent<Storage>().currentlyInteractingInstance;
}
if (itemBeingDragged.GetComponent<AmmoData>() == true)
{
if (itemBeingDragged.GetComponent<ItemCollisionDetection>().Ammoed == true)
{
itemBeingDragged.GetComponent<RectTransform>().sizeDelta = itemBeingDragged.GetComponent<ItemCollisionDetection>().OriginalSize;
}
itemBeingDragged.GetComponent<ItemCollisionDetection>().Ammoed = false;
}
itemBeingDragged.GetComponent<ItemCollisionDetection> ().SlotOn = null;
}
#endregion
#region IDragHandler implementation
public void OnDrag (PointerEventData eventData)
{
transform.position = Input.mousePosition - OffsetVector;
}
#endregion
#region IEndDragHandler implementation
public void OnEndDrag (PointerEventData eventData)
{
itemBeingDragged = null;
GetComponent<CanvasGroup> ().blocksRaycasts = true;
}
#endregion
}