可以在Unity内一键更新,不用再去文件夹点右键提交更新了
using System;
using System.Diagnostics;
using System.IO;
using UnityEditor;
using UnityEngine;
namespace SVNTool
{
public class SvnEditor : EditorWindow
{
#region Setup
private const string Svnkey = "key_svnroot";
private const string SvnName = "TortoiseProc.exe";
private static string s_svnpath = SvnName;
[MenuItem("SVN/Setup SVN", priority = 0)]
public static void Setup()
{
GetWindow<SvnEditor>();
}
#endregion
#region Log
[MenuItem("Assets/SVN/", priority = 10)]
[MenuItem("Assets/SVN/查看所有提交记录 (Log All) ", priority = 11)]
[MenuItem("SVN/", priority = 10)]
[MenuItem("SVN/查看所有提交记录 (Log All) ", priority = 11)]
public static void SVNLogAll()
{
SvnCmdProject(EmSVNCmd.Log);
}
[MenuItem("Assets/SVN/查看提交记录 (Log) ", priority = 1)]
public static void SVNLog()
{
SvnCmdSelect(EmSVNCmd.Log);
}
#endregion
#region Update
[MenuItem("Assets/SVN/更新 (Update) ", priority = 2)]
public static void SVNUpdate()
{
SvnCmdSelect(EmSVNCmd.Update);
}
[MenuItem("Assets/SVN/更新全部 (Update All) ", priority = 12)]
[MenuItem("SVN/更新全部 (Update All) ", priority = 12)]
public static void SVNUpdateAll()
{
SvnCmdProject(EmSVNCmd.Update);
}
#endregion
#region Commit
[MenuItem("Assets/SVN/提交全部 (Commit All) ", priority = 13)]
[MenuItem("SVN/提交全部 (Commit All) ", priority = 13)]
public static void SVNCommitAll()
{
SvnCmdProject(EmSVNCmd.Commit);
}
[MenuItem("Assets/SVN/提交 (Commit) ", priority = 3)]
public static void SVNCommit()
{
SvnCmdSelect(EmSVNCmd.Commit);
}
#endregion
#region Revert
[MenuItem("Assets/SVN/还原 (Revert) ", priority = 4)]
public static void SVNRevert()
{
SvnCmdSelect(EmSVNCmd.Revert);
}
#endregion
#region Clearup
[MenuItem("Assets/SVN/ClearUpAll", priority = 5)]
[MenuItem("SVN/ClearUpAll", priority = 15)]
public static void SVNClearUpAll()
{
SvnCmdProject(EmSVNCmd.Clearup);
}
#endregion
#region core
private static void SvnCmdProject(EmSVNCmd cmd)
{
var path = Application.dataPath;
var project = Directory.GetParent(path);
ProcessStart(cmd, project.FullName);
}
private static void SvnCmdSelect(EmSVNCmd cmd)
{
var select = Selection.activeObject;
var path = AssetDatabase.GetAssetPath(select);
ProcessStart(cmd, path);
}
private static void ProcessStart(EmSVNCmd cmd, string path)
{
#if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN
try
{
var info = new ProcessStartInfo(s_svnpath)
{
Arguments = string.Format("/command:{0} /path:{1} /closeonend:0", cmd.ToString().ToLower(), path)
};
Process.Start(info);
}
catch (Exception)
{
Setup();
}
#endif
}
#endregion
internal void OnEnable()
{
s_svnpath = EditorPrefs.GetString(Svnkey);
}
internal void OnGUI()
{
EditorGUILayout.LabelField("设置SVN");
EditorGUILayout.Space();
EditorGUILayout.BeginHorizontal();
EditorGUILayout.LabelField("SVN程序", GUILayout.Width(50));
EditorGUILayout.SelectableLabel(s_svnpath, GUILayout.Width(200));
if (GUILayout.Button("select"))
{
var path = EditorUtility.OpenFilePanel("请选择TortoiseProc.exe存储位置", "", "exe");
if (string.IsNullOrEmpty(path))
return;
s_svnpath = path;
EditorPrefs.SetString(Svnkey, s_svnpath);
}
if (GUILayout.Button("Clear"))
{
s_svnpath = SvnName;
EditorPrefs.SetString(Svnkey, s_svnpath);
}
EditorGUILayout.EndHorizontal();
}
private enum EmSVNCmd
{
Log,
Update,
Commit,
Revert,
Clearup
}
}
}
网友评论