#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 defineSymbols = new List( PlayerSettings.GetScriptingDefineSymbols(NamedBuildTarget.Standalone).Split(";") ); List removeSymbols = new List(); 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(), 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(), 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(), 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("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 defineSymbols = new List( 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