Unity内嵌SVN自动化检出提交

参考帖
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
主要调用这个程序

image.png

image.png

image.png

选择第一个可以去看命令
这样可以一键检出时设置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();
        }
    }
}
image.png

这个函数可以在Project面板多选提交


image.png

也可以一键提交整个项目
update log界面 CleanUp
不用再切换到文件夹操作了
相当于直接把有用的窗口打开进行操作或者观察结果
但是有个问题 因为文件剔除没办法直接加上去*.sln这样的命令 只能根据路径去添加,
导致


image.png

第一次检出时候会像中了毒一样出现多个添加成功提示框,可能这个文件夹越多他提示的越多
image.png

可以把这一条粘贴过去
image.png

这里激活可以打开设置面板


image.png

这样做好处的Assets文件夹内的也能被屏蔽掉
而这样一件查找添加只会在项目目录下 就是这个
image.png

反正这里可以一件删除 看个人喜好了
image.png

然后我添加了快捷键 把常量命令提取出来

/**
 *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();
        }
    }
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 211,948评论 6 492
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 90,371评论 3 385
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 157,490评论 0 348
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 56,521评论 1 284
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 65,627评论 6 386
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 49,842评论 1 290
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 38,997评论 3 408
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 37,741评论 0 268
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,203评论 1 303
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 36,534评论 2 327
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 38,673评论 1 341
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 34,339评论 4 330
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 39,955评论 3 313
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,770评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,000评论 1 266
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 46,394评论 2 360
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 43,562评论 2 349

推荐阅读更多精彩内容