参考帖
https://blog.csdn.net/egostudio/article/details/51074814
https://blog.csdn.net/qq_25174563/article/details/52789451
https://blog.csdn.net/biospc/article/details/75332279
主要调用这个程序
选择第一个可以去看命令
这样可以一键检出时设置unity部分还有 剔除部分 还有提交位置
/**
*Copyright(C) 2019 by #COMPANY#
*All rights reserved.
*FileName: #SCRIPTFULLNAME#
*Author: #AUTHOR#
*Version: #VERSION#
*UnityVersion:#UNITYVERSION#
*Date: #DATE#
*Description:
*History:
*/
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using System.IO;
public class SVNControl
{
const string url = "https://weihaoyu/svn/SVNControl/SVNControl/trunk";
const string command = "TortoiseProc.exe";
static string[] ignores = new string[] { ".sln", ".csproj", "Library", "Temp" };
[MenuItem("Assets/SVN/CheckOut", false, 5)]
public static void SVNCheckOut()
{
//自动生成mate.文件
UnityEditor.EditorSettings.externalVersionControl = "Visible Meta Files";
//设置二进制文件转换为文本
EditorSettings.serializationMode = SerializationMode.ForceText;
ProcessCommand(command, ":checkout /url:" + url + "/ path:" + SVNProjectPath);
AddIgnores();
}
[MenuItem("Assets/SVN/CommitCheck", false, 0)]
public static void SVNCommitCheck()
{
Object[] objs = Selection.objects;
if (objs.Length == 0)
return;
List<string> paths = new List<string>();
for (int i = 0; i < objs.Length; i++)
{
string path = GetObjPath(objs[i]);
paths.Add(path);
}
string commitPath = string.Join("*", paths.ToArray());
ProcessCommand(command, ":commit /path:" + commitPath);
}
[MenuItem("Assets/SVN/Commit", false, 1)]
public static void SVNCommit()
{
ProcessCommand(command, ":commit /path:" + SVNProjectPath);
}
[MenuItem("Assets/SVN/Update", false, 2)]
public static void SVNUpdate()
{
ProcessCommand(command, ":update /path:" + SVNProjectPath + "/closeonend:0");
}
[MenuItem("Assets/SVN/CleanUp", false, 3)]
public static void SVNCleanUp()
{
ProcessCommand(command, ":cleanup /path:" + SVNProjectPath);
}
[MenuItem("Assets/SVN/Log", false, 4)]
public static void SVNLog()
{
ProcessCommand(command, ":log /path:" + SVNProjectPath);
}
public static string GetObjPath(Object obj)
{
string path = AssetDatabase.GetAssetPath(obj);
string dir_path = Path.GetFullPath(SVNProjectPath + path);
return dir_path;
}
public static void AddIgnores()
{
DirectoryInfo root = new DirectoryInfo(SVNProjectPath);
FileSystemInfo[] files = root.GetFileSystemInfos();
foreach (var item in files)
{
foreach (var ignore in ignores)
{
if (item.FullName.Contains(ignore))
{
ProcessCommand(command, ":ignore /path:" + item.FullName);
}
}
}
}
//parentPath
public static string SVNProjectPath
{
get
{
return Application.dataPath.Replace("Assets", "");
}
}
/// <summary>
/// 启动进程应用命令
/// </summary>
/// <param name="command">命令程序</param>
/// <param name="argument">命令程序启动参数</param>
public static void ProcessCommand(string command, string argument)
{
//打开进程
System.Diagnostics.ProcessStartInfo info = new System.Diagnostics.ProcessStartInfo(command);
info.Arguments = "/command"+ argument;
//设置不在新窗口中启动新的进程
info.CreateNoWindow = false;
//不能启动进程时是否向用户显示错误对话框。
info.ErrorDialog = true;
//是否使用操作系统 shell 启动进程。
info.UseShellExecute = true;
if (info.UseShellExecute)
{
//是否由调用程序获取输出信息
info.RedirectStandardOutput = false;
//是否由调用程序获取输入信息
info.RedirectStandardInput = false;
//是否重定向标准错误输出
info.RedirectStandardError = false;
}
else
{
info.RedirectStandardOutput = true;
info.RedirectStandardError = true;
info.RedirectStandardInput = true;
info.StandardOutputEncoding = System.Text.UTF8Encoding.UTF8;
info.StandardErrorEncoding = System.Text.UTF8Encoding.UTF8;
}
System.Diagnostics.Process process;
using (process = System.Diagnostics.Process.Start(info))
{
if (!info.UseShellExecute)
{
Debug.Log(process.StandardOutput);
Debug.Log(process.StandardError);
}
//process.WaitForExit();
}
}
}
这个函数可以在Project面板多选提交
也可以一键提交整个项目
update log界面 CleanUp
不用再切换到文件夹操作了
相当于直接把有用的窗口打开进行操作或者观察结果
但是有个问题 因为文件剔除没办法直接加上去*.sln这样的命令 只能根据路径去添加,
导致
第一次检出时候会像中了毒一样出现多个添加成功提示框,可能这个文件夹越多他提示的越多
可以把这一条粘贴过去
这里激活可以打开设置面板
这样做好处的Assets文件夹内的也能被屏蔽掉
而这样一件查找添加只会在项目目录下 就是这个
反正这里可以一件删除 看个人喜好了
然后我添加了快捷键 把常量命令提取出来
/**
*Copyright(C) 2019 by #COMPANY#
*All rights reserved.
*FileName: #SCRIPTFULLNAME#
*Author: #AUTHOR#
*Version: #VERSION#
*UnityVersion:#UNITYVERSION#
*Date: #DATE#
*Description:
*History:
*/
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using System.IO;
public class SVNConstantDefine
{
//can change with the SVN to use
public const string url = "https://weihaoyu/svn/SVNControl/SVNControl/trunk";
public const string command = "TortoiseProc.exe";
public static readonly string[] ignores = new string[] { ".sln", ".csproj", "Library", "Temp" };
//public const string ignore = "*.sln *.csproj Library Temp";
//btnName
public const string btnPath = "Assets/SVNTools/";
public const string checkOutName = "CheckOut";
public const string commitCheckName = "CommitCheck";
public const string commitAllName = "CommitAll";
public const string updateName = "Update";
public const string cleanUpName = "CleanUp";
public const string logName = "Log";
//btn shortcut
public const string scHead = " %";
public const string scCheckOut="y";
public const string scCommitCheck = "q";
public const string scCommitAll = "w";
public const string scUpdate = "e";
public const string scCleanUp = "r";
public const string scLog= "t";
//mode
public const string versionControlMode = "Visible Meta Files";
//separator
public const string commitSep = "*";
public const string OpePathSep = "Assets";
//commandHead
public const string cdHead = "/command";
//cd=command
public const string cdCheckOut = ":checkout ";
public const string cdCommit = ":commit ";
public const string cdUpdate = ":update ";
public const string cdCleanup = ":cleanup ";
public const string cdLog = ":log ";
public const string cdSettings = ":settings ";
public const string cdIgnore = ":ignore ";
public const string cdPath = "/path:";
public const string cdSameNodePath = "/ path:";
public const string cdUrl = "/url:";
}
public class SVNControl
{
[MenuItem(SVNConstantDefine.btnPath + SVNConstantDefine.checkOutName+ SVNConstantDefine.scHead+ SVNConstantDefine.scCheckOut, false, 36)]
public static void SVNCheckOut()
{
//to produce .mate File
UnityEditor.EditorSettings.externalVersionControl = SVNConstantDefine.versionControlMode;
//set bytes[]file to string file
EditorSettings.serializationMode = SerializationMode.ForceText;
//ProcessCommand(SVNConstantDefine.command, SVNConstantDefine.cdSettings);
ProcessCommand(SVNConstantDefine.command, SVNConstantDefine.cdCheckOut + SVNConstantDefine.cdPath + SVNConstantDefine.url + SVNConstantDefine.cdSameNodePath + SVNProjectPath);
AddIgnores();
}
[MenuItem(SVNConstantDefine.btnPath + SVNConstantDefine.commitCheckName + SVNConstantDefine.scHead + SVNConstantDefine.scCommitCheck, true, 31)]
public static bool SVNCommitCheckJudgement()
{
if (Selection.objects.Length == 0)
return false;
else
return true;
}
[MenuItem(SVNConstantDefine.btnPath + SVNConstantDefine.commitCheckName + SVNConstantDefine.scHead + SVNConstantDefine.scCommitCheck, false, 31)]
public static void SVNCommitCheck()
{
Object[] objs = Selection.objects;
List<string> paths = new List<string>();
for (int i = 0; i < objs.Length; i++)
{
string path = GetObjPath(objs[i]);
paths.Add(path);
}
string commitPath = string.Join(SVNConstantDefine.commitSep, paths.ToArray());
ProcessCommand(SVNConstantDefine.command, SVNConstantDefine.cdCommit + SVNConstantDefine.cdPath + commitPath);
}
[MenuItem(SVNConstantDefine.btnPath + SVNConstantDefine.commitAllName + SVNConstantDefine.scHead + SVNConstantDefine.scCommitAll, false, 32)]
public static void SVNCommit()
{
ProcessCommand(SVNConstantDefine.command, SVNConstantDefine.cdCommit + SVNConstantDefine.cdPath + SVNProjectPath);
}
[MenuItem(SVNConstantDefine.btnPath + SVNConstantDefine.updateName + SVNConstantDefine.scHead + SVNConstantDefine.scUpdate, false, 33)]
public static void SVNUpdate()
{
ProcessCommand(SVNConstantDefine.command, SVNConstantDefine.cdUpdate + SVNConstantDefine.cdPath + SVNProjectPath + "/closeonend:0");
}
[MenuItem(SVNConstantDefine.btnPath + SVNConstantDefine.cleanUpName + SVNConstantDefine.scHead + SVNConstantDefine.scCleanUp, false, 34)]
public static void SVNCleanUp()
{
ProcessCommand(SVNConstantDefine.command, SVNConstantDefine.cdCleanup + SVNConstantDefine.cdPath + SVNProjectPath);
}
[MenuItem(SVNConstantDefine.btnPath + SVNConstantDefine.logName + SVNConstantDefine.scHead + SVNConstantDefine.scLog, false, 35)]
public static void SVNLog()
{
ProcessCommand(SVNConstantDefine.command, SVNConstantDefine.cdLog + SVNConstantDefine.cdPath + SVNProjectPath);
}
public static string GetObjPath(Object obj)
{
string path = AssetDatabase.GetAssetPath(obj);
string dir_path = Path.GetFullPath(SVNProjectPath + path);
return dir_path;
}
public static void AddIgnores()
{
DirectoryInfo root = new DirectoryInfo(SVNProjectPath);
FileSystemInfo[] files = root.GetFileSystemInfos();
foreach (var item in files)
{
foreach (var ignore in SVNConstantDefine.ignores)
{
if (item.FullName.Contains(ignore))
{
ProcessCommand(SVNConstantDefine.command, SVNConstantDefine.cdIgnore + SVNConstantDefine.cdPath + item.FullName);
}
}
}
}
//parentPath
public static string SVNProjectPath
{
get
{
return Application.dataPath.Replace(SVNConstantDefine.OpePathSep, "");
}
}
/// <summary>
/// use .exe
/// </summary>
/// <param name="command">exe</param>
/// <param name="argument">exeCommind</param>
public static void ProcessCommand(string command, string argument)
{
//open exe
System.Diagnostics.ProcessStartInfo info = new System.Diagnostics.ProcessStartInfo(command);
info.Arguments = SVNConstantDefine.cdHead + argument;
//don't use new process to open
info.CreateNoWindow = false;
//if exe open error,can open th error window?
info.ErrorDialog = true;
//can use shell to open exe?
info.UseShellExecute = true;
if (info.UseShellExecute)
{
//can exe to get outPut message?
info.RedirectStandardOutput = false;
//can exe to get inPut message?
info.RedirectStandardInput = false;
//can exe redirect error to outPut?
info.RedirectStandardError = false;
}
else
{
info.RedirectStandardOutput = true;
info.RedirectStandardError = true;
info.RedirectStandardInput = true;
info.StandardOutputEncoding = System.Text.UTF8Encoding.UTF8;
info.StandardErrorEncoding = System.Text.UTF8Encoding.UTF8;
}
System.Diagnostics.Process process;
using (process = System.Diagnostics.Process.Start(info))
{
if (!info.UseShellExecute)
{
Debug.Log(process.StandardOutput);
Debug.Log(process.StandardError);
}
//process.WaitForExit();
}
}
}