public override IEnumerator Demo(GameObject[] sortingElements) { i = 0; j = 0; // Line 0 (set parameter) pseudoCodeViewer.SetCodeLine(CollectLine(0), Util.BLACKBOARD_TEXT_COLOR); // Create buckets Vector3[] pos = new Vector3[1] { bucketManager.FirstBucketPosition }; int numberOfBuckets = bucketSortManager.NumberOfBuckets; bucketManager.CreateObjects(numberOfBuckets, pos); // Line 1 (Create buckets) yield return(HighlightPseudoCode(CollectLine(1), Util.HIGHLIGHT_STANDARD_COLOR)); // Buckets GameObject[] buckets = null; if (bucketManager != null) { buckets = bucketManager.Buckets; } // Add elements to buckets for (i = 0; i < sortingElements.Length; i++) { // Check if user wants to stop the demo if (sortMain.UserStoppedTask) { break; } // Line 2 (Update for-loop) yield return(HighlightPseudoCode(CollectLine(2), Util.HIGHLIGHT_STANDARD_COLOR)); // Check if user wants to stop the demo if (sortMain.UserStoppedTask) { break; } // Get element GameObject element = sortingElements[i]; PreparePseudocodeValue(element.GetComponent <SortingElementBase>().Value, 1); // Bucket index bucketIndex = BucketIndex(value1, numberOfBuckets, maxValue); // Line 3 (Display bucket index) yield return(HighlightPseudoCode(CollectLine(3), Util.HIGHLIGHT_STANDARD_COLOR)); // Check if user wants to stop the demo if (sortMain.UserStoppedTask) { break; } // Get bucket Bucket bucket = buckets[bucketIndex].GetComponent <Bucket>(); // element.GetComponent<SortingElementBase>().Value - minValue); // Move element above the bucket and put it inside element.transform.position = bucket.transform.position + UtilSort.ABOVE_BUCKET_VR; // Line 4 (Put element into bucket) yield return(HighlightPseudoCode(CollectLine(4), Util.HIGHLIGHT_STANDARD_COLOR)); } // Line 5 (end for-loop) yield return(HighlightPseudoCode(CollectLine(5), Util.HIGHLIGHT_STANDARD_COLOR)); // Display elements for (int x = 0; x < numberOfBuckets; x++) { // Check if user wants to stop the demo if (sortMain.UserStoppedTask) { break; } // Line 6 (For-loop: Sort elements in buckets) //pseudoCodeViewer.SetCodeLine(6, PseudoCode(6, x, Util.NO_VALUE, Util.NO_VALUE, true), Util.HIGHLIGHT_COLOR); //yield return new WaitForSeconds(seconds); //pseudoCodeViewer.SetCodeLine(6, PseudoCode(6, x, Util.NO_VALUE, Util.NO_VALUE, true), Util.BLACKBOARD_TEXT_COLOR); Bucket bucket = buckets[x].GetComponent <Bucket>(); bucket.SetEnterTrigger(false); // Sort bucket *** TODO: go to insertion sort scene bucket.CurrenHolding = InsertionSort.InsertionSortStandard2(bucket.CurrenHolding); // Line 6 (Sort elements in bucket) i = x; yield return(HighlightPseudoCode(CollectLine(6), Util.HIGHLIGHT_STANDARD_COLOR)); // Check if user wants to stop the demo if (sortMain.UserStoppedTask) { break; } // Put elements for display on top of buckets int numberOfElementsInBucket = bucket.CurrenHolding.Count; for (int y = 0; y < numberOfElementsInBucket; y++) { // Check if user wants to stop the demo if (sortMain.UserStoppedTask) { break; } SortingElementBase element = bucket.GetElementForDisplay(y); element.gameObject.active = true; element.transform.position += UtilSort.ABOVE_BUCKET_VR; yield return(demoStepDuration); } } // Line 8 (end for loop) //pseudoCodeViewer.SetCodeLine(8, PseudoCode(8, Util.NO_VALUE, Util.NO_VALUE, Util.NO_VALUE, true), Util.HIGHLIGHT_COLOR); //yield return new WaitForSeconds(seconds); //pseudoCodeViewer.SetCodeLine(8, PseudoCode(8, Util.NO_VALUE, Util.NO_VALUE, Util.NO_VALUE, true), Util.BLACKBOARD_TEXT_COLOR); // Put elements back into list k = 0; // Line 7 (set k) yield return(HighlightPseudoCode(CollectLine(7), Util.HIGHLIGHT_STANDARD_COLOR)); // Holder positions (where the sorting elements initialized) Vector3[] holderPos = sortMain.HolderManager.GetHolderPositions(); // while (k < sortingElements.Length && i < numberOfBuckets) for (i = 0; i < numberOfBuckets; i++) { // Check if user wants to stop the demo if (sortMain.UserStoppedTask) { break; } Bucket bucket = buckets[i].GetComponent <Bucket>(); // number of elements in bucket bucketSize = bucket.CurrenHolding.Count.ToString(); // Line 8 (For-loop: Concatenate all buckets) yield return(HighlightPseudoCode(CollectLine(8), Util.HIGHLIGHT_STANDARD_COLOR)); for (j = 0; j < bucket.CurrenHolding.Count; j++) { // Check if user wants to stop the demo if (sortMain.UserStoppedTask) { break; } // Line 9 (2nd For-loop: Concatenate all buckets) yield return(HighlightPseudoCode(CollectLine(9), Util.HIGHLIGHT_STANDARD_COLOR)); // Check if user wants to stop the demo if (sortMain.UserStoppedTask) { break; } sortingElements[k] = bucket.RemoveSoringElement().gameObject; // Value of sorting element PreparePseudocodeValue(sortingElements[k].GetComponent <SortingElementBase>().Value, 2); // Move element back to holder sortingElements[k].transform.position = holderPos[k] + UtilSort.ABOVE_HOLDER_VR; sortingElements[k].transform.rotation = Quaternion.identity; sortingElements[k].GetComponent <SortingElementBase>().IsSorted = true; // Line 10 (Put element back into list) yield return(HighlightPseudoCode(CollectLine(10), Util.HIGHLIGHT_STANDARD_COLOR)); // Check if user wants to stop the demo if (sortMain.UserStoppedTask) { break; } // Line 11 (Update k) yield return(HighlightPseudoCode(CollectLine(11), Util.HIGHLIGHT_STANDARD_COLOR)); k++; } // Line 12 (2nd for-inner-loop end) yield return(HighlightPseudoCode(CollectLine(12), Util.HIGHLIGHT_STANDARD_COLOR)); // Check if user wants to stop the demo if (sortMain.UserStoppedTask) { break; } } // Line 13 (2nd for-loop end) yield return(HighlightPseudoCode(CollectLine(13), Util.HIGHLIGHT_STANDARD_COLOR)); if (sortMain.UserStoppedTask) { sortMain.UpdateCheckList(Util.DEMO, true); } else { isTaskCompleted = true; } }