Tanoda
DummyControlUnit.cs
Go to the documentation of this file.
1using UnityEngine;
2using UnityEngine.UI;
3using System.Collections;
4
8public class DummyControlUnit : MonoBehaviour
9{
14 void OnSimpleDragAndDropEvent(DragAndDropCell.DropEventDescriptor desc)
15 {
16 // Get control unit of source cell
17 DummyControlUnit sourceSheet = desc.sourceCell.GetComponentInParent<DummyControlUnit>();
18 // Get control unit of destination cell
19 DummyControlUnit destinationSheet = desc.destinationCell.GetComponentInParent<DummyControlUnit>();
20 switch (desc.triggerType) // What type event is?
21 {
22 case DragAndDropCell.TriggerType.DropRequest: // Request for item drag (note: do not destroy item on request)
23 Debug.Log("Request " + desc.item.name + " from " + sourceSheet.name + " to " + destinationSheet.name);
24 break;
25 case DragAndDropCell.TriggerType.DropEventEnd: // Drop event completed (successful or not)
26 if (desc.permission == true) // If drop successful (was permitted before)
27 {
28 Debug.Log("Successful drop " + desc.item.name + " from " + sourceSheet.name + " to " + destinationSheet.name);
29 }
30 else // If drop unsuccessful (was denied before)
31 {
32 Debug.Log("Denied drop " + desc.item.name + " from " + sourceSheet.name + " to " + destinationSheet.name);
33 }
34 break;
35 case DragAndDropCell.TriggerType.ItemAdded: // New item is added from application
36 Debug.Log("Item " + desc.item.name + " added into " + destinationSheet.name);
37 break;
38 case DragAndDropCell.TriggerType.ItemWillBeDestroyed: // Called before item be destructed (can not be canceled)
39 Debug.Log("Item " + desc.item.name + " will be destroyed from " + sourceSheet.name);
40 break;
41 default:
42 Debug.Log("Unknown drag and drop event");
43 break;
44 }
45 }
46
52 {
53 foreach (DragAndDropCell cell in GetComponentsInChildren<DragAndDropCell>())
54 {
55 if (cell != null)
56 {
57 if (cell.GetItem() == null)
58 {
59 cell.AddItem(Instantiate(item.gameObject).GetComponent<DragAndDropItem>());
60 break;
61 }
62 }
63 }
64 }
65
69 public void RemoveFirstItem()
70 {
71 foreach (DragAndDropCell cell in GetComponentsInChildren<DragAndDropCell>())
72 {
73 if (cell != null)
74 {
75 if (cell.GetItem() != null)
76 {
77 cell.RemoveItem();
78 break;
79 }
80 }
81 }
82 }
83}
UnityEngine.Debug Debug
Definition: TanodaServer.cs:19
Every item's cell must contain this script
void AddItem(DragAndDropItem newItem)
Manualy add item into this cell
DragAndDropItem GetItem()
Get item from this cell
void RemoveItem()
Manualy delete item from this cell
Drag and Drop item.
Example of control application for drag and drop events handle
void RemoveFirstItem()
Remove item from first not empty cell
void AddItemInFreeCell(DragAndDropItem item)
Add item in first free cell