private IEnumerator ReverseRemoveCurrentNode(NodeRepresentation nodeRep, bool moveOther) { graphMain.UpdateCheckList(UtilGraph.LIST_VISUAL, false); if (!moveOther) { // Move element back into stack Vector3 onTopOfStack = NextElementPositionOnTopOfList() - oneListIndexUp; nodeRep.MoveNodeRepresentation(onTopOfStack); nodeRep.SetGravity(false); yield return(mediumDuration); nodeRep.SetGravity(true); } else { // Disable gravity of swapping node reps int lastNodeRep = nodeRepresentations.Count - 1; SetGravityForMultipleNodeReps(0, lastNodeRep, false); // First move all other node representations up yield return(MoveOtherNodes(0, lastNodeRep, false)); // Move element back into list nodeRep.MoveNodeRepresentation(spawnPointList.position); yield return(smallDuration); // Enable gravity of swapping node reps SetGravityForMultipleNodeReps(0, lastNodeRep, true); } graphMain.UpdateCheckList(UtilGraph.LIST_VISUAL, true); graphMain.WaitForSupportToComplete--; }
// Swap 1 by 1: Not implemented/used private void SwapPositionsOf(NodeRepresentation np1, NodeRepresentation np2) { np1.SetGravity(false); np2.SetGravity(false); Debug.Log("Switching"); Vector3 np1MoveLeft = np1.transform.position + new Vector3(-0.5f, 0f, 0f); np1.MoveNodeRepresentation(np1MoveLeft); Vector3 np2MoveRight = np2.transform.position + new Vector3(0.5f, 0f, 0f); np2.MoveNodeRepresentation(np2MoveRight); Debug.Log("Done switching"); }
// Adding a visual representation of the node, with priority based on its distance value) public void PriorityAdd(Node node, int index) { UpdateListRoofPosition(); // Move all existing list elements up (from the point where we want to insert the new element) for (int i = 0; i < index; i++) { // Remove gravity to make it easier to move the objects nodeRepresentations[i].GetComponent <Rigidbody>().useGravity = false; // Find new position and move it Vector3 newPos = nodeRepresentations[i].transform.position + oneListIndexUp; // new Vector3(0f, 1f, 0f); nodeRepresentations[i].GetComponent <MoveObject>().SetDestination(newPos); } // Add new element into the open slot Vector3 pos = spawnPointList.position + oneListIndexUp * (nodeRepresentations.Count - index); // new Vector3(0f, 1f, 0f) <- oneListIndexUp NodeRepresentation newPrioNodeRep = CreateNodeRepresentation(node, pos, index); //newPrioNodeRep.GetComponent<TextHolder>().SetSurfaceText(node.NodeAlphaID, node.Dist); newPrioNodeRep.UpdateSurfaceText(UtilGraph.VISITED_COLOR); newPrioNodeRep.MoveNodeRepresentation(pos); nodeRepresentations.Insert(index, newPrioNodeRep); // Change color of the node representation we are looking for if (node.IsEndNode) { newPrioNodeRep.CurrentColor = UtilGraph.SHORTEST_PATH_COLOR; } // Enable gravity again and update indexes for (int i = 0; i < nodeRepresentations.Count; i++) { NodeRepresentation nodeRep = nodeRepresentations[i]; nodeRep.SetGravity(true); nodeRep.ListIndex = i; } }