4using System.Collections;
10[RequireComponent(typeof(
Image))]
37 [Tooltip(
"Functional type of this cell")]
39 [Tooltip(
"Sprite color for empty cell")]
41 [Tooltip(
"Sprite color for filled cell")]
43 [Tooltip(
"This cell has unlimited amount of items")]
55 StartCoroutine(LateOnEnabled());
58 IEnumerator LateOnEnabled()
60 yield
return new WaitForEndOfFrame();
78 if (myDadItem !=
null)
81 if (myDadItem == item)
101 if (myDadItem !=
null)
112 public void OnDrop(PointerEventData data)
120 if ((item !=
null) && (sourceCell !=
this))
135 StartCoroutine(NotifyOnDragEnd(desc));
138 if (myDadItem !=
null)
142 descAutoswap.
item = myDadItem;
145 SendRequest(descAutoswap);
146 StartCoroutine(NotifyOnDragEnd(descAutoswap));
168 StartCoroutine(NotifyOnDragEnd(desc));
182 StartCoroutine(NotifyOnDragEnd(desc));
222 string itemName = item.name;
223 item = Instantiate(item);
224 item.name = itemName;
227 item.transform.SetParent(transform,
false);
228 item.transform.localPosition =
Vector3.zero;
238 private void DestroyItem()
241 if (myDadItem !=
null)
243 DropEventDescriptor desc =
new DropEventDescriptor();
245 desc.triggerType =
TriggerType.ItemWillBeDestroyed;
246 desc.item = myDadItem;
248 desc.destinationCell =
this;
249 SendNotification(desc);
250 if (myDadItem !=
null)
252 Destroy(myDadItem.gameObject);
263 private void SendNotification(DropEventDescriptor desc)
268 gameObject.SendMessageUpwards(
"OnSimpleDragAndDropEvent", desc, SendMessageOptions.DontRequireReceiver);
277 private bool SendRequest(DropEventDescriptor desc)
283 desc.permission =
true;
284 SendNotification(desc);
285 result = desc.permission;
295 private IEnumerator NotifyOnDragEnd(DropEventDescriptor desc)
300 yield
return new WaitForEndOfFrame();
303 SendNotification(desc);
315 Image bg = GetComponent<Image>();
318 bg.color = myDadItem !=
null ?
full :
empty;
327 myDadItem = GetComponentInChildren<DragAndDropItem>();
354 SendNotification(desc);
373 if ((firstCell !=
null) && (secondCell !=
null))
378 if (firstItem !=
null)
380 firstItem.transform.SetParent(secondCell.transform,
false);
381 firstItem.transform.localPosition = Vector3.zero;
384 if (secondItem !=
null)
386 secondItem.transform.SetParent(firstCell.transform,
false);
387 secondItem.transform.localPosition = Vector3.zero;
407 myDadItem = v.myDadItem
System.Drawing.Image Image
DragAndDropCell destinationCell
DragAndDropCell sourceCell
Every item's cell must contain this script
void SwapItems(DragAndDropCell firstCell, DragAndDropCell secondCell)
Swap items between two cells
void AddItem(DragAndDropItem newItem)
Manualy add item into this cell
void OnDrop(PointerEventData data)
Item is dropped in this cell
void UpdateBackgroundState()
Change cell's sprite color on item put/remove.
DragAndDropItem GetItem()
Get item from this cell
void RemoveItem()
Manualy delete 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