• 大小: 2KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-06-05
  • 语言: 其他
  • 标签: Unity  Svn  工具  源码  

资源简介

在Unity中快速使用svn的小工具。 从此不用只是在打开文件夹后去做svn操作,而可以在unity环境下点击文件右键直接操作svn。

资源截图

代码片段和文件信息

using UnityEngine;
using UnityEditor;
using System.Collections;

/// 
/// Unity Svn 工具
/// 参考: http://www.cnblogs.com/me115/archive/2011/05/31/2064047.html 
/// 官网:http://tortoisesvn.net/docs/release/TortoiseSVN_zh_CN/tsvn-automation.html 
/// 

public class MiniSvn
{
    #region - SVN -

    [MenuItem(“Assets/SVN/showlog“)]
    static void ExternalSvnShowLog()
    {
        SvnShowLog(GetCurProjectObjPath());
    }
    [MenuItem(“Assets/SVN/add“)]
    static void ExternalSvnAdd()
    {
        SvnAdd(GetCurProjectObjPath());
    }
    [MenuItem(“Assets/SVN/commit“)]
    static void ExternalSvnCommit()
    {
        SvnCommit(GetCurProjectObjPath());
    }
    [MenuItem(“Assets/SVN/update“)]
    static void ExternalSvnUpdate()
    {
        SvnUpdate(GetCurProjectObjPath());
    }

    static string GetCurProjectObjPath()
    {
        if (null == Selection.objects || Selection.objects.Length != 1) return string.Empty;

        string path = AssetDatabase.GetAssetPath(Selection.objects[0].GetInstanceID());
        if (!string.IsNullOrEmpty(path))
        {
            path = System.IO.Path.GetFullPath(path);
        }
        return path;
    }

    #endregion

    private const string SVN_EXE_PATH = “C:\\Program Files\\TortoiseSVN\\bin\\TortoiseProc.exe“;

    public static void SvnShowLog(string filePath)
    {
        string args = “/command:log /path:“ + filePath + “ /closeonend:0“;
        // 快捷方式
        System.Diagnostics.Process.Start(SVN_EXE_PATH args);
        // cmd方式
        //string[] cmdArray = new string[]
        //{
        //    “cd C:\\Program Files\\TortoiseSVN\\bin\\“
        //    “TortoiseProc.exe“ + “ “ + args
        //};
        //RunCmd(cmdArray);
    }

    public static void SvnAdd(string filePath)
    {
        string addRes = filePath;
        if (System.IO.File.Exists(filePath))
        {
            addRes = System.IO.Path.GetDirectoryName(filePath);
        }
        string args = “/command:add /path:“ + addRes + “ /closeonend:0“;
        System.Diagnostics.Process.Start(SVN_EXE_PATH args);
    }

    public static void SvnCommit(string filePath)
    {
        string args = “/command:commit /path:“ + filePath + “ /logmsg:res: ui“ + “ /closeonend:0“;
        System.Diagnostics.Process.Start(SVN_EXE_PATH args);
    }

    public static void SvnUpdate(string filePath)
    {
        string args = “/command:update /path:“ + filePath + “ /closeonend:0“;
        System.Diagnostics.Process.Start(SVN_EXE_PATH args);
    }

    private static void RunCmd(string[] cmds)
    {
        System.Diagnostics.Process proc = new System.Diagnostics.Process();
        proc.StartInfo.CreateNoWindow = true;
        proc.StartInfo.FileName = “cmd.exe“;
        proc.StartInfo.UseShellExecute = false;
        proc.StartInfo.RedirectStandardError = true;
        proc.StartInfo.RedirectStandardInput

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2015-07-07 10:39  Unity Svn 工具\
     文件        3287  2015-07-07 10:37  Unity Svn 工具\MiniSvn.cs
     文件         178  2015-07-07 10:07  Unity Svn 工具\MiniSvn.cs.meta

评论

共有 条评论