public void AddBranch(FolderItemSlot itemSlot, int count, int startIndex, bool skipFirstPlacement = false) { if (!skipFirstPlacement) { //Update positions for (int i = startIndex; i < itemSlot.SubItems.Count; i++) { RectTransform childTransform = ((Component)itemSlot.SubItems[i]).GetComponent <RectTransform>(); childTransform.anchoredPosition = new Vector2(childTransform.anchoredPosition.x, childTransform.anchoredPosition.y + (SlotOffset.y * count)); } } if (itemSlot.Show) { //Update branch count itemSlot.BranchCount += count; //Update child line if (itemSlot.ChildLine) { itemSlot.ChildLine.sizeDelta = new Vector2(itemSlot.ChildLine.sizeDelta.x, ChildLineOffset.y * (itemSlot.BranchCount - 1)); } //Recursive branching if (itemSlot.Parent != null) { AddBranch((FolderItemSlot)itemSlot.Parent, count, itemSlot.BranchIndex + 1); } } }
public void RemoveFile(string path) { if (Items.ContainsKey(path)) { FileItemSlot fileSlot = (FileItemSlot)Items[path]; if (fileSlot.Parent != null) { FolderItemSlot parentSlot = (FolderItemSlot)fileSlot.Parent; parentSlot.SubItems.Remove(fileSlot); if (parentSlot.Show) { RemoveBranch(parentSlot, fileSlot.BranchCount, fileSlot.BranchIndex); } else { for (int i = fileSlot.BranchIndex; i < parentSlot.SubItems.Count; i++) { RectTransform childTransform = ((Component)parentSlot.SubItems[i]).GetComponent <RectTransform>(); childTransform.anchoredPosition = new Vector2(childTransform.anchoredPosition.x, childTransform.anchoredPosition.y - (SlotOffset.y * fileSlot.BranchCount)); parentSlot.SubItems[i].BranchIndex = i; } } Destroy(fileSlot.gameObject); Items.Remove(path); } } }
public void Hide(string path) { if (Items.ContainsKey(path)) { FolderItemSlot folderSlot = (FolderItemSlot)Items[path]; RemoveBranch((FolderItemSlot)folderSlot.Parent, folderSlot.BranchCount - 1, folderSlot.BranchIndex + 1); folderSlot.BranchCount = 1; } }
public void Show(string path) { if (Items.ContainsKey(path)) { FolderItemSlot folderSlot = (FolderItemSlot)Items[path]; folderSlot.BranchCount = 1; for (int i = 0; i < folderSlot.SubItems.Count; i++) { AddBranch(folderSlot, folderSlot.SubItems[i].BranchCount, folderSlot.SubItems[i].BranchIndex + 1, true); } } }
public void RemoveFolder(string path) { if (Items.ContainsKey(path)) { FolderItemSlot folderSlot = (FolderItemSlot)Items[path]; if (folderSlot.Parent != null) { for (int i = 0; i < folderSlot.SubItems.Count; i++) { //Recursive branching if (folderSlot.SubItems[i].GetType() == typeof(FolderItemSlot)) { RemoveFolder(folderSlot.SubItems[i].Path); i--; } else { Items.Remove(folderSlot.SubItems[i].Path); } } FolderItemSlot parentSlot = (FolderItemSlot)folderSlot.Parent; parentSlot.SubItems.Remove(folderSlot); if (parentSlot.Show) { RemoveBranch(parentSlot, folderSlot.BranchCount, folderSlot.BranchIndex); } else { for (int i = folderSlot.BranchIndex; i < parentSlot.SubItems.Count; i++) { RectTransform childTransform = ((Component)parentSlot.SubItems[i]).GetComponent <RectTransform>(); childTransform.anchoredPosition = new Vector2(childTransform.anchoredPosition.x, childTransform.anchoredPosition.y - (SlotOffset.y * folderSlot.BranchCount)); parentSlot.SubItems[i].BranchIndex = i; } } Destroy(folderSlot.gameObject); Items.Remove(path); } } }
public void CreateFile(FolderItemSlot folderItemSlot, string path) { if (!Items.ContainsKey(path)) { FileItemSlot fileSlotChild = Instantiate(FileItemTemplate, folderItemSlot.FileSlotOrigin); fileSlotChild.gameObject.SetActive(true); fileSlotChild.Path = path; fileSlotChild.NameText.text = Path.GetFileNameWithoutExtension(fileSlotChild.Path); fileSlotChild.Parent = folderItemSlot; fileSlotChild.BranchIndex = folderItemSlot.SubItems.Count; fileSlotChild.GetComponent <RectTransform>().anchoredPosition = new Vector2(SlotOffset.x, SlotOffset.y * (folderItemSlot.BranchCount - 1)); if (folderItemSlot.Show) { folderItemSlot.BranchCount += 1; if (folderItemSlot.ChildLine) { folderItemSlot.ChildLine.sizeDelta = new Vector2(folderItemSlot.ChildLine.sizeDelta.x, ChildLineOffset.y * (folderItemSlot.BranchCount - 1)); } if (folderItemSlot.Parent != null) { AddBranch((FolderItemSlot)folderItemSlot.Parent, 1, folderItemSlot.BranchIndex + 1); } } else { int branchCount = 0; for (int i = 0; i < folderItemSlot.SubItems.Count; i++) { branchCount += folderItemSlot.SubItems[i].BranchCount; } fileSlotChild.GetComponent <RectTransform>().anchoredPosition = new Vector2(SlotOffset.x, SlotOffset.y * branchCount); } folderItemSlot.SubItems.Add(fileSlotChild); Items.Add(path, fileSlotChild); } }