Unity_SVNTool

找了个Unity下调用常用svn命令的脚本,很方便,免得经常切出去了

把脚本放在Editor文件夹下就好。 效果如下图

svn

下面是代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
using System;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
public static class SVNTool
{
/// <summary>
/// SVN更新指定的路径
/// 路径示例:Assets/1.png
/// </summary>
/// <param name="assetPaths"></param>
public static void UpdateAtPath(string assetPath)
{
List<string> assetPaths = new List<string>();
assetPaths.Add(assetPath);
UpdateAtPaths(assetPaths);
}
/// <summary>
/// SVN更新指定的路径
/// 路径示例:Assets/1.png
/// </summary>
/// <param name="assetPaths"></param>
public static void UpdateAtPaths(List<string> assetPaths)
{
if (assetPaths.Count == 0)
{
return;
}
string arg = "/command:update /closeonend:0 /path:\"";
for (int i = 0; i < assetPaths.Count; i++)
{
var assetPath = assetPaths[i];
if (i != 0)
{
arg += "*";
}
arg += assetPath;
}
arg += "\"";
SvnCommandRun(arg);
}
/// <summary>
/// SVN提交指定的路径
/// 路径示例:Assets/1.png
/// </summary>
/// <param name="assetPaths"></param>
public static void CommitAtPaths(List<string> assetPaths, string logmsg = null)
{
if (assetPaths.Count == 0)
{
return;
}
string arg = "/command:commit /closeonend:0 /path:\"";
for (int i = 0; i < assetPaths.Count; i++)
{
var assetPath = assetPaths[i];
if (i != 0)
{
arg += "*";
}
arg += assetPath;
}
arg += "\"";
if (!string.IsNullOrEmpty(logmsg))
{
arg += " /logmsg:\"" + logmsg + "\"";
}
SvnCommandRun(arg);
}
[MenuItem("Assets/SVN Tool/SVN 更新")]
private static void SvnToolUpdate()
{
List<string> assetPaths = GetSelectionAssetPaths();
UpdateAtPaths(assetPaths);
}
[MenuItem("Assets/SVN Tool/SVN 提交...")]
private static void SvnToolCommit()
{
List<string> assetPaths = GetSelectionAssetPaths();
CommitAtPaths(assetPaths);
}
[MenuItem("Assets/SVN Tool/显示日志")]
private static void SvnToolLog()
{
List<string> assetPaths = GetSelectionAssetPaths();
if (assetPaths.Count == 0)
{
return;
}
// 显示日志,只能对单一资产
string arg = "/command:log /closeonend:0 /path:\"";
arg += assetPaths[0];
arg += "\"";
SvnCommandRun(arg);
}
[MenuItem("Assets/SVN Tool/全部更新", false, 1100)]
private static void SvnToolAllUpdate()
{
// 往上一级,包括数据配置文件
string arg = "/command:update /closeonend:0 /path:\"";
arg += ".";
arg += "\"";
SvnCommandRun(arg);
}
[MenuItem("Assets/SVN Tool/全部日志", false, 1101)]
private static void SvnToolAllLog()
{
// 往上一级,包括数据配置文件
string arg = "/command:log /closeonend:0 /path:\"";
arg += ".";
arg += "\"";
SvnCommandRun(arg);
}
/// <summary>
/// SVN命令运行
/// </summary>
/// <param name="arg"></param>
private static void SvnCommandRun(string arg)
{
string workDirectory = Application.dataPath.Remove(Application.dataPath.LastIndexOf("/Assets", StringComparison.Ordinal));
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo
{
UseShellExecute = false,
CreateNoWindow = true,
FileName = "TortoiseProc",
Arguments = arg,
WorkingDirectory = workDirectory
});
}
/// <summary>
/// 得到选中资产路径列表
/// </summary>
/// <returns></returns>
public static List<string> GetSelectionAssetPaths()
{
List<string> assetPaths = new List<string>();
// 这个接口才能取到两列模式时候的文件夹
foreach (var guid in Selection.assetGUIDs)
{
if (string.IsNullOrEmpty(guid))
{
continue;
}
string path = AssetDatabase.GUIDToAssetPath(guid);
if (!string.IsNullOrEmpty(path))
{
assetPaths.Add(path);
}
}
return assetPaths;
}
}

坚持原创技术分享,您的支持将鼓励我继续创作!