Unity扩展SVN命令

可以直接在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

相关推荐

  1. SVN 常用命令

    2024-07-19 12:06:02       47 阅读
  2. svn常用命令

    2024-07-19 12:06:02       23 阅读
  3. SVN常用命令

    2024-07-19 12:06:02       22 阅读
  4. Unity编辑器扩展

    2024-07-19 12:06:02       30 阅读
  5. unity编辑器扩展

    2024-07-19 12:06:02       33 阅读
  6. Unity编辑器扩展

    2024-07-19 12:06:02       24 阅读
  7. Unity编辑器扩展

    2024-07-19 12:06:02       21 阅读
  8. Unity编辑器扩展

    2024-07-19 12:06:02       26 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-19 12:06:02       66 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-19 12:06:02       70 阅读
  3. 在Django里面运行非项目文件

    2024-07-19 12:06:02       57 阅读
  4. Python语言-面向对象

    2024-07-19 12:06:02       68 阅读

热门阅读

  1. C# 4.List

    2024-07-19 12:06:02       18 阅读
  2. 声音处理:分帧与加窗

    2024-07-19 12:06:02       19 阅读
  3. spring 同类方法调用事务失效解决办法

    2024-07-19 12:06:02       13 阅读
  4. 前端面试题日常练-day93 【Less】

    2024-07-19 12:06:02       20 阅读
  5. 【.NET】图形库SkiaSharp

    2024-07-19 12:06:02       20 阅读
  6. OpenCV教程:cv2图像逻辑运算

    2024-07-19 12:06:02       19 阅读
  7. 学习补充008-xx-01 Migrations Overview(迁移概述)

    2024-07-19 12:06:02       19 阅读