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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
|
#if UNITY_EDITOR
using System;
using System.Collections.Generic;
using System.IO;
using UnityEditor;
using UnityEditor.Build;
using UnityEditor.ProjectWindowCallback;
using UnityEngine;
using Object = UnityEngine.Object;
namespace Mountools.Tools.Editor
{
public static class MenuItems
{
#region 基础
#if MT_L_CHINESE
[MenuItem("Mountools/语言/英文")]
#endif
#if MT_L_ENGLISH
[MenuItem("Mountools/Language/English")]
#endif
public static void ChangeLanguageToEnglish()
{
ChangeLanguageTo("ENGLISH");
}
#if MT_L_CHINESE
[MenuItem("Mountools/语言/中文")]
#endif
#if MT_L_ENGLISH
[MenuItem("Mountools/Language/Chinese")]
#endif
public static void ChangeLanguageToChinese()
{
ChangeLanguageTo("CHINESE");
}
public static void ChangeLanguageTo(string language)
{
List<string> defineSymbols =
new List<string>(
PlayerSettings.GetScriptingDefineSymbols(NamedBuildTarget.Standalone).Split(";")
);
List<string> removeSymbols = new List<string>();
foreach (var symbol in defineSymbols)
{
if (symbol.Contains("MT_L_"))
{
removeSymbols.Add(symbol);
}
}
foreach (var removeSymbol in removeSymbols)
{
defineSymbols.Remove(removeSymbol);
}
defineSymbols.Add("MT_L_" + language);
PlayerSettings.SetScriptingDefineSymbols(NamedBuildTarget.Standalone, defineSymbols.ToArray());
}
#endregion
#region 脚本模板
#if MT_L_CHINESE
[MenuItem("Assets/Create/脚本模板/编辑器脚本", false, 79)]
#endif
#if MT_L_ENGLISH
[MenuItem("Assets/Create/C# Templates/Editor Script", false, 79)]
#endif
public static void CreateNewEditorScript()
{
ProjectWindowUtil.StartNameEditingIfProjectWindowExists(0,
ScriptableObject.CreateInstance<CreateEditorScriptAssetAction>(),
GetSelectedPathOrFallback() + "/MonoBehaviourEditor.cs",
EditorGUIUtility.FindTexture("d_cs Script Icon"),
"EditorScript");
}
#if MT_L_CHINESE
[MenuItem("Assets/Create/脚本模板/编辑器窗口", false, 79)]
#endif
#if MT_L_ENGLISH
[MenuItem("Assets/Create/C# Templates/Editor Window", false, 79)]
#endif
public static void CreateEditorWindowScript()
{
ProjectWindowUtil.StartNameEditingIfProjectWindowExists(0,
ScriptableObject.CreateInstance<CreateScriptableObjectScriptAssetAction>(),
GetSelectedPathOrFallback() + "/NewEditorWindow.cs",
EditorGUIUtility.FindTexture("d_cs Script Icon"),
"EditorWindow");
}
#if MT_L_CHINESE
[MenuItem("Assets/Create/脚本模板/可序列化对象", false, 79)]
#endif
#if MT_L_ENGLISH
[MenuItem("Assets/Create/C# Templates/Scriptable Object", false, 80)]
#endif
public static void CreateNewScriptableObjectScript()
{
ProjectWindowUtil.StartNameEditingIfProjectWindowExists(0,
ScriptableObject.CreateInstance<CreateScriptableObjectScriptAssetAction>(),
GetSelectedPathOrFallback() + "/NewScriptableObjectScript.cs",
EditorGUIUtility.FindTexture("d_cs Script Icon"),
"ScriptableObject");
}
private static string GetSelectedPathOrFallback()
{
string path = "Assets";
foreach (Object obj in Selection.GetFiltered(typeof(Object), SelectionMode.Assets))
{
path = AssetDatabase.GetAssetPath(obj);
if (!string.IsNullOrEmpty(path) && File.Exists(path))
{
path = Path.GetDirectoryName(path);
break;
}
}
return path;
}
#endregion
#region 工具
#if MT_L_CHINESE
[MenuItem("Mountools/工具/游戏内自由相机 #G")]
#endif
#if MT_L_ENGLISH
[MenuItem("Mountools/Tools/In-Game Free Camera #G")]
#endif
private static void FreeCameraEnter()
{
ToolFreeCamera.FreeCameraEnter();
}
#if MT_L_CHINESE
[MenuItem("Mountools/工具/方法调用器")]
#endif
#if MT_L_ENGLISH
[MenuItem("Mountools/Tools/Object Method Invoker")]
#endif
public static void ObjectMethodInvoker()
{
ToolObjectMethodInvoker invoker = EditorWindow.GetWindow<ToolObjectMethodInvoker>("Object Method Invoker");
#if MT_L_CHINESE
var strMethodInvoker = "方法调用器";
#endif
#if MT_L_ENGLISH
var strMethodInvoker = "Method Invoker";
#endif
invoker.titleContent = new GUIContent(strMethodInvoker);
}
#if MT_L_CHINESE
[MenuItem("Mountools/工具/添加 Visual Scripting 适配")]
#endif
#if MT_L_ENGLISH
[MenuItem("Mountools/Tools/Add Visual Scripting Support")]
#endif
public static void SupportVisualScripting()
{
List<string> defineSymbols =
new List<string>(
PlayerSettings.GetScriptingDefineSymbols(NamedBuildTarget.Standalone).Split(";")
);
foreach (var symbol in defineSymbols)
{
if (symbol.Contains("MT_TOOL_VS"))
{
return;
}
}
defineSymbols.Add("MT_TOOL_VS");
PlayerSettings.SetScriptingDefineSymbols(NamedBuildTarget.Standalone, defineSymbols.ToArray());
}
#endregion
}
public class CreateEditorScriptAssetAction : EndNameEditAction
{
public override void Action(int instanceId, string pathName, string resourceFile)
{
var file = new FileInfo(new DirectoryInfo(Application.dataPath).Parent + "/"
+ pathName.Replace(".cs", "Editor.cs"));
var name = file.Name.Replace("Editor.cs", "");
var templateText = MountoolsEditor.ScriptTemplate(resourceFile)
.Replace("[NameVariable]", name.Substring(0, 1).ToLower() + name.Substring(1))
.Replace("[NameSpace]", MountoolsEditor.GetNamespaceByPath(pathName))
.Replace("[Name]", name)
.Replace("[Author]", Application.companyName)
.Replace("[Date]", DateTime.Today.ToString("yyyy / MM / dd - HH:mm:ss"));
File.WriteAllText(file.FullName, templateText);
AssetDatabase.Refresh();
}
}
public class CreateEditorWindowAssetAction : EndNameEditAction
{
public override void Action(int instanceId, string pathName, string resourceFile)
{
var file = new FileInfo(new DirectoryInfo(Application.dataPath).Parent + "/"
+ pathName);
var templateText = MountoolsEditor.ScriptTemplate(resourceFile)
.Replace("[NameSpace]", MountoolsEditor.GetNamespaceByPath(pathName))
.Replace("[Name]", file.Name.Replace(".cs", ""))
.Replace("[Author]", Application.companyName)
.Replace("[Date]", DateTime.Today.ToString("yyyy / MM / dd - HH:mm:ss"));
File.WriteAllText(file.FullName, templateText);
AssetDatabase.Refresh();
}
}
public class CreateScriptableObjectScriptAssetAction : EndNameEditAction
{
public override void Action(int instanceId, string pathName, string resourceFile)
{
var file = new FileInfo(new DirectoryInfo(Application.dataPath).Parent + "/"
+ pathName);
var templateText = MountoolsEditor.ScriptTemplate(resourceFile)
.Replace("[NameSpace]", MountoolsEditor.GetNamespaceByPath(pathName))
.Replace("[Name]", file.Name.Replace(".cs", ""))
.Replace("[Author]", Application.companyName)
.Replace("[Date]", DateTime.Today.ToString("yyyy / MM / dd - HH:mm:ss"));
File.WriteAllText(file.FullName, templateText);
AssetDatabase.Refresh();
}
}
}
#endif
|