Example #1
0
    private GameObject DuplicateLine(GameObject obj)
    {
        GameObject line = Instantiate(bar, parentPanel.transform, false);

        LineControl.Copy(line.GetComponent <LineControl>(), obj.GetComponent <LineControl>());
        return(line);
    }
Example #2
0
    // Standard top-down Merge Sort for an integer array A.
    private IEnumerator MergeSort(int[] A, GameObject[] A_ob, GameObject[] B_ob)
    {
        int L = A.Length;

        int[] B = new int[L];

        int target = 2020;

        for (int i = 0; i < L; i++)
        {
            B[i] = A[i];
            // copy each A_ob into the second array.
            Destroy(B_ob[i]);
            B_ob[i] = Instantiate(bar, parentPanel.transform, false);
            LineControl.Copy(B_ob[i].GetComponent <LineControl>(), A_ob[i].GetComponent <LineControl>());
            B_ob[i].GetComponent <LineControl>().MoveToLocation(i, (A_ob[i].GetComponent <LineControl>().array + 1) % 2);
            yield return(new WaitForSeconds(0.01f));
        }

        while (!B_ob[B_ob.Length - 1].GetComponent <LineControl>().finishedMoving)
        {
            yield return(new WaitForSeconds(0.001f));
        }

        yield return(StartCoroutine(SplitSubArray(A, 0, L, B, A_ob, B_ob)));

        yield return(new WaitForSeconds(3.0f));

        foreach (GameObject obj in A_ob)
        {
            Destroy(obj);
        }

        array1.alpha = 0;

        yield return(StartCoroutine(Staircase(A, B_ob, target, 0.1f, -1, 1)));

        yield return(StartCoroutine(Staircase2(A, B_ob, target)));

        /*
         * for (int i = 0; i < L; i++)
         * {
         *  A[i] = B[i];
         *  Destroy(A_ob[i]);
         *  A_ob[i] = Instantiate(bar, parentPanel.transform, false);
         *  LineControl.Copy(A_ob[i].GetComponent<LineControl>(), B_ob[i].GetComponent<LineControl>());
         *  A_ob[i].GetComponent<LineControl>().MoveToLocation(i, (B_ob[i].GetComponent<LineControl>().array + 1) % 2);
         * }
         */
    }
Example #3
0
    private IEnumerator MergeArray(int[] A, int start, int middle, int end, int[] B, GameObject[] A_ob, GameObject[] B_ob)
    {
        int i = start;
        int j = middle;

        for (int k = start; k < end; k++)
        {
            if (i < middle && (j >= end || A[i] <= A[j]))
            {
                B[k] = A[i];

                Destroy(B_ob[k]);
                B_ob[k] = Instantiate(bar, parentPanel.transform, false);
                LineControl.Copy(B_ob[k].GetComponent <LineControl>(), A_ob[i].GetComponent <LineControl>());
                B_ob[k].GetComponent <LineControl>().MoveToLocation(k, (A_ob[i].GetComponent <LineControl>().array + 1) % 2);

                //B_ob[k].GetComponent<LineControl>().Instantiate(k, (A_ob[i].GetComponent<LineControl>().array + 1) % 2, A_ob[i].GetComponent<LineControl>().v);
                //while (!B_ob[k].GetComponent<LineControl>().finishedMoving)

                yield return(new WaitForSeconds(0.001f));

                i++;
            }
            else
            {
                B[k] = A[j];
                Destroy(B_ob[k]);
                B_ob[k] = Instantiate(bar, parentPanel.transform, false);
                LineControl.Copy(B_ob[k].GetComponent <LineControl>(), A_ob[j].GetComponent <LineControl>());
                B_ob[k].GetComponent <LineControl>().MoveToLocation(k, (A_ob[j].GetComponent <LineControl>().array + 1) % 2);

                //B_ob[k].GetComponent<LineControl>().Instantiate(k, (A_ob[j].GetComponent<LineControl>().array + 1) % 2, A_ob[j].GetComponent<LineControl>().v);
                yield return(new WaitForSeconds(0.001f));

                j++;
            }

            while (!B_ob[end - 1].GetComponent <LineControl>().finishedMoving)
            {
                yield return(new WaitForSeconds(0.01f));
            }
        }
    }