void InitData(bool isChange) { if (!isChange) { return; } foreach (Transform child in baseDirTrsm) { Destroy(child.gameObject); } if (FilePanel.instance != null) { Destroy(FilePanel.instance.gameObject); } if (FileInfoPanel.instance != null) { Destroy(FileInfoPanel.instance.gameObject); } if (DirPanel.instance != null) { Destroy(DirPanel.instance.gameObject); } for (int i = 0; i < baseDirData.dirs.Count; i++) { DirData oneDirData = baseDirData.dirs[i]; Transform dirObj = Instantiate(dirPrefab, baseDirTrsm); dirObj.GetComponent <Toggle>().group = baseToggleGroup; oneDirData.attachedObj = dirObj; oneDirData.parentDir = baseDirData; DirPrefab tmpDirPrefab = dirObj.GetComponent <DirPrefab>(); tmpDirPrefab.SetDirName(oneDirData.dirName); tmpDirPrefab.SetPos(0); tmpDirPrefab.attachedDirData = oneDirData; } baseDirData.isFold = false; for (int i = 0; i < baseDirData.files.Count; i++) { FileData oneFileData = baseDirData.files[i]; Transform fileObj = Instantiate(filePrefab, baseDirTrsm); fileObj.GetComponent <Toggle>().group = baseToggleGroup; oneFileData.attachedObj = fileObj; oneFileData.parentDir = baseDirData; fileObj.GetComponent <FilePrefab>().Init(oneFileData); } ResetSize(); }
/// <summary> /// 新建最外层文件夹 /// </summary> public void Btn_baseNewDir() { Transform dirObj = Instantiate(dirPrefab, baseDirTrsm); dirObj.GetComponent <Toggle>().group = baseToggleGroup; DirData tmp = new DirData(); baseDirData.dirs.Add(tmp); tmp.parentDir = baseDirData; tmp.dirName = "默认分组"; tmp.attachedObj = dirObj; DirPrefab tmpDirPrefab = dirObj.GetComponent <DirPrefab>(); tmpDirPrefab.SetDirName(tmp.dirName); tmpDirPrefab.SetPos(0); tmpDirPrefab.attachedDirData = tmp; dirObj.SetSiblingIndex(tmp.GetDirIndex()); SaveData(); ResetSize(); }
public void OnToggleClick(bool isOn) { if (isOn) { nowIsOpen = !nowIsOpen; attachedDirData.isFold = !nowIsOpen; transform.Find("dir/dirState").GetComponent <Image>().sprite = nowIsOpen ? dirOpenImg : dirCloseImg; transform.Find("files").gameObject.SetActive(nowIsOpen); if (nowIsOpen) { Transform fileParent = transform.Find("files"); if (fileParent.childCount == 0) { for (int i = 0; i < attachedDirData.dirs.Count; i++) { DirData oneDirData = attachedDirData.dirs[i]; Transform dirObj = Instantiate(Main.instance.dirPrefab, fileParent); dirObj.GetComponent <Toggle>().group = Main.instance.baseToggleGroup; oneDirData.attachedObj = dirObj; oneDirData.parentDir = attachedDirData; DirPrefab tmpDirPrefab = dirObj.GetComponent <DirPrefab>(); tmpDirPrefab.SetDirName(oneDirData.dirName); tmpDirPrefab.SetPos(oneDirData.GetParentDirArr().Count * 100); tmpDirPrefab.attachedDirData = oneDirData; } for (int i = 0; i < attachedDirData.files.Count; i++) { FileData oneFileData = attachedDirData.files[i]; Transform fileObj = Instantiate(Main.instance.filePrefab, fileParent); fileObj.GetComponent <Toggle>().group = Main.instance.baseToggleGroup; oneFileData.attachedObj = fileObj; oneFileData.parentDir = attachedDirData; fileObj.GetComponent <FilePrefab>().Init(oneFileData); } } } Main.instance.ResetSize(); } }
public void Btn_newDir() { int dirArrCount = attachedDirData.GetParentDirArr().Count; if (dirArrCount >= 4) { return; } if (attachedDirData.isFold) { Toggle tmpToggle = GetComponent <Toggle>(); if (!tmpToggle.isOn) { tmpToggle.isOn = true; } else { OnToggleClick(true); } } Transform parentTrsm = transform.Find("files"); Transform dirObj = Instantiate(Main.instance.dirPrefab, parentTrsm); dirObj.GetComponent <Toggle>().group = Main.instance.baseToggleGroup; DirData tmp = new DirData(); attachedDirData.dirs.Add(tmp); tmp.parentDir = attachedDirData; tmp.dirName = "默认分组"; tmp.attachedObj = dirObj; DirPrefab tmpDirPrefab = dirObj.GetComponent <DirPrefab>(); tmpDirPrefab.SetDirName(tmp.dirName); tmpDirPrefab.SetPos((dirArrCount + 1) * 100); tmpDirPrefab.attachedDirData = tmp; dirObj.SetSiblingIndex(tmp.GetDirIndex()); Main.instance.SaveData(); Main.instance.ResetSize(); }