diff --git a/Editor/Constant.meta b/Editor/Constant.meta new file mode 100644 index 0000000..6d605c5 --- /dev/null +++ b/Editor/Constant.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: b754973ba11c47d69820bf13f57d73fc +timeCreated: 1753701166 \ No newline at end of file diff --git a/Editor/Constant/UXGUIConfig.cs b/Editor/Constant/UXGUIConfig.cs new file mode 100644 index 0000000..0fc3530 --- /dev/null +++ b/Editor/Constant/UXGUIConfig.cs @@ -0,0 +1,7 @@ +internal class UXGUIConfig +{ + + public static readonly string RootPath = "Packages/com.alicizax.unity.ui.extension/"; + public static readonly string GUIPath = RootPath + "Runtime/Res/UX-GUI/"; + public static readonly string UIDefaultMatPath = GUIPath + "UX_ImageDefault.mat"; +} diff --git a/Editor/Constant/UXGUIConfig.cs.meta b/Editor/Constant/UXGUIConfig.cs.meta new file mode 100644 index 0000000..9d71fdc --- /dev/null +++ b/Editor/Constant/UXGUIConfig.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 8524035785784316be7145b02ae2d658 +timeCreated: 1753701173 \ No newline at end of file diff --git a/Editor/Inspector.meta b/Editor/Inspector.meta new file mode 100644 index 0000000..0dab37a --- /dev/null +++ b/Editor/Inspector.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 7fbc70da0ad64703a6ad7f8deadede84 +timeCreated: 1753700883 \ No newline at end of file diff --git a/Editor/Inspector/UIEffectWrapDrawer.cs b/Editor/Inspector/UIEffectWrapDrawer.cs new file mode 100644 index 0000000..447d762 --- /dev/null +++ b/Editor/Inspector/UIEffectWrapDrawer.cs @@ -0,0 +1,105 @@ +using UnityEditor; + +namespace UnityEngine.UI +{ + public static class UIEffectWrapDrawer + { + static string LabelStr; + static string ShadowStr; + static string OutlineStr; + + public static void InitInspectorString() + { + LabelStr = "Effect"; + ShadowStr = "Shadow"; + OutlineStr = "Outline"; + } + + + public static void Draw(Rect position, GameObject target) + { + var nameRect = new Rect(position) + { + width = position.width / 2 + }; + + EditorGUI.LabelField(nameRect, LabelStr); + + var shadowRect = new Rect(position) + { + x = position.x + EditorGUIUtility.labelWidth + 2, + width = 60 + }; + + if (GUI.Button(shadowRect, ShadowStr)) + { + if (target.GetComponent() != null) + { + } + else if (target.GetComponent() != null) + { + } + + GenShadowComponent(target); + } + + var outlineRect = new Rect(position) + { + x = shadowRect.x + 50 + 20, + width = 60 + }; + + if (GUI.Button(outlineRect, OutlineStr)) + { + if (target.GetComponent() != null) + { + } + else if (target.GetComponent() != null) + { + } + + GenOutLineComponent(target); + } + } + + private static void GenOutLineComponent(GameObject target) + { + target.TryAddComponent(); + } + + private static void GenShadowComponent(GameObject target) + { + //暂时无法处理 有继承关系的Component 单独判定区分outline + //target.TryAddComponent(); + // Shadow[] components = target.GetComponents(); + + // bool hasShadow = false; + // for (int i = 0; i < components.Length; i++) + // { + // Outline outline = components[i] as Outline; + // //有一个不是OutLine就认为是Shadow + // if (outline == null) + // { + // hasShadow = true; + // } + // } + + //if (!hasShadow) + //{ + target.AddComponent(); + //} + } + + private static T TryAddComponent(this GameObject target) where T : Component + { + //暂时无法处理 有继承关系的Component 挠头 + target.TryGetComponent(out T component); + //if (component == null) + //{ + component = target.AddComponent(); + //} + + return component; + } + } +} diff --git a/Editor/Inspector/UIEffectWrapDrawer.cs.meta b/Editor/Inspector/UIEffectWrapDrawer.cs.meta new file mode 100644 index 0000000..18fc111 --- /dev/null +++ b/Editor/Inspector/UIEffectWrapDrawer.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 4040cba561a84d028e6210fb189703b6 +timeCreated: 1753700892 \ No newline at end of file diff --git a/Editor/Inspector/UXUIEditor.cs b/Editor/Inspector/UXUIEditor.cs new file mode 100644 index 0000000..a438a21 --- /dev/null +++ b/Editor/Inspector/UXUIEditor.cs @@ -0,0 +1,73 @@ +using System; +using System.Reflection; +using TMPro.EditorUtilities; +using UnityEditor; +using UnityEngine; +using UnityEngine.UI; + + +public 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