示例#1
0
    // Creates the holders
    public void CreateObjects(int numberOfHolders, Vector3[] positions)
    {
        if (containsHolders)
        {
            return;
        }

        Vector3 firstHolderPos = new Vector3(firstHolderPosition.position.x + (UtilSort.MAX_NUMBER_OF_ELEMENTS - numberOfHolders) * (UtilSort.SPACE_BETWEEN_HOLDERS / 2), firstHolderPosition.position.y, firstHolderPosition.position.z);

        holders = new GameObject[numberOfHolders]; // ***
        for (int x = 0; x < numberOfHolders; x++)
        {
            holders[x] = Instantiate(holderPrefab, firstHolderPos + new Vector3((x * UtilSort.SPACE_BETWEEN_HOLDERS), 0f, 0f), Quaternion.identity);
            switch (superElement.GetTeachingAlgorithm().AlgorithmName)
            {
            case UtilSort.BUBBLE_SORT: holders[x].AddComponent <BubbleSortHolder>(); break;

            case UtilSort.INSERTION_SORT: holders[x].AddComponent <InsertionSortHolder>(); break;

            case UtilSort.BUCKET_SORT: holders[x].AddComponent <BucketSortHolder>(); break;

            case UtilSort.MERGE_SORT: holders[x].AddComponent <MergeSortHolder>(); break;

            default: Debug.LogError("Add subclass for holder!"); break;
            }

            holders[x].GetComponent <HolderBase>().SuperElement = superElement; // null(?): add C# script to holder / sorting elements
            holders[x].transform.parent = sortingTableHoldersObj.transform;
        }
        containsHolders = true;

        // TODO: incease width of table
        //Vector3 lastHolder = holders[holders.Length - 1].transform.position;
        //sortingTableHoldersObj.GetComponentInChildren<MeshRenderer>().transform.localScale += new Vector3(lastHolder.x - firstHolderPos.x, 0f, 0f);
    }
示例#2
0
    // Creation without rules
    public void CreateObjects(int numberOfElements, Vector3[] positions) // NOT USED?
    {
        if (containsElements)
        {
            return;
        }

        Debug.Log("OBS!!!!! Fix back to random here <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
        int val = 0;

        sortingElements = new GameObject[numberOfElements]; // Util.CreateObjects(sortingElementPrefab, numberOfElements, positions, gameObject);
        for (int x = 0; x < numberOfElements; x++)
        {
            sortingElements[x] = Instantiate(sortingElementPrefab, positions[x] + UtilSort.ABOVE_HOLDER_VR, Quaternion.identity);
            switch (superElement.GetTeachingAlgorithm().AlgorithmName)
            {
            case Util.BUBBLE_SORT: sortingElements[x].AddComponent <BubbleSortElement>(); break;

            case Util.INSERTION_SORT: sortingElements[x].AddComponent <InsertionSortElement>(); break;

            case Util.BUCKET_SORT: sortingElements[x].AddComponent <BucketSortElement>(); break;

            case Util.MERGE_SORT: sortingElements[x].AddComponent <MergeSortElement>(); break;

            default: Debug.LogError("Add subclass for sorting element!"); break;
            }
            sortingElements[x].GetComponent <SortingElementBase>().Value     = val++;//Random.Range(0, UtilSort.MAX_VALUE);
            sortingElements[x].GetComponent <ISortSubElement>().SuperElement = superElement;
            sortingElements[x].GetComponent <ElementInteraction>().SetParent(sortingTableElementsObj.transform);
        }

        for (int x = 0; x < sortingElements.Length; x++)
        {
            // Hotfix (sorting element currentHolding / prevHolding problem)
            sortingElements[x].GetComponent <SortingElementBase>().PlaceManuallySortingElementOn(GetComponent <HolderManager>().Holders[x].GetComponent <HolderBase>());
        }

        containsElements = true;
    }