不管是我的开发仍是团队开发,养成好的版本管理习惯能够大大提升开发效率。经常使用的版本管理软件通常用SVN或者Git。尽管2者都在用,可是更加偏好SVN一些。安装TortoiseSVN就能够直接将SVN管理软件集成到Windows的Explorer中了。点击鼠标右键就会有SVN的相关菜单,能够很是方便地CheckOut项目以及Commit和Update。html
在使用Unity3D开发时,目前主流的代码编辑器(IDE)都会选择Virsual Studio(VS)。做为宇宙第一强大的IDE,VS天然也有SVN插件——Virsual SVN。安装后就能够在VS里面进行SVN操做了。以下图所示,一个项目若是已经归入了版本管理,在文件前面会有标记。绿色表示同步,黄色表示不一样步,红色则表示冲突。可使用右键进行SVN操做编辑器
可是美中不足是Unity3D里面无法快速地进行SVN操做。通常都是回到Explorer中而后进行提交,不够便捷。查看了Unity Asset Store上的SVN插件,发现大多过于复杂,或者一些操做不符合原有的操做习惯。因此对于以极简高效为原则的我来讲,还不如本身写一个足够用的小工具。svn
在《unity插件开发——一个例子:简单的svn集成》中,已经说明了相关方法是,经过Process.Start方法开启一个TortoiseProc.exe进程,并将参数(点击《TortoiseSVN 操做》查看全部参数)传给TortoiseProc,使之执行相关的命令。工具
using System; using System.Diagnostics; using System.IO; using UnityEditor; using UnityEngine; public class SvnEditor : EditorWindow { #region Setup private const string Svnkey = "key_svnroot"; private const string SvnName = "TortoiseProc.exe"; private static string s_svnpath = SvnName; [MenuItem("SVN/Setup", priority = 0)] public static void Setup() { GetWindow<SvnEditor>(); } #endregion #region Log [MenuItem("Assets/SVN/", priority = 10)] [MenuItem("Assets/SVN/LogAll", priority = 11)] [MenuItem("SVN/", priority = 10)] [MenuItem("SVN/LogAll", priority = 11)] public static void SVNLogAll() { SvnCmdProject(EmSVNCmd.Log); } [MenuItem("Assets/SVN/Log", priority = 1)] public static void SVNLog() { SvnCmdSelect(EmSVNCmd.Log); } #endregion #region Update [MenuItem("Assets/SVN/Update", priority = 2)] public static void SVNUpdate() { SvnCmdSelect(EmSVNCmd.Update); } [MenuItem("Assets/SVN/UpdateAll", priority = 12)] [MenuItem("SVN/UpdateAll", priority = 12)] public static void SVNUpdateAll() { SvnCmdProject(EmSVNCmd.Update); } #endregion #region Commit [MenuItem("Assets/SVN/CommitAll", priority = 13)] [MenuItem("SVN/CommitAll", priority = 13)] public static void SVNCommitAll() { SvnCmdProject(EmSVNCmd.Commit); } [MenuItem("Assets/SVN/Commit", priority = 3)] public static void SVNCommit() { SvnCmdSelect(EmSVNCmd.Commit); } #endregion #region Revert [MenuItem("Assets/SVN/Revert", priority = 4)] public static void SVNRevert() { SvnCmdSelect(EmSVNCmd.Revert); } #endregion #region Clearup [MenuItem("Assets/SVN/ClearUpAll", priority = 5)] [MenuItem("SVN/ClearUpAll", priority = 15)] public static void SVNClearUpAll() { SvnCmdProject(EmSVNCmd.Clearup); } #endregion #region core private static void SvnCmdProject(EmSVNCmd cmd) { var path = Application.dataPath; var project = Directory.GetParent(path); ProcessStart(cmd, project.FullName); } private static void SvnCmdSelect(EmSVNCmd cmd) { var select = Selection.activeObject; var path = AssetDatabase.GetAssetPath(select); ProcessStart(cmd, path); } private static void ProcessStart(EmSVNCmd cmd, string path) { #if UNITY_STANDALONE_WIN||UNITY_EDITOR_WIN try { var info = new ProcessStartInfo(s_svnpath) { Arguments = string.Format("/command:{0} /path:{1} /closeonend:0", cmd.ToString().ToLower(), path) }; Process.Start(info); } catch (Exception) { Setup(); } #endif } #endregion internal void OnEnable() { s_svnpath = EditorPrefs.GetString(Svnkey); } internal void OnGUI() { EditorGUILayout.LabelField("设置SVN"); EditorGUILayout.Space(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("SVN程序", GUILayout.Width(50)); EditorGUILayout.SelectableLabel(s_svnpath, GUILayout.Width(200)); if (GUILayout.Button("select")) { var path = EditorUtility.OpenFilePanel("请选择TortoiseProc.exe存储位置", "", "exe"); if (string.IsNullOrEmpty(path)) return; s_svnpath = path; EditorPrefs.SetString(Svnkey, s_svnpath); } if (GUILayout.Button("Clear")) { s_svnpath = SvnName; EditorPrefs.SetString(Svnkey, s_svnpath); } EditorGUILayout.EndHorizontal(); } private enum EmSVNCmd { Log, Update, Commit, Revert, Clearup } }