public void ToggleSubtree(RenderMode mode) { if (this.size != 0) // A file has no subtree { return; } Linker.Container child = this.children[0]; if (child.isInstantiated) // The tree has been instantiated { if (child.self.activeSelf) // GameObject is active { DisableSubtree(); ToggleSubtreeLines(); } else { EnableSubtree(); } } else { InstantiateSubtree(mode, 1); } }
public void InstantiateRoot(Linker.Container root, Vector3 startPosition, Vector3 size) { GameObject prefab; if (root.size == 0) { prefab = folderPrefab; } else { prefab = filePrefab; } root.self = Instantiate(prefab, new Vector3(startPosition.x, startPosition.y, startPosition.z), Quaternion.identity); root.line = Instantiate(linePrefab); root.isInstantiated = true; root.rootPosition = new Vector3(0, 0, 0); root.self.transform.localScale = size; root.self.GetComponent <Renderer>().material.color = root.color; root.folderPrefab = folderPrefab; root.filePrefab = filePrefab; root.linePrefab = linePrefab; root.self.GetComponent <Linker>().container = root; }
public int GetMaxFileSize() { Queue <Linker.Container> parentQueue = new Queue <Linker.Container>(); List <Linker.Container> files = new List <Linker.Container>(); Linker.Container parent = null; int maxFileSize = 0; parentQueue.Enqueue(this); while (parentQueue.Count != 0) { parent = parentQueue.Dequeue(); foreach (Linker.Container child in parent.children) { if (child.size != 0) { files.Add(child); } else { parentQueue.Enqueue(child); } } } foreach (Linker.Container file in files) { if (file.size > maxFileSize) { maxFileSize = file.size; } } return(maxFileSize); }
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); }
private int RecursiveDepth(Linker.Container node, int depth) { if (node.parent == null) { return(depth); } return(RecursiveDepth(node.parent, ++depth)); }
private void Start() { nodes = new List <List <Linker.Container> >(); root = JSONParser.Read(file); InitializeNodes(); InstantiateRoot(root, new Vector3(0, 0, 0), new Vector3(0.25f, 0.25f, 0.25f)); }
private List <List <Linker.Container> > GetAllSiblings(int depth) { List <List <Linker.Container> > siblings = new List <List <Linker.Container> >(); Queue <Linker.Container> childrenQueue = new Queue <Linker.Container>(); Linker.Container parent = this; // 'this' is the root Linker.Container child; int level = 0; bool depthReached = false; //siblings.Add(new List<Linker.Container>()); //siblings[level++].Add(parent); // Add node as the single object at the first level if (depth == 0) { return(siblings); } siblings.Add(new List <Linker.Container>()); // Cover edge case so we don't need to check against root's parent, since it's parent is null foreach (Linker.Container grandchild in parent.children) // Add root's children to the queue { childrenQueue.Enqueue(grandchild); } while (childrenQueue.Count != 0) { child = childrenQueue.Dequeue(); foreach (Linker.Container grandchild in child.children) // Add the parent's children to the queue { childrenQueue.Enqueue(grandchild); } if (child.parent.id != parent.id) // If there is a new grandparent, increment level { if (level == depth) { depthReached = true; } else { level++; parent = child.parent; siblings.Add(new List <Linker.Container>()); } } siblings[level].Add(child); if (depthReached) { break; } } return(siblings); }
public void Init(SteamVR_Action_Boolean action, SteamVR_Input_Sources handType) { Debug.Log("load file"); var path = StandaloneFileBrowser.OpenFilePanel("Open File", "", "", false); root = JSONParser.Read(path[0]); nodes = new List <List <Linker.Container> >(); //root = JSONParser.Read(file); InitializeNodes(); InstantiateRoot(root, new Vector3(0, 0, 0), new Vector3(0.25f, 0.25f, 0.25f)); }
private int RecursiveSize(Linker.Container node, int size) { foreach (Linker.Container child in node.children) { if (child.size != 0) // leaf node, no children { size += child.size; } else { size = RecursiveSize(child, size); } } return(size); }
public void InstantiateNode(Linker.Container node, Vector3 position, Vector3 size) { if (node.size == 0) { node.self = Instantiate(node.folderPrefab, new Vector3(position.x, position.y, position.z), Quaternion.identity); } else { node.self = Instantiate(node.filePrefab, new Vector3(position.x, position.y, position.z), Quaternion.identity); } node.line = Instantiate(node.linePrefab); node.isInstantiated = true; node.self.GetComponent <Linker>().container = node; node.self.transform.localScale = size; // Change size node.self.GetComponent <Renderer>().material.color = node.color; // Change color }
private void SetMaxDepth(Linker.Container root, int maxDepth) { Queue <Linker.Container> childrenQueue = new Queue <Linker.Container>(); Linker.Container parent; childrenQueue.Enqueue(root); while (childrenQueue.Count != 0) // set max depth { parent = childrenQueue.Dequeue(); parent.maxDepth = maxDepth; foreach (Linker.Container child in parent.children) { childrenQueue.Enqueue(child); } } }
private Linker.Container CopyNode() { Linker.Container copy = new Linker.Container(); copy.color = new Color(); copy.children = new List <Container>(); copy.siblings = new List <Container>(); copy.parent = null; copy.self = null; copy.folderPrefab = this.folderPrefab; copy.filePrefab = this.filePrefab; copy.linePrefab = this.linePrefab; copy.isInstantiated = false; copy.isDrawingLine = false; copy.id = this.id; copy.subtreeDepth = -1; copy.name = this.name; copy.size = this.size; copy.weight = this.weight; copy.color = this.color; return(copy); }
private int GetMaxDepth(Linker.Container root) { Queue <Linker.Container> childrenQueue = new Queue <Linker.Container>(); Linker.Container parent; int maxDepth = 0; childrenQueue.Enqueue(root); while (childrenQueue.Count != 0) // Get max depth { parent = childrenQueue.Dequeue(); if (parent.depth > maxDepth) { maxDepth = parent.depth; } foreach (Linker.Container child in parent.children) { childrenQueue.Enqueue(child); } } return(maxDepth); }
private List <List <Linker.Container> > GetAllLevels(int depth) { List <List <Linker.Container> > levels = new List <List <Linker.Container> >(); if (depth == 0) { return(levels); } int newSubtreeDepth = -1; if (this.subtreeDepth > -1) { newSubtreeDepth = this.subtreeDepth + depth; this.subtreeDepth = newSubtreeDepth; } int depthOffset = this.depth + 1; Queue <Linker.Container> childrenQueue = new Queue <Linker.Container>(); Linker.Container child = this; // 'this' is the root int level = 0; bool depthReached = false; //levels.Add(new List<Linker.Container>()); //levels[level++].Add(child); // Add root node on a single level levels.Add(new List <Linker.Container>()); foreach (Linker.Container grandchild in child.children) // Add the parent's children to the queue { childrenQueue.Enqueue(grandchild); } while (childrenQueue.Count != 0) { child = childrenQueue.Dequeue(); foreach (Linker.Container grandchild in child.children) // Add the parent's children to the queue { childrenQueue.Enqueue(grandchild); } if (child.depth > depthOffset + level) { if (level + 1 == depth) { depthReached = true; } else { level++; levels.Add(new List <Linker.Container>()); } } if (depthReached) { break; } child.subtreeDepth = newSubtreeDepth; levels[level].Add(child); } return(levels); }