Tanoda
EquipmentSlot.cs
Go to the documentation of this file.
1using System;
2using UnityEngine;
4
5public class EquipmentSlot : MonoBehaviour
6{
7 protected DropArea DropArea;
9
10 //private DisableDropCondition disableDropCondition;
11
12 protected virtual void Awake()
13 {
14 DropArea = GetComponent<DropArea>() ?? gameObject.AddComponent<DropArea>();
15 DropArea.OnDropHandler += OnItemDropped;
16 //disableDropCondition = new DisableDropCondition();
17 }
18
19 public void Initialize(MouseDragBehaviour currentItem)
20 {
21 if (currentItem == null)
22 {
23 Debug.LogError("Tried to initialize the slot with an null item!");
24 return;
25 }
26
27 OnItemDropped(currentItem);
28 }
29
30 private void OnItemDropped(MouseDragBehaviour draggable)
31 {
32 draggable.transform.position = transform.position;
33 CurrentItem = draggable;
34 //DropArea.DropConditions.Add(disableDropCondition);
35 draggable.OnBeginDragHandler += CurrentItemOnBeginDrag;
36 }
37
38 //Current item is being dragged so we listen for the EndDrag event
39 private void CurrentItemOnBeginDrag(PointerEventData eventData)
40 {
41 CurrentItem.OnEndDragHandler += CurrentItemEndDragHandler;
42 }
43
44 private void CurrentItemEndDragHandler(PointerEventData eventData, bool dropped)
45 {
46 CurrentItem.OnEndDragHandler -= CurrentItemEndDragHandler;
47
48 if (!dropped)
49 {
50 return;
51 }
52
53 //DropArea.DropConditions.Remove(disableDropCondition); //We dropped the component in another slot so we can remove the DisableDropCondition
54 CurrentItem.OnBeginDragHandler -= CurrentItemOnBeginDrag; //We make sure to remove this listener as the item is no longer in this slot
55 //CurrentItem = null; //We no longer have an item in this slot, so we remove the refference
56 }
57}
UnityEngine.Debug Debug
Definition: TanodaServer.cs:19
Action< MouseDragBehaviour > OnDropHandler
Definition: DropArea.cs:8
MouseDragBehaviour CurrentItem
Definition: EquipmentSlot.cs:8
void Initialize(MouseDragBehaviour currentItem)
DropArea DropArea
Definition: EquipmentSlot.cs:7
virtual void Awake()
Action< PointerEventData > OnBeginDragHandler
Action< PointerEventData, bool > OnEndDragHandler