public void CopySubtree(Vector3 offset)
        {
            Queue <Linker.Container> childrenQueue    = new Queue <Linker.Container>();
            Queue <Linker.Container> newChildrenQueue = new Queue <Linker.Container>();

            Linker.Container parent;
            Linker.Container newParent;
            Linker.Container newChild;

            Vector3 position = self.transform.position;
            Vector3 size     = self.transform.localScale;

            Vector3 newPosition = new Vector3(position.x + offset.x, position.y + offset.y, position.z + offset.z);
            Vector3 newSize     = new Vector3(size.x, size.y, size.z);

            Linker.Container newRoot = this.CopyNode();
            if (newRoot.subtreeDepth < -1)             // Copied a node != root when full tree was displayed
            {
                newRoot.subtreeDepth = -1;
            }
            newRoot.depth        = newRoot.GetDepth();
            newRoot.rootPosition = newPosition;
            newRoot.root         = newRoot;

            childrenQueue.Enqueue(this);
            newChildrenQueue.Enqueue(newRoot);
            while (childrenQueue.Count != 0)
            {
                parent    = childrenQueue.Dequeue();
                newParent = newChildrenQueue.Dequeue();
                foreach (Linker.Container child in parent.children)
                {
                    newChild              = child.CopyNode();
                    newChild.parent       = newParent;
                    newChild.depth        = newChild.GetDepth();
                    newChild.rootPosition = newRoot.rootPosition;
                    newChild.root         = newRoot;
                    newChildrenQueue.Enqueue(newChild);

                    newParent.children.Add(newChild);
                    childrenQueue.Enqueue(child);
                }

                foreach (Linker.Container child in newParent.children)                // Add siblings
                {
                    foreach (Linker.Container sibling in newParent.children)
                    {
                        if (child.id != sibling.id)
                        {
                            child.siblings.Add(sibling);
                        }
                    }
                }
            }
            SetMaxDepth(newRoot, GetMaxDepth(newRoot));             // Calculate max depth and set all nodes max depth to it in the new tree starting from the new root

            InstantiateNode(newRoot, newPosition, newSize);
        }
Exemple #2
0
    public void InitializeNodes()
    {
        Queue <Linker.Container> childrenQueue = new Queue <Linker.Container>();

        Linker.Container parent;
        int   id        = 0;
        float colorTint = 0.2f;

        root.parent         = null;
        root.root           = root;
        root.siblings       = new List <Linker.Container>();
        root.depth          = root.GetDepth();
        root.id             = id++;
        root.isInstantiated = false;
        root.isDrawingLine  = false;
        root.subtreeDepth   = 0;

        childrenQueue.Enqueue(root);
        while (childrenQueue.Count != 0)
        {
            parent = childrenQueue.Dequeue();
            foreach (Linker.Container child in parent.children)
            {
                child.siblings = new List <Linker.Container>();
                foreach (var sibling in parent.children)                 // Add all siblings to all children
                {
                    if (child.id != sibling.id)
                    {
                        child.siblings.Add(sibling);
                    }
                }

                child.parent         = parent;
                child.depth          = child.GetDepth();
                child.id             = id++;
                child.root           = root;
                child.isInstantiated = false;
                child.isDrawingLine  = false;
                child.subtreeDepth   = -1;
                child.rootPosition   = root.rootPosition;

                if (child.id > 0 && child.id < 4)
                {
                    child.color = new Color();
                    switch (child.id)
                    {
                    case 1:
                        child.color = Color.red;
                        break;

                    case 2:
                        child.color = Color.green;
                        break;

                    case 3:
                        child.color = Color.blue;
                        break;
                    }
                }

                else
                {
                    child.color = new Color(parent.color.r + colorTint, parent.color.g + colorTint, parent.color.b + colorTint);
                }

                childrenQueue.Enqueue(child);
            }
        }

        SetMaxDepth(root, GetMaxDepth(root));
    }
    public void InitializeNodes()
    {
        Queue <Linker.Container> childrenQueue = new Queue <Linker.Container>();

        Linker.Container parent;
        int   id            = 0;
        float colorTint     = 0.2f;
        int   maxFileSize   = (int)Mathf.Log(root.GetMaxFileSize());
        int   maxFolderSize = (int)Mathf.Log(root.GetSize());

        Debug.Log(maxFileSize + ", " + maxFolderSize);

        Color fileColor = new Color();

        fileColor = Color.red;

        root.color          = new Color();
        root.color          = Color.white;
        root.parent         = null;
        root.root           = root;
        root.siblings       = new List <Linker.Container>();
        root.depth          = root.GetDepth();
        root.id             = id++;
        root.isInstantiated = false;
        root.isDrawingLine  = false;
        root.subtreeDepth   = 0;

        childrenQueue.Enqueue(root);
        while (childrenQueue.Count != 0)
        {
            parent = childrenQueue.Dequeue();
            foreach (Linker.Container child in parent.children)
            {
                child.siblings = new List <Linker.Container>();
                foreach (var sibling in parent.children) // Add all siblings to all children
                {
                    if (child.id != sibling.id)
                    {
                        child.siblings.Add(sibling);
                    }
                }

                child.parent         = parent;
                child.depth          = child.GetDepth();
                child.id             = id++;
                child.root           = root;
                child.isInstantiated = false;
                child.isDrawingLine  = false;
                child.subtreeDepth   = -1;
                child.rootPosition   = root.rootPosition;

                if (child.size == 0) // folder
                {
                    child.color = child.CalculateColor(root.color, maxFolderSize);
                }
                else
                {
                    child.color = child.CalculateColor(fileColor, maxFileSize);
                }

                /*
                 *              if (child.id > 0 && child.id < 4)
                 *              {
                 *                      child.color = new Color();
                 *                      switch (child.id)
                 *                      {
                 *                              case 1:
                 *                                      child.color = Color.red;
                 *                                      break;
                 *                              case 2:
                 *                                      child.color = Color.green;
                 *                                      break;
                 *                              case 3:
                 *                                      child.color = Color.blue;
                 *                                      break;
                 *                      }
                 *              }
                 *
                 *              else
                 *                      child.color = new Color(parent.color.r + colorTint, parent.color.g + colorTint, parent.color.b + colorTint);
                 */

                childrenQueue.Enqueue(child);
            }
        }

        SetMaxDepth(root, GetMaxDepth(root));
    }