/// <summary> /// 更改文件勾选状态 /// </summary> private void OnChangeSelectSVNToolFile(SVNToolFile targetFile) { String targetPath = targetFile.path; Boolean targetSelect = targetFile.ifSelected; foreach (SVNToolPrefab prefab in storedPrefabs) { if (!prefab.ifSelected) { continue; } foreach (SVNToolFile file in prefab.contentFilePath) { if (file != targetFile && file.path.Equals(targetPath)) { file.ifSelected = targetSelect; } } foreach (SVNToolFolder folder in prefab.contentFolderPath) { foreach (SVNToolFile file in folder.contentNeedSyncFiles) { if (file != targetFile && file.path.Equals(targetPath)) { file.ifSelected = targetSelect; } } } } }
/// <summary> /// 添加路径至配置中 /// </summary> /// <param name="path"></param> public void AddNewSVNToolPath(String path) { if (Directory.Exists(path)) // 如果是文件夹 { foreach (SVNToolFolder folder in contentFolderPath) { if (folder.path.Equals(path)) { return; } } SVNToolFolder newFolder = new SVNToolFolder(path); contentFolderPath.Add(newFolder); } else if (File.Exists(path)) // 如果是文件 { foreach (SVNToolFile file in contentFilePath) { if (file.path.Equals(path)) { return; } } SVNToolFile newFile = new SVNToolFile(path); contentFilePath.Add(newFile); } }
/// <summary> /// 获取文件同步状态 /// </summary> private void GetSVNToolObjStateJob(SVNToolPrefab prefab) { List <SVNToolFile> files = prefab.contentFilePath; for (Int32 i = 0; i < files.Count; i++) { SVNToolFile file = files[i]; file.CanBeCommit = SVNToolUtil.GetSVNToolFileStateJob(file.path); // 获取文件的svn url file.SyncFileSVNURL(); } }
/// <summary> /// 添加路径到未选择路径中 /// </summary> /// <param name="file"></param> private void AddSVNToolFileIntoHideResult(SVNToolFile file) { Boolean ifExist = false; foreach (SVNToolFile toolFile in hideResult) { if (toolFile.path.Equals(file.path)) { ifExist = true; break; } } if (!ifExist) { hideResult.Add(file); } }
private void SVNToolWindowWriteFileField(SVNToolFile file) { // 浏览模式 - 仅展示需同步文件 if (file.GetSVNToolFileCurrentSyncState() == EnumSVNToolFileNeedSyncState.SELECTED_NEED_COMMIT) { SetSVNToolFileCanBeCommitColor(); } else if (file.GetSVNToolFileCurrentSyncState() == EnumSVNToolFileNeedSyncState.NEED_COMMIT_WITHOUT_SEELCTED) { SetSVNToolFileNeedSelectedColor(); } Boolean preSelected = file.ifSelected; file.ifSelected = GUILayout.Toggle(file.ifSelected, "", GUILayout.Width(20)); if (file.ifSelected != preSelected) { ifChooseDataDirty = true; OnChangeSelectSVNToolFile(file); SaveSVNToolPrefabs(); // 保存配置 GUI.FocusControl("zero"); // 取消聚焦,防止选中“当前已选择”后不刷新 } EditorGUILayout.LabelField(file.name, GUILayout.MinWidth(m_RightPathTextLength)); GUILayout.FlexibleSpace(); if (GUILayout.Button("Find", GUILayout.Width(40))) { UESvnOperation.GetSvnOperation().ShowFileInExplorer(file.path); } if (GUILayout.Button("完整路径", GUILayout.Width(70))) { ShowNotification(new GUIContent(file.svnURL)); } if (GUILayout.Button("查看差异", GUILayout.Width(70))) { UESvnOperation.GetSvnOperation().DiffFile(file.path); } SetDefaultSVNToolBackgroundColor(); }
private void SetSVNToolPrefabGUI() { EditorGUILayout.BeginHorizontal(GUILayout.Height(500)); #region 择预设 EditorGUILayout.BeginVertical(GUI.skin.box, GUILayout.Width(200)); // 顶部按钮 EditorGUILayout.BeginHorizontal(GUILayout.Width(270)); EditorGUILayout.LabelField("预设选择", GUILayout.Width(100)); GUILayout.FlexibleSpace(); if (m_CurrentEditState == EnumSVNToolWindowEditState.EDIT) { if (GUILayout.Button("注销", GUILayout.Width(50))) { PlayerPrefs.DeleteKey(SVN_TOOL_USER_ID_PREF_NAME); m_SvnToolUserID = null; m_FinishReadData = false; } if (GUILayout.Button("新增", GUILayout.Width(50))) { Int32 largeID = 1; // 拿到最大的ID foreach (SVNToolPrefab storedPrefab in storedPrefabs) { largeID = Math.Max(largeID, storedPrefab.ID); } m_SelectedPrefab = new SVNToolPrefab(largeID + 1); storedPrefabs.Add(m_SelectedPrefab); } GUI.enabled = SetIfCurrentActionEnableBySelected(); if (GUILayout.Button("删除", GUILayout.Width(50))) { storedPrefabs.Remove(m_SelectedPrefab); m_SelectedPrefab = null; } GUI.enabled = true; if (GUILayout.Button("保存", GUILayout.Width(50))) { SaveSVNToolPrefabs(); // 刷新状态 InitSyncSVNToolPrefabStatus(); } } else if (m_CurrentEditState == EnumSVNToolWindowEditState.VIEW) { if (GUILayout.Button("开启配置", GUILayout.Width(70))) { m_CurrentEditState = EnumSVNToolWindowEditState.EDIT; if (null != m_SelectedPrefab) { foreach (SVNToolFolder folder in m_SelectedPrefab.contentFolderPath) { folder.openFolder = false; } } } } EditorGUILayout.EndHorizontal(); // 展示预设内容列表 leftScrollPos = EditorGUILayout.BeginScrollView(leftScrollPos, GUI.skin.box); { for (int i = 0; i < storedPrefabs.Count; i++) { SVNToolPrefab currentPrefab = storedPrefabs[i]; if (null != m_SelectedPrefab && m_SelectedPrefab.ID == currentPrefab.ID) { SetOnSelectedBackgroundColor(); } EditorGUILayout.BeginHorizontal(GUI.skin.box); { GUI.backgroundColor = Color.white; Boolean preSelected = currentPrefab.ifSelected; Boolean ifChanged = false; currentPrefab.ifSelected = GUILayout.Toggle(currentPrefab.ifSelected, "同步", GUILayout.Width(40)); if (preSelected != currentPrefab.ifSelected) { // 如果选择了不同的同步规则,则保存 SaveSVNToolPrefabs(); // 刷新已选Data ifChooseDataDirty = true; ifChanged = true; if (currentPrefab.ifSelected) { DoSyncSVNToolPrefabStatus(currentPrefab, false); } } // 预设名 if (m_CurrentEditState == EnumSVNToolWindowEditState.EDIT) { currentPrefab.name = EditorGUILayout.TextField(currentPrefab.name, GUILayout.Width(120)); } else if (m_CurrentEditState == EnumSVNToolWindowEditState.VIEW) { EditorGUILayout.LabelField(currentPrefab.name, GUILayout.Width(120)); } if (ifChanged) { GUI.FocusControl("zero"); } GUILayout.FlexibleSpace(); if (null != currentPrefab.name && currentPrefab.name.Equals("Global") && null != m_SvnToolUserID && !m_SvnToolUserID.Equals("Global") && m_CurrentEditState == EnumSVNToolWindowEditState.EDIT) { if (GUILayout.Button("恢复", GUILayout.Width(40))) { DoRestoreGlobalPrefab(currentPrefab); } } if (GUILayout.Button("查看", GUILayout.Width(40))) { SelectCurrentSVNToolPrefab(currentPrefab); } } EditorGUILayout.EndHorizontal(); SetDefaultSVNToolBackgroundColor(); } } EditorGUILayout.EndScrollView(); EditorGUILayout.EndVertical(); #endregion #region 预设与配置主体 EditorGUILayout.BeginVertical(GUI.skin.box); EditorGUILayout.BeginHorizontal(); GUIStyle redGUISkin = new GUIStyle(); redGUISkin.fontSize = 14; redGUISkin.normal.textColor = Color.red; if (m_CurrentEditState == EnumSVNToolWindowEditState.EDIT) { EditorGUILayout.LabelField("预设配置"); GUILayout.Label(null == m_SelectedPrefab ? "需要左侧选择目标预设" : "拖拽文件/文件夹到下方即可添加", redGUISkin); } else if (m_CurrentEditState == EnumSVNToolWindowEditState.VIEW) { EditorGUILayout.LabelField("配置文件"); GUILayout.FlexibleSpace(); if (CheckIfSelectedPrefabSyncing()) { GUILayout.Label("同步中...", redGUISkin); } GUI.enabled = !CheckIfSelectedPrefabSyncing(); if (GUILayout.Button("刷新同步")) { m_SelectedPrefab.initedFileStatus = false; DoSyncSVNToolPrefabStatus(m_SelectedPrefab); } GUI.enabled = true; } EditorGUILayout.EndHorizontal(); // 设定ScrollView为一个Control对象 GUI.SetNextControlName("text:"); rightScrollPos = EditorGUILayout.BeginScrollView(rightScrollPos, GUI.skin.box); { if (null != m_SelectedPrefab) { // 当前是否在进行同步 if (CheckIfSelectedPrefabSyncing()) { GUILayout.Label("加载中"); } else { #region 显示文件夹 for (int i = 0; i < m_SelectedPrefab.contentFolderPath.Count; i++) { SVNToolFolder folder = m_SelectedPrefab.contentFolderPath[i]; EditorGUILayout.BeginVertical(GUI.skin.box); { EditorGUILayout.BeginHorizontal(); { // 配置状态 if (m_CurrentEditState == EnumSVNToolWindowEditState.EDIT) { EditorGUILayout.LabelField("【文件夹】\t" + folder.name, GUILayout.Width(m_RightPathTextLength)); GUILayout.FlexibleSpace(); if (GUILayout.Button("打开文件夹", GUILayout.Width(100))) { UESvnOperation.GetSvnOperation().ShowFileInExplorer(folder.path); } if (GUILayout.Button("Del", GUILayout.Width(30))) { m_SelectedPrefab.contentFolderPath.Remove(folder); } } else if (m_CurrentEditState == EnumSVNToolWindowEditState.VIEW) { GUI.enabled = folder.contentNeedSyncFiles.Count > 0; if (folder.existNewFileOrFolder) { SetSVNToolFolderSelectedParyColor(); if (GUILayout.Button("存在新建,以及文件夹操作,请点击此处", GUILayout.Width(220))) { UESvnOperation.GetSvnOperation().CommitFile(folder.path); InitSyncSVNToolPrefabStatus(); } SetDefaultSVNToolBackgroundColor(); } // 浏览模式 - 仅展示需同步文件 if (folder.GetSVNToolFileCurrentSyncState() == EnumSVNToolFolderNeedSyncState.SELECTED_ALL) { SetSVNToolFileCanBeCommitColor(); } else if (folder.GetSVNToolFileCurrentSyncState() == EnumSVNToolFolderNeedSyncState.SELECTED_PART) { SetSVNToolFolderSelectedParyColor(); } Int32 selectedFolderFileCount = folder.GetTotalSelectedSVNToolFiles().Count; if (GUILayout.Button(selectedFolderFileCount == 0 ? "全选" : "取消选择", GUILayout.Width(60))) { // 全选 if (selectedFolderFileCount == 0) { foreach (SVNToolFile file in folder.contentNeedSyncFiles) { file.ifSelected = true; } } else { foreach (SVNToolFile file in folder.contentNeedSyncFiles) { file.ifSelected = false; } } ifChooseDataDirty = true; GUI.FocusControl("zero"); // 取消聚焦,防止选中“当前已选择”后不刷新 } EditorGUILayout.LabelField("已选 " + selectedFolderFileCount + "/" + folder.contentNeedSyncFiles.Count, GUILayout.Width(70)); SetDefaultSVNToolBackgroundColor(); folder.openFolder = EditorGUILayout.Foldout(folder.openFolder, folder.name, true); GUI.enabled = true; if (GUILayout.Button("打开文件夹", GUILayout.Width(100))) { UESvnOperation.GetSvnOperation().ShowFileInExplorer(folder.path); } } } EditorGUILayout.EndHorizontal(); if (folder.openFolder) { EditorGUILayout.BeginVertical(); { //折叠开关开启时需要显示的内容 foreach (SVNToolFile file in folder.contentNeedSyncFiles) { EditorGUILayout.BeginHorizontal(GUI.skin.box); { SVNToolWindowWriteFileField(file); } EditorGUILayout.EndHorizontal(); } } EditorGUILayout.EndVertical(); } } EditorGUILayout.EndVertical(); } #endregion #region 显示文件 for (int i = 0; i < m_SelectedPrefab.contentFilePath.Count; i++) { SVNToolFile file = m_SelectedPrefab.contentFilePath[i]; if (m_CurrentEditState == EnumSVNToolWindowEditState.VIEW && !file.CanBeCommit) { continue; } EditorGUILayout.BeginHorizontal(GUI.skin.box); { // 编辑模式 if (m_CurrentEditState == EnumSVNToolWindowEditState.EDIT) { EditorGUILayout.LabelField("【 文 件 】\t" + file.name, GUILayout.Width(m_RightPathTextLength)); GUILayout.FlexibleSpace(); if (GUILayout.Button("Del", GUILayout.Width(30))) { m_SelectedPrefab.contentFilePath.Remove(file); } } // 浏览模式 else if (m_CurrentEditState == EnumSVNToolWindowEditState.VIEW) { SVNToolWindowWriteFileField(file); } } EditorGUILayout.EndHorizontal(); } #endregion } } } EditorGUILayout.EndScrollView(); #region 添加拖拽事件 var rect = GUILayoutUtility.GetLastRect(); //如果鼠标正在拖拽中或拖拽结束时,并且鼠标所在位置在文本输入框内 if ((Event.current.type == EventType.DragUpdated || Event.current.type == EventType.DragPerform) && m_CurrentEditState == EnumSVNToolWindowEditState.EDIT && null != m_SelectedPrefab && rect.Contains(Event.current.mousePosition) ) { //改变鼠标的外表 DragAndDrop.visualMode = DragAndDropVisualMode.Generic; if (Event.current.type == EventType.DragPerform && DragAndDrop.paths != null && DragAndDrop.paths.Length > 0 ) { AddNewSVNToolPath(DragAndDrop.paths); // 保存 // SaveSVNToolPrefabs(); } } #endregion EditorGUILayout.EndVertical(); #endregion EditorGUILayout.EndHorizontal(); #region 结果列表 if (CheckIfSelectedPrefabSyncing()) { EditorGUILayout.BeginVertical(GUI.skin.box); { GUILayout.Label("加载中"); } EditorGUILayout.EndVertical(); } else if (m_CurrentEditState == EnumSVNToolWindowEditState.EDIT) { EditorGUILayout.BeginVertical(GUI.skin.box); { GUILayout.Label("编辑中"); } EditorGUILayout.EndVertical(); } else { // TODO 刷新值修改为 - 当做了选择后进行的刷新 if (ifChooseDataDirty) { RefreshAllSelectedSVNToolFiles(); // 刷新值 } #region 未选择结果列表 GUILayout.Label("配置文件未选择"); hideScrollPos = EditorGUILayout.BeginScrollView(hideScrollPos, GUI.skin.box, GUILayout.MaxHeight(100)); { EditorGUILayout.TextArea(hideChooseResult, GUILayout.Height(100)); } EditorGUILayout.EndScrollView(); #endregion #region 已选结果列表 GUILayout.Label("当前已选择"); showScrollPos = EditorGUILayout.BeginScrollView(showScrollPos, GUI.skin.box, GUILayout.MaxHeight(300)); { EditorGUILayout.TextArea(showChooseResult, GUILayout.Height(300)); } EditorGUILayout.EndScrollView(); #endregion } #endregion #region 操作组 // 控制提交按钮的可控 GUI.enabled = m_CurrentEditState != EnumSVNToolWindowEditState.EDIT && !CheckIfSelectedPrefabSyncing(); EditorGUILayout.BeginHorizontal(); { if (GUILayout.Button("提交")) { StringBuilder stringBuilder = new StringBuilder(); foreach (SVNToolFile file in showResult) { stringBuilder.Append(file.path).Append("*"); } UESvnOperation.GetSvnOperation().CommitFile(stringBuilder.ToString()); InitSyncSVNToolPrefabStatus(); } } EditorGUILayout.EndHorizontal(); GUI.enabled = true; #endregion }