-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDragAndDrop.cs
More file actions
78 lines (71 loc) · 2.75 KB
/
DragAndDrop.cs
File metadata and controls
78 lines (71 loc) · 2.75 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
using Lean.Touch;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DragAndDrop : MonoBehaviour
{
private LayerMask ignoreLayer;
private Lean.Touch.LeanFinger currentFinger;
private void Awake()
{
ignoreLayer = LayerMask.GetMask("OuterLevel");
}
public void SetFinger(Lean.Touch.LeanFinger finger)
{
currentFinger = finger;
}
public void RaycastDrop()
{
if(currentFinger != null)
{
if (gameObject.GetComponent<InventorySlot>().occupied)
{
#region UICast
foreach (InventorySlot slot in Inventory.Instance.UiSlots)
{
if (slot != gameObject.GetComponent<InventorySlot>())
{
RectTransform slotTransform = slot.transform as RectTransform;
if (RectTransformUtility.RectangleContainsScreenPoint(slotTransform, Input.mousePosition))
{
if (slot.occupied)
{
ItemCombining.Instance.CombineItems(slot.storedObjectId, slot);
}
return;
}
}
}
#endregion
#region physicsCast
RaycastHit hit;
Ray ray = Camera.main.ScreenPointToRay(currentFinger.ScreenPosition);
// Does the ray intersect any objects excluding the player layer
if (Physics.Raycast(ray.origin, ray.direction, out hit, Mathf.Infinity, ~ignoreLayer))
{
if (hit.collider.gameObject.TryGetComponent(out PlaceLocationObject objective) &&
Inventory.Instance.HasItemSelected)
{
if (objective.gameObject.TryGetComponent(out PointOfInterest poi))
{
if (poi.IsFocused)
{
objective.TryInteract(Inventory.Instance.SelectedItem);
}
}
else
{
objective.TryInteract(Inventory.Instance.SelectedItem);
}
}
Debug.DrawRay(ray.origin, ray.direction * hit.distance, Color.yellow);
}
else
{
Debug.DrawRay(ray.origin, ray.direction * 1000, Color.black);
}
#endregion
}
}
}
}