4using System.Collections;
10[RequireComponent(typeof(RawImage))]
13 [Tooltip(
"Functional type of this cell")]
15 [Tooltip(
"Sprite color for empty cell")]
17 [Tooltip(
"Sprite color for filled cell")]
19 [Tooltip(
"This cell has unlimited amount of items")]
31 StartCoroutine(LateOnEnabled());
34 IEnumerator LateOnEnabled()
36 yield
return new WaitForEndOfFrame();
54 if (myDadItem !=
null)
57 if (myDadItem == item)
62 case CellType.DropOnly:
77 if (myDadItem !=
null)
88 public void OnDrop(PointerEventData data)
96 if ((item !=
null) && (sourceCell !=
this))
98 DropEventDescriptor desc =
new DropEventDescriptor();
109 desc.destinationCell =
this;
111 StartCoroutine(NotifyOnDragEnd(desc));
112 if (desc.permission ==
true)
114 if (myDadItem !=
null)
117 DropEventDescriptor descAutoswap =
new DropEventDescriptor();
118 descAutoswap.item = myDadItem;
120 descAutoswap.destinationCell = sourceCell;
121 SendRequest(descAutoswap);
122 StartCoroutine(NotifyOnDragEnd(descAutoswap));
123 if (descAutoswap.permission ==
true)
142 desc.destinationCell =
this;
144 StartCoroutine(NotifyOnDragEnd(desc));
145 if (desc.permission ==
true)
152 case CellType.DropOnly:
156 desc.destinationCell =
this;
158 StartCoroutine(NotifyOnDragEnd(desc));
159 if (desc.permission ==
true)
198 string itemName = item.name;
199 item = Instantiate(item);
200 item.name = itemName;
203 item.transform.SetParent(transform,
false);
204 item.transform.localPosition =
Vector3.zero;
214 private void DestroyItem()
217 if (myDadItem !=
null)
219 DropEventDescriptor desc =
new DropEventDescriptor();
221 desc.triggerType = TriggerType.ItemWillBeDestroyed;
222 desc.item = myDadItem;
224 desc.destinationCell =
this;
225 SendNotification(desc);
226 if (myDadItem !=
null)
228 Destroy(myDadItem.gameObject);
239 private void SendNotification(DropEventDescriptor desc)
244 gameObject.SendMessageUpwards(
"OnSimpleDragAndDropEvent", desc, SendMessageOptions.DontRequireReceiver);
253 private bool SendRequest(DropEventDescriptor desc)
258 desc.triggerType = TriggerType.DropRequest;
259 desc.permission =
true;
260 SendNotification(desc);
261 result = desc.permission;
271 private IEnumerator NotifyOnDragEnd(DropEventDescriptor desc)
276 yield
return new WaitForEndOfFrame();
278 desc.triggerType = TriggerType.DropEventEnd;
279 SendNotification(desc);
291 RawImage bg = GetComponent<RawImage>();
294 bg.color = myDadItem !=
null ?
full :
empty;
303 myDadItem = GetComponentInChildren<DragAndDropItem>();
324 DropEventDescriptor desc =
new DropEventDescriptor();
326 desc.triggerType = TriggerType.ItemAdded;
329 desc.destinationCell =
this;
330 SendNotification(desc);
349 if ((firstCell !=
null) && (secondCell !=
null))
354 if (firstItem !=
null)
356 firstItem.transform.SetParent(secondCell.transform,
false);
357 firstItem.transform.localPosition = Vector3.zero;
360 if (secondItem !=
null)
362 secondItem.transform.SetParent(firstCell.transform,
false);
363 secondItem.transform.localPosition = Vector3.zero;
Every item's cell must contain this script
void UpdateBackgroundState()
Change cell's sprite color on item put/remove.
DragAndDropItem GetItem()
Get item from this cell
void UpdateMyItem()
Updates my item
static DragEvent OnItemDragEndEvent
static DragAndDropCell sourceCell
static DragAndDropItem draggedItem
void MakeRaycast(bool condition)
Enable item's raycast.
static DragEvent OnItemDragStartEvent
Every item's cell must contain this script
void SwapItems(DragAndDropCell firstCell, DragAndDropCell secondCell)
Swap items between two cells
void OnDrop(PointerEventData data)
Item is dropped in this cell
void UpdateBackgroundState()
Change cell's sprite color on item put/remove.
void RemoveItem()
Manualy delete item from this cell
void UpdateMyItem()
Updates my item
DragAndDropItem GetItem()
Get item from this cell
void AddItem(DragAndDropItem newItem)
Manualy add item into this cell