From 4c8534b7b36e77a7c7c47a10b163695686391739 Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Sun, 1 Feb 2026 10:13:56 +0800 Subject: 整合素材 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/Mountools/Tools/Editor.meta | 8 + Assets/Mountools/Tools/Editor/LabelAttribute.cs | 14 + .../Mountools/Tools/Editor/LabelAttribute.cs.meta | 3 + .../Mountools/Tools/Editor/LabelAttributeDrawer.cs | 20 + .../Tools/Editor/LabelAttributeDrawer.cs.meta | 3 + Assets/Mountools/Tools/Editor/MenuItems.cs | 246 ++++++++++ Assets/Mountools/Tools/Editor/MenuItems.cs.meta | 11 + .../Tools/Editor/ToolInspectorBookmarkEditor.cs | 50 +++ .../Editor/ToolInspectorBookmarkEditor.cs.meta | 11 + Assets/Mountools/Tools/Mountools.Tools.asmdef | 16 + Assets/Mountools/Tools/Mountools.Tools.asmdef.meta | 7 + Assets/Mountools/Tools/MountoolsEditor.cs | 296 ++++++++++++ Assets/Mountools/Tools/MountoolsEditor.cs.meta | 11 + Assets/Mountools/Tools/MountoolsLanguage.cs | 15 + Assets/Mountools/Tools/MountoolsLanguage.cs.meta | 3 + Assets/Mountools/Tools/MountoolsMath.cs | 58 +++ Assets/Mountools/Tools/MountoolsMath.cs.meta | 11 + Assets/Mountools/Tools/MountoolsShortcut.cs | 56 +++ Assets/Mountools/Tools/MountoolsShortcut.cs.meta | 3 + Assets/Mountools/Tools/ToolFreeCamera.cs | 167 +++++++ Assets/Mountools/Tools/ToolFreeCamera.cs.meta | 11 + Assets/Mountools/Tools/ToolInspectorBookmark.cs | 22 + .../Mountools/Tools/ToolInspectorBookmark.cs.meta | 11 + Assets/Mountools/Tools/ToolObjectMethodInvoker.cs | 500 +++++++++++++++++++++ .../Tools/ToolObjectMethodInvoker.cs.meta | 11 + 25 files changed, 1564 insertions(+) create mode 100755 Assets/Mountools/Tools/Editor.meta create mode 100755 Assets/Mountools/Tools/Editor/LabelAttribute.cs create mode 100755 Assets/Mountools/Tools/Editor/LabelAttribute.cs.meta create mode 100755 Assets/Mountools/Tools/Editor/LabelAttributeDrawer.cs create mode 100755 Assets/Mountools/Tools/Editor/LabelAttributeDrawer.cs.meta create mode 100755 Assets/Mountools/Tools/Editor/MenuItems.cs create mode 100755 Assets/Mountools/Tools/Editor/MenuItems.cs.meta create mode 100755 Assets/Mountools/Tools/Editor/ToolInspectorBookmarkEditor.cs create mode 100755 Assets/Mountools/Tools/Editor/ToolInspectorBookmarkEditor.cs.meta create mode 100755 Assets/Mountools/Tools/Mountools.Tools.asmdef create mode 100755 Assets/Mountools/Tools/Mountools.Tools.asmdef.meta create mode 100755 Assets/Mountools/Tools/MountoolsEditor.cs create mode 100755 Assets/Mountools/Tools/MountoolsEditor.cs.meta create mode 100755 Assets/Mountools/Tools/MountoolsLanguage.cs create mode 100755 Assets/Mountools/Tools/MountoolsLanguage.cs.meta create mode 100755 Assets/Mountools/Tools/MountoolsMath.cs create mode 100755 Assets/Mountools/Tools/MountoolsMath.cs.meta create mode 100755 Assets/Mountools/Tools/MountoolsShortcut.cs create mode 100755 Assets/Mountools/Tools/MountoolsShortcut.cs.meta create mode 100755 Assets/Mountools/Tools/ToolFreeCamera.cs create mode 100755 Assets/Mountools/Tools/ToolFreeCamera.cs.meta create mode 100755 Assets/Mountools/Tools/ToolInspectorBookmark.cs create mode 100755 Assets/Mountools/Tools/ToolInspectorBookmark.cs.meta create mode 100755 Assets/Mountools/Tools/ToolObjectMethodInvoker.cs create mode 100755 Assets/Mountools/Tools/ToolObjectMethodInvoker.cs.meta (limited to 'Assets/Mountools/Tools') diff --git a/Assets/Mountools/Tools/Editor.meta b/Assets/Mountools/Tools/Editor.meta new file mode 100755 index 0000000..cc64abf --- /dev/null +++ b/Assets/Mountools/Tools/Editor.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: ac8cd71a8e4f37f4f965fe4e13cc7b44 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Mountools/Tools/Editor/LabelAttribute.cs b/Assets/Mountools/Tools/Editor/LabelAttribute.cs new file mode 100755 index 0000000..51302df --- /dev/null +++ b/Assets/Mountools/Tools/Editor/LabelAttribute.cs @@ -0,0 +1,14 @@ +using UnityEngine; + +namespace Mountools.Tools.Editor +{ + public class LabelAttribute : PropertyAttribute + { + public string Name { get; } + + public LabelAttribute(string name) + { + Name = name; + } + } +} \ No newline at end of file diff --git a/Assets/Mountools/Tools/Editor/LabelAttribute.cs.meta b/Assets/Mountools/Tools/Editor/LabelAttribute.cs.meta new file mode 100755 index 0000000..ac6aa51 --- /dev/null +++ b/Assets/Mountools/Tools/Editor/LabelAttribute.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 9eb0e6417a53467c99d5d28aacd1bde0 +timeCreated: 1718475094 \ No newline at end of file diff --git a/Assets/Mountools/Tools/Editor/LabelAttributeDrawer.cs b/Assets/Mountools/Tools/Editor/LabelAttributeDrawer.cs new file mode 100755 index 0000000..7a11334 --- /dev/null +++ b/Assets/Mountools/Tools/Editor/LabelAttributeDrawer.cs @@ -0,0 +1,20 @@ +#if UNITY_EDITOR +using UnityEditor; +using UnityEngine; + +namespace Mountools.Tools.Editor +{ + [CustomPropertyDrawer(typeof(LabelAttribute))] + public class LabelAttributeDrawer : PropertyDrawer + { + public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) + { + if (attribute is LabelAttribute attr && attr.Name.Length > 0) + { + label.text = attr.Name; + } + EditorGUI.PropertyField(position, property, label); + } + } +} +#endif \ No newline at end of file diff --git a/Assets/Mountools/Tools/Editor/LabelAttributeDrawer.cs.meta b/Assets/Mountools/Tools/Editor/LabelAttributeDrawer.cs.meta new file mode 100755 index 0000000..cf8ff29 --- /dev/null +++ b/Assets/Mountools/Tools/Editor/LabelAttributeDrawer.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 192a1578461144b39d96a190c9d904ff +timeCreated: 1718475094 \ No newline at end of file diff --git a/Assets/Mountools/Tools/Editor/MenuItems.cs b/Assets/Mountools/Tools/Editor/MenuItems.cs new file mode 100755 index 0000000..f00eb4f --- /dev/null +++ b/Assets/Mountools/Tools/Editor/MenuItems.cs @@ -0,0 +1,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 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 diff --git a/Assets/Mountools/Tools/Editor/MenuItems.cs.meta b/Assets/Mountools/Tools/Editor/MenuItems.cs.meta new file mode 100755 index 0000000..31bcef4 --- /dev/null +++ b/Assets/Mountools/Tools/Editor/MenuItems.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 1f79ee2a4c458864d90468256a109524 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Mountools/Tools/Editor/ToolInspectorBookmarkEditor.cs b/Assets/Mountools/Tools/Editor/ToolInspectorBookmarkEditor.cs new file mode 100755 index 0000000..1fbd688 --- /dev/null +++ b/Assets/Mountools/Tools/Editor/ToolInspectorBookmarkEditor.cs @@ -0,0 +1,50 @@ +#if UNITY_EDITOR +using UnityEditor; +using UnityEngine; + +namespace Mountools.Tools.Editor +{ + [CustomEditor(typeof(ToolInspectorBookmark))] + public class ToolInspectorBookmarkEditor : UnityEditor.Editor + { + /* + * Editor page created by Mountools + * Author : CatilGrass + * Date : 2024 / 10 / 21 - 00:00:00 + */ + + public ToolInspectorBookmark bookmark; + + private void OnEnable() + { + bookmark = (ToolInspectorBookmark) target; + } + + private void DrawToolInspectorBookmarkEditor() + { + EditorGUILayout.BeginVertical(); + { + var lineCount = bookmark.bookmarkContent.Split("\n").Length; + bookmark.bookmarkContent = EditorGUILayout.TextArea(bookmark.bookmarkContent + , GUILayout.Height(lineCount * 15 + 5)); + } + EditorGUILayout.EndVertical(); + } + + public override void OnInspectorGUI() + { + Undo.RecordObject(bookmark, "Edit ToolInspectorBookmark"); + EditorGUI.BeginChangeCheck(); + + // DrawDefaultInspector(); + DrawToolInspectorBookmarkEditor(); + + if (EditorGUI.EndChangeCheck()) + { + EditorUtility.SetDirty(bookmark); + Undo.FlushUndoRecordObjects(); + } + } + } +} +#endif \ No newline at end of file diff --git a/Assets/Mountools/Tools/Editor/ToolInspectorBookmarkEditor.cs.meta b/Assets/Mountools/Tools/Editor/ToolInspectorBookmarkEditor.cs.meta new file mode 100755 index 0000000..306db22 --- /dev/null +++ b/Assets/Mountools/Tools/Editor/ToolInspectorBookmarkEditor.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 09cf465d97bd97541a7b735333d39c8c +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Mountools/Tools/Mountools.Tools.asmdef b/Assets/Mountools/Tools/Mountools.Tools.asmdef new file mode 100755 index 0000000..adbaf5d --- /dev/null +++ b/Assets/Mountools/Tools/Mountools.Tools.asmdef @@ -0,0 +1,16 @@ +{ + "name": "Mountools.Tools", + "rootNamespace": "", + "references": [], + "includePlatforms": [], + "excludePlatforms": [], + "allowUnsafeCode": false, + "overrideReferences": false, + "precompiledReferences": [], + "autoReferenced": true, + "defineConstraints": [ + "MOUNTOOLS" + ], + "versionDefines": [], + "noEngineReferences": false +} \ No newline at end of file diff --git a/Assets/Mountools/Tools/Mountools.Tools.asmdef.meta b/Assets/Mountools/Tools/Mountools.Tools.asmdef.meta new file mode 100755 index 0000000..db6b539 --- /dev/null +++ b/Assets/Mountools/Tools/Mountools.Tools.asmdef.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: badcfa392cfb92b438720b19250e4fee +AssemblyDefinitionImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Mountools/Tools/MountoolsEditor.cs b/Assets/Mountools/Tools/MountoolsEditor.cs new file mode 100755 index 0000000..7551615 --- /dev/null +++ b/Assets/Mountools/Tools/MountoolsEditor.cs @@ -0,0 +1,296 @@ +using System; +using UnityEngine; +using Object = UnityEngine.Object; + +#if UNITY_EDITOR +using UnityEditor; +#endif + +namespace Mountools.Tools +{ + // Mountools 编辑器相关 + public static class MountoolsEditor + { + public static string rootPath = "Assets/Mountools"; + + // 设置已修改 (任何时候) + public static void SetDirty(Object obj) + { +#if UNITY_EDITOR + if (Application.isPlaying) + { + EditorUtility.SetDirty(obj); + } +#endif + } + + // 创建游戏对象 + public static GameObject CreateEmptyGameObject(string name = "New Game Object", bool moveToView = true) + { + var obj = new GameObject(name); + +#if UNITY_EDITOR + if (! Application.isPlaying) + { + if (moveToView) + SceneView.lastActiveSceneView.MoveToView(obj.transform); + + obj.transform.parent = Selection.gameObjects.Length > 0 ? Selection.gameObjects[0].transform : null; + SetDirty(obj); + Undo.RegisterCreatedObjectUndo(obj, $"Create GameObject \"{name}\""); + } +#endif + + return obj; + } + + // 创建带组件的游戏对象 + public static T CreateGameObject (string name = "", bool moveToView = true) where T : Component + { + var obj = new GameObject(name == "" ? typeof(T).Name : name); + var component = obj.AddComponent(); + +#if UNITY_EDITOR + if (! Application.isPlaying) + { + if (moveToView) + SceneView.lastActiveSceneView.MoveToView(obj.transform); + + obj.transform.parent = Selection.gameObjects.Length > 0 ? Selection.gameObjects[0].transform : null; + SetDirty(obj); + Undo.RegisterCreatedObjectUndo(obj, $"Create {typeof(T).Name}"); + } +#endif + + return component; + } + + // 获得脚本模板内容 + public static string ScriptTemplate(string templateName) + { + var result = ""; + +#if UNITY_EDITOR + var fullName = $"{rootPath}/_RESOURCES/SCRIPT_TEMPLATE/" + templateName.Trim() + "Template.txt"; + TextAsset templateText = AssetDatabase.LoadAssetAtPath(fullName); + result = templateText.text; +#endif + + return result.Trim(); + } + + // 通过路径计算命名空间 + public static string GetNamespaceByPath(string pathName) + { + var start = pathName.IndexOf('/') + 1; + return pathName.Substring + (start, pathName.LastIndexOf('/') - start) + .Replace("/", "."); + } + + public static void FoldoutMenu(ref bool fold, string title, Action layout) + { +#if UNITY_EDITOR + EditorGUILayout.BeginHorizontal("FrameBox"); + { + EditorGUILayout.LabelField("", GUILayout.Width(20)); + + fold = ! EditorGUILayout.Foldout(! fold, title); + } + EditorGUILayout.EndHorizontal(); + + if (! fold) + { + EditorGUI.indentLevel++; + + EditorGUILayout.BeginVertical("OL box NoExpand"); + { + layout.Invoke(); + } + EditorGUILayout.EndVertical(); + + EditorGUI.indentLevel--; + + EditorGUILayout.Space(); + } +#endif + } + + public static void FoldoutMenuWithToggle(ref bool fold, ref bool toggle, string title, Action layout) + { +#if UNITY_EDITOR + EditorGUILayout.BeginHorizontal("FrameBox"); + { + EditorGUILayout.LabelField("", GUILayout.Width(20)); + + fold = ! EditorGUILayout.Foldout(! fold, title); + + toggle = EditorGUILayout.Toggle("", toggle, GUILayout.Width(20)); + } + EditorGUILayout.EndHorizontal(); + + if (! fold) + { + EditorGUI.BeginDisabledGroup(! toggle); + { + EditorGUI.indentLevel++; + + EditorGUILayout.BeginVertical("OL box NoExpand"); + { + layout.Invoke(); + } + EditorGUILayout.EndVertical(); + + EditorGUI.indentLevel--; + } + EditorGUI.EndDisabledGroup(); + + EditorGUILayout.Space(); + } +#endif + } + + public static class GUIStyles + { + public static GUIStyle titleStyleLarge => new() + { + normal = { textColor = GUI.contentColor }, + fontStyle = FontStyle.Bold, + fontSize = 16 + }; + + public static GUIStyle titleStyleSmall => new() + { + normal = { textColor = GUI.contentColor }, + fontStyle = FontStyle.Bold + }; + + public static GUIStyle contentStyleItalic => new() + { + normal = { textColor = GUI.contentColor }, + fontStyle = FontStyle.Italic + }; + } + } + + // Mountools 数据 + + // 可视化 Vector2 范围 + [Serializable] + public struct Vector2Square + { + public float x; + + public float y; + + public Vector2Square(float x = 0.5f, float y = 0.5f) + { + this.x = x; + this.y = y; + } + } + +#if UNITY_EDITOR + [CustomPropertyDrawer(typeof(Vector2Square))] + public class Vector2SquarePropertyDrawer : PropertyDrawer + { + private Rect drawerPosition; + + public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) + { + drawerPosition = position; + + EditorGUI.BeginProperty(position, label, property); + { + // xy的参数 + var xValue = (float) typeof(Vector2Square).GetField("x").GetValue(property.boxedValue); + var yValue = (float) typeof(Vector2Square).GetField("y").GetValue(property.boxedValue); + + // 自身对象 + var selfObject = (Vector2Square) property.boxedValue; + + // 事件 + Event currentEvent = Event.current; + + { + // ----------- 绘制部分 + + // 绘制文本 + position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label); + position.y += 25; + + // 绘制方块 + var size = drawerPosition.width / 3; + var squareRect = new Rect(new Vector2(20, position.y), size * Vector2.one); + EditorGUI.HelpBox(squareRect, "", MessageType.None); + // position.x += size; + + // 绘制点 + var pointSize = 2; + var pointRect = new Rect( + new Vector2( + Mathf.Lerp(squareRect.xMin, squareRect.xMax, xValue), + Mathf.Lerp(squareRect.yMax, squareRect.yMin, yValue) + ), + pointSize * Vector2.one + ); + EditorGUI.DrawRect(pointRect, Color.white); + + // 绘制数值拖动条 + EditorGUI.BeginChangeCheck(); + { + selfObject.x = EditorGUI.Slider(position, "", xValue, 0, 1); + position.y += 35; + selfObject.y = EditorGUI.Slider(position, "", yValue, 0, 1); + } + if (EditorGUI.EndChangeCheck()) + { + property.boxedValue = selfObject; + property.serializedObject.ApplyModifiedProperties(); + } + + // ----------- 数值更改部分 + + // 鼠标点击 + if ((currentEvent.type == EventType.MouseDrag || currentEvent.type == EventType.MouseDown) + && currentEvent.button == 0) + { + // 鼠标位置 + var pos = currentEvent.mousePosition; + + // 若在范围 + if ( + MountoolsMath.IsInRange(pos.x, squareRect.xMin - 5, squareRect.xMax + 5) && + MountoolsMath.IsInRange(pos.y, squareRect.yMin - 5, squareRect.yMax + 5) + ) + { + var newX = + Mathf.Lerp(0, 1, Mathf.InverseLerp(squareRect.xMin, squareRect.xMax, pos.x)); + + var newY = + Mathf.Lerp(0, 1, Mathf.InverseLerp(squareRect.yMax, squareRect.yMin, pos.y)); + + selfObject.x = newX; + selfObject.y = newY; + + property.boxedValue = selfObject; + property.serializedObject.ApplyModifiedProperties(); + } + } + } + } + EditorGUI.EndProperty(); + } + + public override float GetPropertyHeight(SerializedProperty property, GUIContent label) + { + var height = 0f; + height += 25; // 第一行 + height += drawerPosition.width / 3; // 方块 + height += 5; + + return height; + } + } +#endif +} diff --git a/Assets/Mountools/Tools/MountoolsEditor.cs.meta b/Assets/Mountools/Tools/MountoolsEditor.cs.meta new file mode 100755 index 0000000..967933c --- /dev/null +++ b/Assets/Mountools/Tools/MountoolsEditor.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 758b469ed37f76e42abc008db85ab298 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Mountools/Tools/MountoolsLanguage.cs b/Assets/Mountools/Tools/MountoolsLanguage.cs new file mode 100755 index 0000000..cabe183 --- /dev/null +++ b/Assets/Mountools/Tools/MountoolsLanguage.cs @@ -0,0 +1,15 @@ +namespace Mountools.Tools +{ + public static class MountoolsLanguage + { + public static string Lang(string chinese, string english) + { +#if MT_L_CHINESE + return chinese; +#endif +#if MT_L_ENGLISH + return english; +#endif + } + } +} \ No newline at end of file diff --git a/Assets/Mountools/Tools/MountoolsLanguage.cs.meta b/Assets/Mountools/Tools/MountoolsLanguage.cs.meta new file mode 100755 index 0000000..de02711 --- /dev/null +++ b/Assets/Mountools/Tools/MountoolsLanguage.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: d86babedc80646fca88a520413c044af +timeCreated: 1719412570 \ No newline at end of file diff --git a/Assets/Mountools/Tools/MountoolsMath.cs b/Assets/Mountools/Tools/MountoolsMath.cs new file mode 100755 index 0000000..3b982e5 --- /dev/null +++ b/Assets/Mountools/Tools/MountoolsMath.cs @@ -0,0 +1,58 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Linq.Expressions; +using UnityEngine; + +#if UNITY_EDITOR +using UnityEditorInternal; +#endif + +namespace Mountools.Tools +{ + public static class MountoolsMath + { + public static bool IsInRange(int n, int min, int max, bool equals = true) + { + return equals ? + n <= max && n >= min : + n < max && n > min ; + } + + public static bool IsInRange(float n, float min, float max, bool equals = true) + { + return equals ? + n <= max && n >= min : + n < max && n > min ; + } + + public static int InRange(int n, int min, int max) + { + if (n < min) return min; + if (n > max) return max; + return n; + } + + public static float InRange(float n, float min, float max) + { + if (n < min) return min; + if (n > max) return max; + return n; + } + + public static float To(float a, float b, float t) + { + if (a > b) return InRange(a - t, b, a); + if (a < b) return InRange(a + t, a, b); + return a; + } + + public static int To(int a, int b, int t) + { + if (a > b) return InRange(a - t, b, a); + if (a < b) return InRange(a + t, a, b); + return a; + } + } +} diff --git a/Assets/Mountools/Tools/MountoolsMath.cs.meta b/Assets/Mountools/Tools/MountoolsMath.cs.meta new file mode 100755 index 0000000..d8c4fdc --- /dev/null +++ b/Assets/Mountools/Tools/MountoolsMath.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 59ccbe5b0e8b24c43bbe38561c115bca +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Mountools/Tools/MountoolsShortcut.cs b/Assets/Mountools/Tools/MountoolsShortcut.cs new file mode 100755 index 0000000..32beebb --- /dev/null +++ b/Assets/Mountools/Tools/MountoolsShortcut.cs @@ -0,0 +1,56 @@ +using UnityEngine; + +namespace Mountools.Tools +{ + public class MountoolsShortcut + { + public static bool ctrl => + Input.GetKey(KeyCode.LeftControl) + || Input.GetKey(KeyCode.LeftCommand) + || Input.GetKey(KeyCode.RightControl) + || Input.GetKey(KeyCode.RightCommand); + + public static bool shift => + Input.GetKey(KeyCode.LeftShift) + || Input.GetKey(KeyCode.RightShift); + + public static bool alt => + Input.GetKey(KeyCode.LeftAlt) + || Input.GetKey(KeyCode.RightAlt); + + public static bool Ctrl(KeyCode keyCode, bool checkHold = false) + { + return ctrl && !shift && !alt && (checkHold ? Input.GetKey(keyCode) : Input.GetKeyDown(keyCode)); + } + + public static bool CtrlShift(KeyCode keyCode, bool checkHold = false) + { + return ctrl && shift && !alt && (checkHold ? Input.GetKey(keyCode) : Input.GetKeyDown(keyCode)); + } + + public static bool CtrlAlt(KeyCode keyCode, bool checkHold = false) + { + return ctrl && !shift && alt && (checkHold ? Input.GetKey(keyCode) : Input.GetKeyDown(keyCode)); + } + + public static bool CtrlShiftAlt(KeyCode keyCode, bool checkHold = false) + { + return ctrl && shift && alt && (checkHold ? Input.GetKey(keyCode) : Input.GetKeyDown(keyCode)); + } + + public static bool Shift(KeyCode keyCode, bool checkHold = false) + { + return !ctrl && shift && !alt && (checkHold ? Input.GetKey(keyCode) : Input.GetKeyDown(keyCode)); + } + + public static bool ShiftAlt(KeyCode keyCode, bool checkHold = false) + { + return !ctrl && shift && alt && (checkHold ? Input.GetKey(keyCode) : Input.GetKeyDown(keyCode)); + } + + public static bool Alt(KeyCode keyCode, bool checkHold = false) + { + return !ctrl && !shift && alt && (checkHold ? Input.GetKey(keyCode) : Input.GetKeyDown(keyCode)); + } + } +} \ No newline at end of file diff --git a/Assets/Mountools/Tools/MountoolsShortcut.cs.meta b/Assets/Mountools/Tools/MountoolsShortcut.cs.meta new file mode 100755 index 0000000..dab0986 --- /dev/null +++ b/Assets/Mountools/Tools/MountoolsShortcut.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: cbce2c729f31492d812ae5af45e43b75 +timeCreated: 1719412590 \ No newline at end of file diff --git a/Assets/Mountools/Tools/ToolFreeCamera.cs b/Assets/Mountools/Tools/ToolFreeCamera.cs new file mode 100755 index 0000000..8f7fce8 --- /dev/null +++ b/Assets/Mountools/Tools/ToolFreeCamera.cs @@ -0,0 +1,167 @@ +#if UNITY_EDITOR +using System.Collections.Generic; +using UnityEngine; + +namespace Mountools.Tools +{ + public class ToolFreeCamera : MonoBehaviour + { + [HideInInspector] public string cameraRotationX = "Mouse Y"; + [HideInInspector] public string cameraRotationY = "Mouse X"; + [HideInInspector] public string cameraRotationZ = "Horizontal"; + [HideInInspector] public string cameraForwardAxisName = "Vertical"; + [HideInInspector] public string cameraFastMoveButton = "Fire3"; + [HideInInspector] public string enableRotationZ = "Fire1"; + [HideInInspector] public string cameraRotationZRecover = "Jump"; + + public float cameraSensitivity = 150f; + public float cameraMovingSpeed = 20f; + public float cameraFastMovingSpeed = 50f; + public bool canCameraRotationZ; + + // 场景内相机状态 + private readonly Dictionary _cameraStatus = new(); + + private float _currentSpeed; + private Vector3 _currentRotation; + + // 相机状态 + public bool active => FindObjectOfType() != null; + + public static void FreeCameraEnter() + { + if (! Application.isPlaying) return; + if (FindObjectOfType() != null) return; + + GameObject gameObject = new GameObject("Free Camera"); + Camera selfCamera = gameObject.AddComponent(); + ToolFreeCamera freeCamera = gameObject.AddComponent(); + Camera[] cameras = FindObjectsOfType(true); + + freeCamera._cameraStatus.Clear(); + foreach (var cam in cameras) + { + if (cam == selfCamera) continue; + + freeCamera._cameraStatus.Add(cam, cam.gameObject.activeSelf); + + if (cam.gameObject.activeSelf) + { + var camTransform = cam.transform; + var selfCameraTransform = selfCamera.transform; + + selfCameraTransform.position = camTransform.position; + freeCamera._currentRotation = camTransform.rotation.eulerAngles; + + selfCamera.fieldOfView = cam.fieldOfView; + selfCamera.orthographic = cam.orthographic; + selfCamera.depth = cam.depth; + selfCamera.aspect = cam.aspect; + selfCamera.clearFlags = cam.clearFlags; + selfCamera.backgroundColor = cam.backgroundColor; + + cam.gameObject.SetActive(false); + continue; + } + + cam.gameObject.SetActive(false); + } + + Cursor.lockState = CursorLockMode.Locked; + Cursor.visible = false; + } + + public static void FreeCameraExit() + { + if (! Application.isPlaying) return; + var freeCamera = FindObjectOfType(); + if (freeCamera == null) return; + + freeCamera.gameObject.SetActive(false); + + foreach (var cameras in freeCamera._cameraStatus) + { + cameras.Key.gameObject.SetActive(cameras.Value); + } + + Destroy(freeCamera.gameObject); + } + + private void Update() + { + if (Input.GetKeyDown(KeyCode.Mouse0)) + { + Cursor.lockState = CursorLockMode.Locked; + Cursor.visible = false; + } + + if (Input.GetKeyDown(KeyCode.Mouse1) || Input.GetKeyDown(KeyCode.Escape)) + { + if (Cursor.lockState == CursorLockMode.None) + { + FreeCameraExit(); + } + else + { + Cursor.lockState = CursorLockMode.None; + Cursor.visible = true; + } + } + + UpdateCameraRotation(); + } + + public void UpdateCameraRotation() + { + if (Cursor.lockState == CursorLockMode.None) return; + + var camRotationZ = Input.GetAxis(cameraRotationZ); + + var canRotationZ = canCameraRotationZ && Input.GetButton(enableRotationZ); + + // Rotation Control + var rotationVector = new Vector3 + { + x = Input.GetAxis(cameraRotationX), + y = Input.GetAxis(cameraRotationY), + z = canRotationZ ? camRotationZ : 0 + }; + + // Change Rotation + var t = transform; + _currentRotation.x -= cameraSensitivity * Time.fixedDeltaTime * rotationVector.x; + _currentRotation.y += cameraSensitivity * Time.fixedDeltaTime * rotationVector.y; + _currentRotation.z -= cameraSensitivity * Time.fixedDeltaTime * rotationVector.z; + _currentRotation.x = ClampRotation(_currentRotation.x, -90, 90); + _currentRotation.z = ClampRotation(_currentRotation.z, -90, 90); + + if (Input.GetButton(cameraRotationZRecover)) + _currentRotation.z = Mathf.Lerp(_currentRotation.z, 0, 0.2f); + + t.rotation = Quaternion.Euler(_currentRotation); + + // Movement Control + var movementAxisForward = Input.GetAxis(cameraForwardAxisName); + var movementAxisRight = canRotationZ ? 0 : camRotationZ; + + var speed = Input.GetButton(cameraFastMoveButton) ? cameraFastMovingSpeed : cameraMovingSpeed; + _currentSpeed = Mathf.Lerp(_currentSpeed, speed, 0.3f); + + t.position += t.forward * (Time.deltaTime * _currentSpeed * movementAxisForward) + + t.right * (Time.deltaTime * _currentSpeed * movementAxisRight); + } + + private static float ClampRotation(float n, float min, float max) + { + if (n < -360) + n += 360; + + if (n > 360) + n-= 360; + + return Mathf.Clamp(n, min, max); + } + } +} + +#endif \ No newline at end of file diff --git a/Assets/Mountools/Tools/ToolFreeCamera.cs.meta b/Assets/Mountools/Tools/ToolFreeCamera.cs.meta new file mode 100755 index 0000000..36661c9 --- /dev/null +++ b/Assets/Mountools/Tools/ToolFreeCamera.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: e92933fc3e5cf944998e2203f13c3dd5 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Mountools/Tools/ToolInspectorBookmark.cs b/Assets/Mountools/Tools/ToolInspectorBookmark.cs new file mode 100755 index 0000000..50ee7fb --- /dev/null +++ b/Assets/Mountools/Tools/ToolInspectorBookmark.cs @@ -0,0 +1,22 @@ +using UnityEngine; + +namespace Mountools.Tools +{ +#if MT_L_CHINESE + [AddComponentMenu("Mountools/工具/书签")] +#endif +#if MT_L_ENGLISH + [AddComponentMenu("Mountools/Tools/Bookmark")] +#endif + [Icon("Assets/Mountools/_RESOURCES/ICONS/TOOLS/BOOKMARK.png")] + public class ToolInspectorBookmark : MonoBehaviour + { + [HideInInspector] +#if MT_L_CHINESE + public string bookmarkContent = "写点啥 :)"; +#endif +#if MT_L_ENGLISH + public string bookmarkContent = "Write something :)"; +#endif + } +} diff --git a/Assets/Mountools/Tools/ToolInspectorBookmark.cs.meta b/Assets/Mountools/Tools/ToolInspectorBookmark.cs.meta new file mode 100755 index 0000000..96e6fe2 --- /dev/null +++ b/Assets/Mountools/Tools/ToolInspectorBookmark.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: b7a24f53e89a97f4d931bde1d8810ae3 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Mountools/Tools/ToolObjectMethodInvoker.cs b/Assets/Mountools/Tools/ToolObjectMethodInvoker.cs new file mode 100755 index 0000000..148f121 --- /dev/null +++ b/Assets/Mountools/Tools/ToolObjectMethodInvoker.cs @@ -0,0 +1,500 @@ +#if UNITY_EDITOR +using System; +using System.Collections.Generic; +using System.Reflection; +using UnityEditor; +using UnityEngine; + +namespace Mountools.Tools +{ + public class ToolObjectMethodInvoker : EditorWindow + { + private string _search = ""; + + private Vector2 _scrollPositionRight = Vector2.zero; + + private Dictionary _parameterCache; + private Dictionary _foldoutEnableMethod; + + private bool _showGetter; + private bool _showSetter; + private bool _showPrivate; + private bool _showInherit; + + private Component _debugComponent; + + private void OnGUI() + { + EditorGUILayout.BeginVertical(); + Draw(); + EditorGUILayout.EndVertical(); + } + + private void Draw() + { + if (_parameterCache == null) + _parameterCache = new(); + + if (_foldoutEnableMethod == null) + _foldoutEnableMethod = new(); + + if (Selection.gameObjects == null || Selection.gameObjects.Length < 1) + { + return; + } + + GameObject debugObject = Selection.gameObjects[0]; + + var components = debugObject.GetComponents(); + + EditorGUILayout.BeginVertical(); + { + EditorGUILayout.BeginVertical(GUILayout.Height(20)); + { + int select = 0; + var i = 0; + Component[] selections = components; + List names = new List(); + foreach (var component in components) + { + names.Add(component.GetType().Name); + + if (component == _debugComponent) + select = i; + i++; + } + _debugComponent = selections[GUILayout.Toolbar(select, names.ToArray(), "toolbarbuttonRight")]; + + + } + EditorGUILayout.EndVertical(); + + EditorGUILayout.BeginHorizontal(); + { + _showSetter = GUILayout.Toggle(_showSetter, "Setter", "TE toolbarbutton", GUILayout.Width(45)); + _showGetter = GUILayout.Toggle(_showGetter, "Getter", "TE toolbarbutton", GUILayout.Width(45)); + _showInherit = GUILayout.Toggle(_showInherit, "Inherit", "TE toolbarbutton", GUILayout.Width(60)); + _showPrivate = GUILayout.Toggle(_showPrivate, "Private", "TE toolbarbutton", GUILayout.Width(60)); + _search = EditorGUILayout.TextField("", _search, "SearchTextField"); + } + EditorGUILayout.EndHorizontal(); + + _scrollPositionRight = EditorGUILayout.BeginScrollView(_scrollPositionRight, "OL box NoExpand"); + { + DrawComponentMethodInvokerView(_debugComponent); + } + EditorGUILayout.EndScrollView(); + } + EditorGUILayout.EndVertical(); + } + + private void DrawComponentMethodInvokerView(Component component) + { + if (component == null) + { + return; + } + + var style = new GUIStyle { fontSize = 12, fontStyle = FontStyle.Bold, normal = { textColor = GUI.contentColor } }; + +#if MT_L_CHINESE + var strMethod = "有参数方法列表"; +#endif +#if MT_L_ENGLISH + var strMethod = "Method"; +#endif + EditorGUILayout.LabelField(" " + strMethod, style); + + EditorGUILayout.BeginVertical(); + { + List noParameterMethodInfos = new List(); + var methods = component.GetType().GetMethods(); + var drawCount = 0; + foreach (var method in methods) + { + if (method.Name.Contains("get_") && !_showGetter) continue; + if (method.Name.Contains("set_") && !_showSetter) continue; + if (method.IsPrivate && !_showPrivate) continue; + if (method.DeclaringType != method.ReflectedType && !_showInherit) continue; + if (_search.Trim() != "" && !method.Name.ToLower().Contains(_search.Trim().ToLower())) continue; + + if (!method.ContainsGenericParameters && !method.IsGenericMethod && !method.IsAbstract && + !method.IsConstructor && !method.IsAssembly) + { + ParameterInfo[] paremeters = method.GetParameters(); + if (paremeters.Length > 0) + { + DrawMethodInvoker(component, method, paremeters); + drawCount ++; + } + else + { + noParameterMethodInfos.Add(method); + } + } + } +#if MT_L_CHINESE + var strNone = "无"; + var strNoParameter = "无参数方法列表"; +#endif +#if MT_L_ENGLISH + var strNone = "None"; + var strNoParameter = "No Parameter"; +#endif + if (drawCount == 0) + { + EditorGUILayout.LabelField(strNone); + } + + EditorGUILayout.Space(); + + EditorGUILayout.LabelField(" " + strNoParameter, style); + + if (noParameterMethodInfos.Count < 1) + { + EditorGUILayout.LabelField(strNone); + } + else + { + foreach (var method in noParameterMethodInfos) + { + if (EditorGUILayout.LinkButton(method.Name + "();")) + { + PrintReturnValue(method, method.Invoke(component, null)); + } + } + } + } + EditorGUILayout.EndVertical(); + } + + private void DrawMethodInvoker(Component obj, MethodInfo methodInfo, ParameterInfo[] parameters) + { + string parameterNames = ""; + foreach (var parameter in parameters) + { + parameterNames += parameter.ParameterType.Name + " " + parameter.Name + ", "; + } + + string n = (methodInfo.Name + " (" + parameterNames + ");") + .Replace("Single", "float") + .Replace("Int32", "int") + .Replace(", );", ");"); + + SetFoldoutMethod(methodInfo, + EditorGUILayout.BeginFoldoutHeaderGroup(GetFoldoutMethod(methodInfo), n, "FoldoutHeader")); + EditorGUILayout.EndFoldoutHeaderGroup(); + + EditorGUILayout.BeginHorizontal(); + { + if (GetFoldoutMethod(methodInfo)) + { + EditorGUILayout.BeginVertical("OL box NoExpand"); + { + bool canInvoke = true; + + foreach (var parameter in parameters) + { + if (!DrawParameterInputField(parameter)) + canInvoke = false; + } + +#if MT_L_CHINESE + var strInvoke = "调用方法"; + var strInvokeUnsafe = "调用方法 (非安全)"; +#endif +#if MT_L_ENGLISH + var strInvoke = "Invoke"; + var strInvokeUnsafe = "Invoke (Unsafe)"; +#endif + + bool click = canInvoke + ? GUILayout.Button(strInvoke) + : GUILayout.Button(strInvokeUnsafe); + + if (click) + { + List param = new List(); + foreach (var parameter in parameters) + { + param.Add(GetParameter(parameter)); + } + + PrintReturnValue(methodInfo, methodInfo.Invoke(obj, param.ToArray())); + } + } + EditorGUILayout.EndVertical(); + } + } + EditorGUILayout.EndHorizontal(); + } + + private bool DrawParameterInputField(ParameterInfo parameterInfo) + { + var type = parameterInfo.ParameterType; + var parameterNameRaw = parameterInfo.Name; + var parameterName = ""; + + // Name Formatter + var i = 0; + foreach (var nameChar in parameterNameRaw.Trim()) + { + if (Char.IsUpper(nameChar)) + { + parameterName += " " + nameChar; + continue; + } + + parameterName += nameChar; + } + + if (parameterName.Length > 1) + parameterName = parameterName.Substring(0, 1).ToUpper() + parameterName.Substring(1); + else + parameterName = parameterName.ToUpper(); + + if (type == typeof(int)) + { + string t = parameterInfo.Name.ToLower(); + if (t.Contains("mask") || t.Contains("layer")) + { + SetParameter(parameterInfo, + EditorGUILayout.LayerField(parameterName, (int) GetParameter(parameterInfo, 0))); + return true; + } + + SetParameter(parameterInfo, + EditorGUILayout.IntField(parameterName, (int) GetParameter(parameterInfo, 0))); + return true; + } + + if (type == typeof(float)) + { + SetParameter(parameterInfo, + EditorGUILayout.FloatField(parameterName, (float) GetParameter(parameterInfo, 0f))); + return true; + } + + if (type == typeof(string)) + { + string t = parameterName.ToLower(); + if (t.Contains("password") || t.Contains("pswd") || t.Contains("passwd")) + { + SetParameter(parameterInfo, + EditorGUILayout.PasswordField(parameterName, (string) GetParameter(parameterInfo, 0))); + return true; + } + + SetParameter(parameterInfo, + EditorGUILayout.TextField(parameterName, (string) GetParameter(parameterInfo, ""))); + return true; + } + + if (type == typeof(bool)) + { + SetParameter(parameterInfo, + EditorGUILayout.Toggle(parameterName, (bool) GetParameter(parameterInfo, false))); + return true; + } + + if (type == typeof(Quaternion)) + { + Quaternion q = (Quaternion) GetParameter(parameterInfo, Quaternion.Euler(0, 0, 0)); + Vector4 qv4 = new Vector4(q.x, q.y, q.z, q.w); + Vector4 v = EditorGUILayout.Vector4Field(parameterName, qv4); + SetParameter(parameterInfo, + new Quaternion(v.x, v.y, v.z, v.w)); + return true; + } + + if (type == typeof(Vector4)) + { + SetParameter(parameterInfo, + EditorGUILayout.Vector4Field(parameterName, (Vector4) GetParameter(parameterInfo, Vector4.zero))); + return true; + } + + if (type == typeof(Vector3)) + { + SetParameter(parameterInfo, + EditorGUILayout.Vector3Field(parameterName, (Vector3) GetParameter(parameterInfo, Vector3.zero))); + return true; + } + + if (type == typeof(Vector2)) + { + SetParameter(parameterInfo, + EditorGUILayout.Vector2Field(parameterName, (Vector2) GetParameter(parameterInfo, Vector2.zero))); + return true; + } + + if (type == typeof(Color)) + { + SetParameter(parameterInfo, + EditorGUILayout.ColorField(parameterName, (Color) GetParameter(parameterInfo, Color.black))); + return true; + } + + if (type == typeof(Gradient)) + { + SetParameter(parameterInfo, + EditorGUILayout.GradientField(parameterName, (Gradient) GetParameter(parameterInfo))); + return true; + } + + if (type == typeof(Bounds)) + { + SetParameter(parameterInfo, + EditorGUILayout.BoundsField(parameterName, (Bounds) GetParameter(parameterInfo))); + return true; + } + + if (type == typeof(AnimationCurve)) + { + SetParameter(parameterInfo, + EditorGUILayout.CurveField(parameterName, (AnimationCurve) GetParameter(parameterInfo))); + return true; + } + + if (type == typeof(double)) + { + SetParameter(parameterInfo, + EditorGUILayout.DoubleField(parameterName, (double) GetParameter(parameterInfo))); + return true; + } + + if (type == typeof(long)) + { + SetParameter(parameterInfo, + EditorGUILayout.LongField(parameterName, (long) GetParameter(parameterInfo))); + return true; + } + + if (type == typeof(Rect)) + { + SetParameter(parameterInfo, + EditorGUILayout.RectField(parameterName, (Rect) GetParameter(parameterInfo))); + return true; + } + + if (type == typeof(Transform)) + { + SetParameter(parameterInfo, + EditorGUILayout.ObjectField(parameterName, (Transform) GetParameter(parameterInfo), typeof(Transform), true)); + return true; + } + + GUILayout.Label(parameterName); + return false; + } + + private void PrintReturnValue(MethodInfo methodInfo, object obj) + { + if (obj == null) return; + + Type type = obj.GetType(); + + if (type == typeof(int) || + type == typeof(float) || + type == typeof(double) || + type == typeof(string) || + type == typeof(char) || + type == typeof(long)) + { + PrintReturnValueFormat(methodInfo, obj.ToString()); + return; + } + + if (type == typeof(Color)) + { + Color v = (Color)obj; + PrintReturnValueFormat(methodInfo, $"argb:{v.a},{v.r},{v.g},{v.b}"); + return; + } + + if (type == typeof(Vector2)) + { + Vector2 v = (Vector2)obj; + PrintReturnValueFormat(methodInfo, $"xy:{v.x},{v.y}"); + return; + } + + if (type == typeof(Vector3)) + { + Vector3 v = (Vector3)obj; + PrintReturnValueFormat(methodInfo, $"xyz:{v.x},{v.y},{v.z}"); + return; + } + + if (type == typeof(Vector4)) + { + Vector4 v = (Vector4)obj; + PrintReturnValueFormat(methodInfo, $"xyzw:{v.x},{v.y},{v.z},{v.w}"); + return; + } + + if (type == typeof(Quaternion)) + { + Quaternion v = (Quaternion)obj; + Vector3 e = v.eulerAngles; + PrintReturnValueFormat(methodInfo, $"xyzw:{v.x},{v.y},{v.z},{v.w} euler:{e.x},{e.y},{e.z}"); + return; + } + } + + private void PrintReturnValueFormat(MethodInfo methodInfo, string value) + { + Debug.Log(methodInfo.Name + " Returned : ( " + methodInfo.ReturnType.Name + " ) " + value, _debugComponent); + } + + private object GetParameter(ParameterInfo parameterInfo, object defaultValue = null) + { + if (_parameterCache.ContainsKey(parameterInfo)) + { + if (_parameterCache[parameterInfo] == null && defaultValue != null) + { + SetParameter(parameterInfo, defaultValue); + } + return _parameterCache[parameterInfo]; + } + + _parameterCache.Add(parameterInfo, defaultValue); + return defaultValue; + } + + private void SetParameter(ParameterInfo parameterInfo, object value) + { + if (_parameterCache.ContainsKey(parameterInfo)) + { + _parameterCache[parameterInfo] = value; + return; + } + + _parameterCache.Add(parameterInfo, value); + } + + private bool GetFoldoutMethod(MethodInfo method) + { + if (_foldoutEnableMethod.ContainsKey(method)) + { + return _foldoutEnableMethod[method]; + } + + _foldoutEnableMethod.Add(method, false); + return false; + } + + private void SetFoldoutMethod(MethodInfo method, bool enable) + { + if (_foldoutEnableMethod.ContainsKey(method)) + { + _foldoutEnableMethod[method] = enable; + return; + } + + _foldoutEnableMethod.Add(method, enable); + } + } +} + +#endif \ No newline at end of file diff --git a/Assets/Mountools/Tools/ToolObjectMethodInvoker.cs.meta b/Assets/Mountools/Tools/ToolObjectMethodInvoker.cs.meta new file mode 100755 index 0000000..98fe05f --- /dev/null +++ b/Assets/Mountools/Tools/ToolObjectMethodInvoker.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 79ff1afa25b1fb94e90305c389a7b9d2 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: -- cgit