Пример #1
0
    public void FilterPackagesTest()
    {
        List <GameObject> testComponents = new List <GameObject>();

        int countDocuments   = 20;
        int countDirectories = 7;

        for (int i = 0; i < countDocuments; i++)
        {
            GameObject g = new GameObject();
            g.AddComponent <BaseInformation>();
            g.GetComponent <BaseInformation>().UpdateValues(GetDocumentTreeComponent());
            testComponents.Add(g);
        }

        for (int i = 0; i < countDirectories; i++)
        {
            GameObject g = new GameObject();
            g.AddComponent <BaseInformation>();
            g.GetComponent <BaseInformation>().UpdateValues(GetDirectoryTreeComponent());
            testComponents.Add(g);
        }

        Assert.AreEqual(ComponentFilter.FilterPackages(testComponents).Count, countDirectories);
    }
Пример #2
0
        /// <summary>
        /// Method to traverse the object tree to building the city.
        /// </summary>
        /// <param name="treeObject"></param>
        /// <param name="packageLevel"></param>
        /// <returns></returns>
        private GameObject TraverseTree(TreeComponent treeObject, int packageLevel)
        {
            if (treeObject is DirComponent)
            {
                List <GameObject> childs = new List <GameObject>();

                foreach (TreeComponent child in ((DirComponent)treeObject).components)
                {
                    childs.Add(TraverseTree(child, packageLevel + 1));
                }

                List <GameObject> childDocuments = ComponentFilter.FilterDocuments(childs);
                List <GameObject> childPackages  = ComponentFilter.FilterPackages(childs);

                if (childPackages.Count > 0 && childDocuments.Count > 0)
                {
                    //ComponentLayout.Helix(childDocuments);
                    ComponentLayout.Corner(childDocuments);

                    GameObject helper = componentProducer.GenerateHelper();

                    helperGameObjects.Add(helper);

                    helper.transform.localScale = CalculatePackageSize(childDocuments, helper);
                    SetPackageGameObjectAsParent(helper, childDocuments);

                    childPackages.Add(helper);
                    ComponentLayout.Helix(childPackages);
                }
                else
                {
                    if (childDocuments.Count > 0 && childPackages.Count == 0)
                    {
                        ComponentLayout.Corner(childDocuments);
                    }
                    else
                    {
                        if (childDocuments.Count == 0 && childPackages.Count > 0)
                        {
                            ComponentLayout.Helix(childPackages);
                        }
                    }
                    //ComponentLayout.Helix(childs);
                }

                GameObject packageGameObject = componentProducer.GeneratePackage(treeObject);
                packageGameObject.GetComponent <BaseInformation>().SetChilds(childs);

                packageGameObject.GetComponent <Renderer>().material.color = packageColorizer.PackageLevelColor(packageLevel);

                if (childPackages.Count > 0)
                {
                    packageGameObject.transform.localScale = CalculatePackageSize(childPackages, packageGameObject);
                    SetPackageGameObjectAsParent(packageGameObject, childPackages);
                }
                else
                {
                    packageGameObject.transform.localScale = CalculatePackageSize(childs, packageGameObject);
                    SetPackageGameObjectAsParent(packageGameObject, childs);
                }

                return(packageGameObject);
            }
            else
            {
                GameObject documentGameObject = componentProducer.GenerateDocument(treeObject, selectedMetrics, maxHeight);

                if (documentGameObject.GetComponentInChildren <Renderer>().bounds.size.y > maxDocumentHeight)
                {
                    maxDocumentHeight = documentGameObject.GetComponentInChildren <Renderer>().bounds.size.y;
                }

                return(documentGameObject);
            }
        }