-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathItemScript.cs
More file actions
64 lines (53 loc) · 1.77 KB
/
Copy pathItemScript.cs
File metadata and controls
64 lines (53 loc) · 1.77 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
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
public class ItemScript : MonoBehaviour, IPointerClickHandler
{
private GameObject invenPanel;
public static GameObject selectedItem;
public static IntVector2 selectedItemSize;
public static bool isDragging = false;
private float slotSize;
public ItemClass item;
private void Awake()
{
invenPanel = GameObject.FindGameObjectWithTag("InvenPanel");
slotSize = invenPanel.GetComponent<InvenGridScript>().slotSize;
}
public void SetItemEquipSize(IntVector2 size)
{
RectTransform rect = GetComponent<RectTransform>();
rect.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, size.x * slotSize);
rect.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, size.y * slotSize);
}
//becomes obsolete later
public void OnPointerClick(PointerEventData eventData)
{
SetSelectedItem(this.gameObject);
CanvasGroup canvas = GetComponent<CanvasGroup>();
canvas.blocksRaycasts = false;
canvas.alpha = 0.5f;
transform.SetParent(GameObject.Find("DragParent").transform);
}
private void Update()
{
if (isDragging)
{
selectedItem.transform.position = Input.mousePosition;
}
}
public static void SetSelectedItem(GameObject obj)
{
selectedItem = obj;
selectedItemSize = obj.GetComponent<ItemScript>().item.size;
isDragging = true;
}
public static void ResetSelectedItem()
{
selectedItem = null;
selectedItemSize = IntVector2.Zero;
isDragging = false;
}
}