SVN小工具可以帮助我们在Unity中完成对SVN常用的更新,提交、恢复都操作,而不需要切换到磁盘目录。
注意安装TortoiseSVN时,务必安装命令行支持项.。

UnitySVN命令菜单集成
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
using UnityEditor; using UnityEngine; public class SVNEditor { [MenuItem("Assets/SVN Update" , false , 19)] public static void UpdateProject() { string[] selections = getSelectionPaths(); if (selections == null ) { UnityEngine.Debug.LogWarning("请先选择目标!"); return; } SVNUtility.Update(selections); } // 选择已选择的目录 private static string[] getSelectionPaths() { string[] selections = Selection.assetGUIDs; if (selections == null || selections.Length <= 0) { return null; } string[] paths = new string[selections.Length]; for (int i = 0; i < selections.Length; i++) { string relativePath = AssetDatabase.GUIDToAssetPath(selections[i]); relativePath = relativePath.Replace("Assets", Application.dataPath); paths[i] = relativePath; } return paths; } [MenuItem("Assets/SVN Commit", false, 19)] public static void CommitProject() { string[] selections = getSelectionPaths(); if (selections == null) { UnityEngine.Debug.LogWarning("请先选择目标!"); return; } SVNUtility.Commit(selections , "记得写日志哦!"); } [MenuItem("Assets/Tortoise SVN/Show Log", false, 31)] public static void ShowLog() { //todo } [MenuItem("Assets/Tortoise SVN/Revert", false, 32)] public static void RevertProject() { string[] selections = getSelectionPaths(); if (selections == null) { UnityEngine.Debug.LogWarning("请先选择目标!"); return; } SVNUtility.Revert(selections); } } |
SVN常用操作封装
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
using System; using System.Diagnostics; public class SVNUtility { private const string TORTOISEPROC_NAME = "TortoiseProc.exe"; // 单一路径/目录更新 public static void Update(string path) { string args = string.Format("/command:update /path:{0}", path); Process p = Process.Start(TORTOISEPROC_NAME, args); p.WaitForExit(); } // 多路径/目录同时更新 public static void Update(string[] paths) { Update(string.Join("*", paths)); } // 单一指定路径提交 public static void Commit(string path, string svnLog) { string args = string.Format("/command:commit /path:{0} /logmsg:{1}", path, svnLog); Process p = Process.Start(TORTOISEPROC_NAME, args); p.WaitForExit(); } // 合并多路径同时提交操作 public static void Commit(string[] paths, string svnLog) { Commit(string.Join("*" , paths) , svnLog); } public static void Revert(string[] paths) { throw new Exception("No Implements!!"); } } |