public FolderTreeViewGroup(ViewGroupManager owner, EditorWindowConfigSource configSource, string stateConfigName, string containerConfigName, string dragId = null) : base(owner) { m_ConfigSource = configSource; if (configSource != null) { m_TreeViewState = configSource.GetValue <TreeViewState>(stateConfigName); if (m_TreeViewState == null) { m_TreeViewState = new TreeViewState(); configSource.SetValue(stateConfigName, m_TreeViewState); configSource.SetConfigDirty(); } m_TreeViewState.SetConfigSource(configSource); m_TreeItemContainer = configSource.GetValue <FolderTreeItemContainer>(containerConfigName); if (m_TreeItemContainer == null) { m_TreeItemContainer = ScriptableObject.CreateInstance <FolderTreeItemContainer>(); m_TreeItemContainer.ConfigSource = configSource; configSource.SetValue(containerConfigName, m_TreeItemContainer); configSource.SetConfigDirty(); } else { m_TreeItemContainer.ConfigSource = configSource; m_TreeItemContainer.UpdateItemsParent(); } } if (m_TreeViewState == null) { m_TreeViewState = new TreeViewState(); } m_TreeView = new TreeView(owner.WindowOwner, m_TreeViewState); m_DataSource = new FolderTreeViewDataSource(m_TreeView, m_TreeItemContainer, m_ConfigSource); m_TreeViewGUI = new FolderTreeViewGUI(m_TreeView, m_TreeItemContainer); m_TreeViewDragging = new FolderTreeViewDragging(m_TreeView, dragId != null ? dragId : m_TreeView.GetHashCode().ToString()); DeleteItemsAction += DeleteItems; DuplicateItemsAction += DuplicateItems; m_TreeViewGUI.RenameEndAction += RenameItem; m_TreeViewGUI.BeginRenameAction += () => { m_TreeView.state.renameOverlay.isRenamingFilename = true; }; m_TreeViewDragging.EndDragAction += (hasError) => { if (hasError) { m_TreeItemContainer.UpdateValidItems(); } m_TreeView.data.RefreshData(); m_ConfigSource.SetConfigDirty(); }; }
protected override void InitData() { WindowConfigSource = FileConfigSource.CreateFileConfigSource("ViewConfig/TestWindow/config4.txt", true, typeof(FolderTreeViewTestWindowConfig)); m_FolderTreeViewGroup = new FolderTreeViewGroup(m_LayoutGroupMgr, WindowConfigSource, "TreeViewStateConfig", "TreeViewDataContainer"); m_FolderTreeViewGroup.Active = false; m_DataContainer = m_FolderTreeViewGroup.GetDataContainer(); m_DataContainer.ExtNames = ExtNames; m_DataContainer.UpdateValidItems(); m_TreeView = m_FolderTreeViewGroup.GetTreeView(); m_TreeView.useExpansionAnimation = true; m_TreeView.deselectOnUnhandledMouseDown = true; m_TreeView.contextClickItemCallback = ContextClickItemCallback; m_TreeView.contextClickOutsideItemsCallback = ContextClickOutsideItemsCallback; m_LayoutGroupMgr.AddViewGroup(m_FolderTreeViewGroup); m_TipsViewGroup = new TipsViewGroup(m_LayoutGroupMgr); m_TipsViewGroup.Active = false; m_TipsViewGroup.TipStr = "当前根目录路径不存在,请配置根目录路径"; m_TipsViewGroup.DrawAction += () => { EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button("选择目录")) { var path = EditorUtility.OpenFolderPanel("选择目录", "", ""); if (!string.IsNullOrEmpty(path)) { if (m_DataContainer.RootFolderPath != path) { m_DataContainer.RootFolderPath = path; m_TreeView.state.expandedIDs = new List <int>(); m_TreeView.state.selectedIDs = new List <int>(); m_TreeView.state.lastClickedID = Int32.MinValue; m_TreeView.state.scrollPos = Vector2.zero; if (m_TreeView.data != null) { m_TreeView.data.ReloadData(); } WindowConfigSource.SetConfigDirty(); WindowConfigSource.SaveConfigLazily(); } } } GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); }; m_LayoutGroupMgr.AddViewGroup(m_TipsViewGroup); CheckViewVisible(); }
protected override void InitData() { m_WindowConfigSource = FileConfigSource.CreateFileConfigSource("ViewConfig/TestWindow/config5.txt", true, typeof(FolderGridViewTestWindowSetting1)); //m_WindowConfigSource = AssetConfigSource.CreateAssetConfigSource("config", true, typeof(FolderGridViewTestWindowSetting2)); m_FolderGridViewGroup = new FolderGridViewGroup(m_LayoutGroupMgr, m_WindowConfigSource, "TreeViewStateConfig", "TreeViewDataContainer", DragID); m_FolderGridViewGroup.Active = false; var gridView = m_FolderGridViewGroup.GetGridView(); var searchBar = m_FolderGridViewGroup.GetSearchBar(); m_TreeView = m_FolderGridViewGroup.GetFolderGridViewGroup().GetTreeView(); m_DataContainer = m_FolderGridViewGroup.GetDataContainer(); m_DataContainer.ExtNames = ExtNames; m_DataContainer.UpdateValidItems(); gridView.LoadConfig("GvConfig", WindowConfigSource); searchBar.LoadConfig("SearchText", WindowConfigSource); gridView.GirdItemPopupMenuAction += GirdItemPopupMenuAction; gridView.GridViewPopupMenuAction += GridViewPopupMenuAction; m_TreeView = m_FolderGridViewGroup.GetFolderGridViewGroup().GetTreeView(); m_TreeView.useExpansionAnimation = true; m_TreeView.contextClickItemCallback = ContextClickItemCallback; m_FolderGridViewGroup.UpdateSelectionItemsAction += UpdateSelectionItems; m_FolderGridViewGroup.UpdateSearchItemsAction += UpdateSearchItems; m_FolderGridViewGroup.UpdateItemsBySearchText(); m_LayoutGroupMgr.AddViewGroup(m_FolderGridViewGroup); m_TipsViewGroup = new TipsViewGroup(m_LayoutGroupMgr); m_TipsViewGroup.Active = false; m_TipsViewGroup.TipStr = "当前根目录路径不存在,请配置根目录路径"; m_TipsViewGroup.DrawAction += () => { EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button("选择目录")) { var path = EditorUtility.OpenFolderPanel("选择目录", "", ""); if (!string.IsNullOrEmpty(path)) { if (m_DataContainer.RootFolderPath != path) { m_DataContainer.RootFolderPath = path; m_TreeView.state.expandedIDs = new List <int>(); m_TreeView.state.selectedIDs = new List <int>(); m_TreeView.state.lastClickedID = Int32.MinValue; m_TreeView.state.scrollPos = Vector2.zero; if (m_TreeView.data != null) { m_TreeView.data.ReloadData(); } m_WindowConfigSource.SetConfigDirty(); } } } GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); }; m_LayoutGroupMgr.AddViewGroup(m_TipsViewGroup); CheckViewVisible(); }