This commit is contained in:
陈思海 2025-11-06 16:31:20 +08:00
parent f71b5c3c7c
commit 5b670c2464

View File

@ -1,5 +1,6 @@
using System; using System;
using System.Reflection; using System.Reflection;
using TMPro;
using TMPro.EditorUtilities; using TMPro.EditorUtilities;
using UnityEditor; using UnityEditor;
using UnityEngine; using UnityEngine;
@ -59,6 +60,27 @@ internal class UXUIEditor : Editor
obj.AddComponent<UXButton>(); obj.AddComponent<UXButton>();
} }
[MenuItem("GameObject/UI/UXInput Field")]
public static void CreateUXInputField(MenuCommand menuCommand)
{
Type MenuOptionsType = typeof(TMPro.EditorUtilities.TMPro_CreateObjectMenu).Assembly.GetType("TMPro.EditorUtilities.TMPro_CreateObjectMenu");
InvokeMethod(MenuOptionsType, "AddTextMeshProInputField", new object[] { menuCommand });
GameObject obj = Selection.activeGameObject;
obj.name = "UXInputField";
TMP_InputField inputField = obj.GetComponent<TMP_InputField>();
TextMeshProUGUI oldTextField = inputField.placeholder.GetComponent<TextMeshProUGUI>();
GameObject placeholderGameObject = inputField.placeholder.gameObject;
float oldFontSize = oldTextField.fontSize;
Color oldColor = oldTextField.color;
string oldText = oldTextField.text;
DestroyImmediate(oldTextField);
TextMeshProUGUI newTextField = placeholderGameObject.AddComponent<TextMeshProUGUI>();
newTextField.fontSize = oldFontSize;
newTextField.color = oldColor;
newTextField.text = oldText;
inputField.placeholder = newTextField;
}
[MenuItem("GameObject/UI/UXScrollView")] [MenuItem("GameObject/UI/UXScrollView")]
private static void CreateUxRecyclerView() private static void CreateUxRecyclerView()
{ {