using System; using System.Reflection; using TMPro.EditorUtilities; using UnityEditor; using UnityEngine; using UnityEngine.UI; internal class UXUIEditor : Editor { static object InvokeMethod(Type type, string methodName, object[] parameters = null) { if (parameters == null) { return type.GetMethod(methodName, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static).Invoke(null, null); } Type[] types = new Type[parameters.Length]; for (int i = 0; i < parameters.Length; i++) { types[i] = parameters[i].GetType(); } return type.GetMethod(methodName, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static, null, types, null).Invoke(null, parameters); } [MenuItem("GameObject/UI/UXImage")] public static void CreateUXImage(MenuCommand menuCommand) { Type MenuOptionsType = typeof(UnityEditor.UI.ImageEditor).Assembly.GetType("UnityEditor.UI.MenuOptions"); InvokeMethod(MenuOptionsType, "AddImage", new object[] { menuCommand }); GameObject obj = Selection.activeGameObject; obj.name = "UXImage"; DestroyImmediate(obj.GetComponent()); var image = obj.AddComponent(); image.material = AssetDatabase.LoadAssetAtPath(UXGUIConfig.UIDefaultMatPath); } [MenuItem("GameObject/UI/UXTextMeshPro")] private static void CreateUXTextMeshPro(MenuCommand menuCommand) { Type MenuOptionsType = typeof(UnityEditor.UI.ImageEditor).Assembly.GetType("UnityEditor.UI.MenuOptions"); InvokeMethod(MenuOptionsType, "AddText", new object[] { menuCommand }); GameObject obj = Selection.activeGameObject; obj.name = "UXTextMeshPro"; DestroyImmediate(obj.GetComponent()); obj.AddComponent(); } [MenuItem("GameObject/UI/UXButton")] public static void CreateUXButton(MenuCommand menuCommand) { Type MenuOptionsType = typeof(TMPro.EditorUtilities.TMPro_CreateObjectMenu).Assembly.GetType("TMPro.EditorUtilities.TMPro_CreateObjectMenu"); InvokeMethod(MenuOptionsType, "AddButton", new object[] { menuCommand }); GameObject obj = Selection.activeGameObject; obj.name = "UXButton"; DestroyImmediate(obj.GetComponent