/*public void UpdateMasterAttributeList()
     * {
     *
     * }*/

    //Called to Instantiate new DataObjects and populate them with Data from their respective parents
    public void SetDataLists(TreeObjectCollection <string> DataTreeToSet)
    {
        dataObjectPrefab = (GameObject)Resources.Load("Prefabs/DataObject");
        DataList         = new List <string>();
        CodeList         = new List <string>();
        DataObjectList   = new List <Transform>();
        DataList         = DataTreeToSet.ToList();
        for (int i = 0; i < DataList.Count; i++)
        {
            CodeList.Add(DataList[i].Split(splitChar)[0].Trim());
        }
        dataTree = DataTreeToSet;
    }
    //This fills the root's tree, again only the root does this, the other DataObjects simply copy from this tree
    IEnumerator BuildTree()
    {
        //Set an arbitrary root node for the tree, this shouldn't be displayed
        dataTree = new TreeObjectCollection <string>("Root");
        //The 2D List contains several rows of Trees organized by their NAICS Code digits
        List <TreeObjectCollection <string> >[] TwoDList = { new List <TreeObjectCollection <string> >(), new List <TreeObjectCollection <string> >(), new List <TreeObjectCollection <string> >(), new List <TreeObjectCollection <string> >() };
        for (int i = 0; i < CodeList.Count; i++)
        {
            //Debug.Log("DataList: " + i + " = " + CodeList[i] + " LENGTH = " + CodeList[i].Length);
            if (CodeList[i].Length == 2)
            {
                TwoDList[0].Add(new TreeObjectCollection <string>(DataList[i], dataTree));
                dataTree.children.Add(TwoDList[0][TwoDList[0].Count - 1]);
                //Debug.Log("Root child: " + dataTree.children[dataTree.children.Count - 1].data);
            }
            else if (CodeList[i].Length == 3)
            {
                TwoDList[1].Add(new TreeObjectCollection <string>(DataList[i]));
            }
            else if (CodeList[i].Length == 4)
            {
                TwoDList[2].Add(new TreeObjectCollection <string>(DataList[i]));
            }
            else if (CodeList[i].Length >= 5)
            {
                TwoDList[3].Add(new TreeObjectCollection <string>(DataList[i]));
            }
            //yield return null;
        }

        Debug.Log("2dCount2 = " + TwoDList[0].Count);
        Debug.Log("2dCount3 = " + TwoDList[1].Count);
        Debug.Log("2dCount4 = " + TwoDList[2].Count);
        Debug.Log("2dCount5 = " + TwoDList[3].Count);

        //Now that the 2D List is established, start from the bottom row and point the trees to their parents and those parents to them
        for (int i = 3; i > 0; i--)
        {
            int tempCount = TwoDList[i].Count;
            TreeObjectCollection <string> lastParent = dataTree;
            int lastParentIndex = 0;
            for (int j = 0; j < tempCount; j++)
            {
                if (TwoDList[i][j].data.StartsWith(lastParent.data.Split(splitChar)[0].Trim()))
                {
                    TwoDList[i][j].parent = lastParent;
                    TwoDList[i][j].parent.children.Add(TwoDList[i][j]);

                    //TwoDList[i].RemoveAt(j);
                    //yield return null;
                }
                else
                {
                    for (int k = lastParentIndex; k < TwoDList[i - 1].Count; k++)
                    {
                        if (TwoDList[i][j].data.StartsWith(TwoDList[i - 1][k].data.Split(splitChar)[0].Trim()))
                        {
                            TwoDList[i][j].parent = TwoDList[i - 1][k];
                            TwoDList[i][j].parent.children.Add(TwoDList[i][j]);

                            lastParent      = TwoDList[i][j].parent;
                            lastParentIndex = k + 1;
                            //TwoDList[i].RemoveAt(j);
                            //Debug.Log("Data = " + TwoDList[i][j].data + " Parent = " + TwoDList[i][j].parent.data);
                            yield return(null);
                        }
                    }
                }
            }
        }
        Debug.Log("All Done.");
        StartCoroutine(GenerateCollection());
        //yield return null;
    }