This commit is contained in:
陈思海 2025-11-11 17:14:00 +08:00
parent 5b670c2464
commit 4c4ddfe150
2 changed files with 9 additions and 3 deletions

View File

@ -3,6 +3,7 @@ using System.Reflection;
using TMPro; using TMPro;
using TMPro.EditorUtilities; using TMPro.EditorUtilities;
using UnityEditor; using UnityEditor;
using UnityEditor.UI;
using UnityEngine; using UnityEngine;
using UnityEngine.UI; using UnityEngine.UI;
@ -37,11 +38,12 @@ internal class UXUIEditor : Editor
image.material = AssetDatabase.LoadAssetAtPath<Material>(UXGUIConfig.UIDefaultMatPath); image.material = AssetDatabase.LoadAssetAtPath<Material>(UXGUIConfig.UIDefaultMatPath);
} }
#if TEXTMESHPRO_SUPPORT
[MenuItem("GameObject/UI/UXTextMeshPro")] [MenuItem("GameObject/UI/UXTextMeshPro")]
private static void CreateUXTextMeshPro(MenuCommand menuCommand) private static void CreateUXTextMeshPro(MenuCommand menuCommand)
{ {
Type MenuOptionsType = typeof(UnityEditor.UI.ImageEditor).Assembly.GetType("UnityEditor.UI.MenuOptions"); Type MenuOptionsType = typeof(ImageEditor).Assembly.GetType("UnityEditor.UI.MenuOptions");
InvokeMethod(MenuOptionsType, "AddText", new object[] { menuCommand }); InvokeMethod(MenuOptionsType, "AddText", new object[] { menuCommand });
GameObject obj = Selection.activeGameObject; GameObject obj = Selection.activeGameObject;
obj.name = "UXTextMeshPro"; obj.name = "UXTextMeshPro";
@ -52,7 +54,7 @@ internal class UXUIEditor : Editor
[MenuItem("GameObject/UI/UXButton")] [MenuItem("GameObject/UI/UXButton")]
public static void CreateUXButton(MenuCommand menuCommand) public static void CreateUXButton(MenuCommand menuCommand)
{ {
Type MenuOptionsType = typeof(TMPro.EditorUtilities.TMPro_CreateObjectMenu).Assembly.GetType("TMPro.EditorUtilities.TMPro_CreateObjectMenu"); Type MenuOptionsType = typeof(TMPro_CreateObjectMenu).Assembly.GetType("TMPro.EditorUtilities.TMPro_CreateObjectMenu");
InvokeMethod(MenuOptionsType, "AddButton", new object[] { menuCommand }); InvokeMethod(MenuOptionsType, "AddButton", new object[] { menuCommand });
GameObject obj = Selection.activeGameObject; GameObject obj = Selection.activeGameObject;
obj.name = "UXButton"; obj.name = "UXButton";
@ -63,7 +65,7 @@ internal class UXUIEditor : Editor
[MenuItem("GameObject/UI/UXInput Field")] [MenuItem("GameObject/UI/UXInput Field")]
public static void CreateUXInputField(MenuCommand menuCommand) public static void CreateUXInputField(MenuCommand menuCommand)
{ {
Type MenuOptionsType = typeof(TMPro.EditorUtilities.TMPro_CreateObjectMenu).Assembly.GetType("TMPro.EditorUtilities.TMPro_CreateObjectMenu"); Type MenuOptionsType = typeof(TMPro_CreateObjectMenu).Assembly.GetType("TMPro.EditorUtilities.TMPro_CreateObjectMenu");
InvokeMethod(MenuOptionsType, "AddTextMeshProInputField", new object[] { menuCommand }); InvokeMethod(MenuOptionsType, "AddTextMeshProInputField", new object[] { menuCommand });
GameObject obj = Selection.activeGameObject; GameObject obj = Selection.activeGameObject;
obj.name = "UXInputField"; obj.name = "UXInputField";
@ -80,6 +82,7 @@ internal class UXUIEditor : Editor
newTextField.text = oldText; newTextField.text = oldText;
inputField.placeholder = newTextField; inputField.placeholder = newTextField;
} }
#endif
[MenuItem("GameObject/UI/UXScrollView")] [MenuItem("GameObject/UI/UXScrollView")]
private static void CreateUxRecyclerView() private static void CreateUxRecyclerView()

View File

@ -1,3 +1,4 @@
#if TEXTMESHPRO_SUPPORT
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Reflection; using System.Reflection;
@ -85,3 +86,5 @@ namespace UnityEngine.UI
} }
} }
} }
#endif