void Start() { acceptingNewCommand = false; emptySlot = null; spacing = -50; offset = (int)transform.position.y; // !!! Set Pivot Anchor (x,y) = (0,1) maxCommands = 6; }
void AdjustEmptySpace(TopCommandSlot moveSlot, TopCommand movingCommand) { //Dynamically adjust the position of emptySpace int emptySpaceIndex = (((int)movingCommand.transform.position.y) - offset) / spacing; if (emptySpaceIndex < 0) { moveSlot.transform.SetAsFirstSibling(); } else if (emptySpaceIndex >= GetComponentsInChildren <TopCommandSlot>().Length) { moveSlot.transform.SetSiblingIndex(GetComponentsInChildren <TopCommandSlot>().Length - 1); } else { moveSlot.transform.SetSiblingIndex(emptySpaceIndex); } }
void IPointerEnterHandler.OnPointerEnter(PointerEventData eventData) { if (DragHandler.commandBeingDragged) { outsidePanel = false; } if (SpawnCMDHandler.commandBeingSpawned) { if (GetComponentsInChildren <TopCommandSlot>().Length == maxCommands) { return; } acceptingNewCommand = true; emptySlot = Instantiate(Resources.Load("CSlotPrefab", typeof(TopCommandSlot))) as TopCommandSlot; emptySlot.transform.SetParent(transform); ExecuteEvents.Execute <IUpdateNumbers>(targetPanel.gameObject, null, (x, y) => x.UpdateNumbers(true)); } }
void IHasFinalised.HasFinalised() { int hasDestroied = 0; if (DragHandler.commandBeingDragged) { if (outsidePanel) { TopCommandSlot tobeDiscarded = DragHandler.commandBeingDragged.GetComponentInParent <TopCommandSlot>(); tobeDiscarded.destructCommand(); Destroy(tobeDiscarded.gameObject); hasDestroied = 1; outsidePanel = false; } else { DragHandler.commandBeingDragged.transform.localPosition = Vector2.zero; } } if (SpawnCMDHandler.commandBeingSpawned) { emptySlot.AcceptCommand(SpawnCMDHandler.commandBeingSpawned); acceptingNewCommand = false; emptySlot = null; } //Only shows debugging tool when there are commands in the panel if (GetLength() == hasDestroied) { debugPanel.gameObject.SetActive(false); } else { debugPanel.gameObject.SetActive(true); } }