可以直接在unity里右键文件提交和查看提交记录
顶部菜单栏上回退和更新整个unity工程
SvnForUnity.CS
记得要放在Editor文件夹下
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using UnityEditor;
using UnityEngine;
using Debug = UnityEngine.Debug;public class SvnForUnity
{static string SVN_BASE = Application.dataPath.Replace("/", "\\").Remove(Application.dataPath.Replace("/", "\\").Length - 6, 6);/// <summary>/// 调用cmd命令/// </summary>/// <param name="command">cmd命令</param>/// <param name="argument">命令参数</param>private static void ProcessCommand(string command, string argument){ProcessStartInfo start = new ProcessStartInfo(command){Arguments = argument,CreateNoWindow = false,ErrorDialog = true,UseShellExecute = true//明确传入的执行文件类型};if (start.UseShellExecute){start.RedirectStandardOutput = false;start.RedirectStandardError = false;start.RedirectStandardInput = false;}else{start.RedirectStandardOutput = true;start.RedirectStandardError = true;start.RedirectStandardInput = true;start.StandardOutputEncoding = System.Text.Encoding.UTF8;start.StandardErrorEncoding = System.Text.Encoding.UTF8;}Process p = Process.Start(start);p.WaitForExit();p.Close();}static string MetaFile(string str){return str + ".meta";}static string GetSelectFilePath(){var selectAssets = Selection.GetFiltered<Object>(SelectionMode.Assets);if (selectAssets.Length > 0){string selectionPath = string.Empty;for (int i = 0; i < selectAssets.Length; i++){// Debug.Log(AssetDatabase.GetAssetPath(selectAssets[i]));if (AssetDatabase.GetAssetPath(selectAssets[i]) == "Assets"){return SVN_BASE + "Assets" + "\"";}if (i > 0){selectionPath = selectionPath + "*" + SVN_BASE + AssetDatabase.GetAssetPath(selectAssets[i]).Replace("/", "\\");selectionPath = selectionPath + "*" + SVN_BASE + MetaFile(AssetDatabase.GetAssetPath(selectAssets[i])).Replace("/", "\\");}else{selectionPath = SVN_BASE + AssetDatabase.GetAssetPath(selectAssets[i]).Replace("/", "\\");selectionPath = selectionPath + "*" + SVN_BASE + MetaFile(AssetDatabase.GetAssetPath(selectAssets[i])).Replace("/", "\\");}}return selectionPath + "\"";}return SVN_BASE + "Assets" + "\"";}/// <summary>/// SVN更新/// </summary>[MenuItem("SVN/Update", false, 1)]public static void SvnUpdate(){ProcessCommand("TortoiseProc.exe", "/command:update /path:\"" + SVN_BASE + "Assets" + "\"");}/// <summary>/// SVN提交/// </summary>[MenuItem("Assets/SVN/Commit", false, 2)]public static void SvnCommit(){var selectPath = GetSelectFilePath();ProcessCommand("TortoiseProc.exe", "/command:commit /path:\"" + selectPath);}/// <summary>/// SVN回退/// </summary>[MenuItem("SVN/Revert", false, 3)]public static void SvnRevert(){ProcessCommand("TortoiseProc.exe", "/command:revert /path:\"" + SVN_BASE + "Assets" + "\"");}/// <summary>/// SVN显示信息/// </summary>[MenuItem("Assets/SVN/ShowLog", false, 4)]public static void SvnLog(){var selectPath = GetSelectFilePath();ProcessCommand("TortoiseProc.exe", "/command:log /path:\"" + selectPath);}
}
参考
https://blog.csdn.net/egostudio/article/details/51074814