From 2c5bee8677ce6edbcc059ad590fca8861ddb62bc Mon Sep 17 00:00:00 2001 From: LiRuoChen <571244399@qq.com> Date: Tue, 21 Apr 2026 14:28:37 +0800 Subject: [PATCH] =?UTF-8?q?editor=E9=83=A8=E5=88=86=E8=84=9A=E6=9C=AC?= =?UTF-8?q?=E8=AE=BE=E4=B8=BA=E7=A7=81=E6=9C=89=EF=BC=8C=E9=81=BF=E5=85=8D?= =?UTF-8?q?=E6=B1=A1=E6=9F=93=E8=A1=A5=E5=85=A8=E4=B8=8A=E4=B8=8B=E6=96=87?= =?UTF-8?q?=E3=80=82=20=E6=B7=BB=E5=8A=A0=E6=8C=89=E9=92=AE=E7=9A=84?= =?UTF-8?q?=E9=87=8D=E5=86=99=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Editor/Core/Vessel/ObjectVessel2Property.cs | 2 +- Editor/Core/Vessel/ObjectVessel3Property.cs | 2 +- Editor/Core/Vessel/ObjectVesselProperty.cs | 2 +- .../Core/Vessel/ObjectVesselPropertyBase.cs | 2 +- ...icHorizontalOrVerticalLayoutGroupEditor.cs | 2 +- .../OverrideLayout/XericScrollRectEditor.cs | 2 +- Editor/OverrideUI/XericButtonEditor.cs | 62 ++++++ Editor/OverrideUI/XericButtonEditor.cs.meta | 3 + Editor/OverrideUI/XericToggleEditor.cs | 4 +- Runtime/OverrideUI/XericButton.cs | 204 ++++++++++++++++++ Runtime/OverrideUI/XericButton.cs.meta | 3 + Runtime/OverrideUI/XericToggle.cs | 11 +- 12 files changed, 291 insertions(+), 8 deletions(-) create mode 100644 Editor/OverrideUI/XericButtonEditor.cs create mode 100644 Editor/OverrideUI/XericButtonEditor.cs.meta create mode 100644 Runtime/OverrideUI/XericButton.cs create mode 100644 Runtime/OverrideUI/XericButton.cs.meta diff --git a/Editor/Core/Vessel/ObjectVessel2Property.cs b/Editor/Core/Vessel/ObjectVessel2Property.cs index 5051afa..b004a91 100644 --- a/Editor/Core/Vessel/ObjectVessel2Property.cs +++ b/Editor/Core/Vessel/ObjectVessel2Property.cs @@ -8,7 +8,7 @@ using Object = UnityEngine.Object; namespace XericUIEditor.Core.Vessel { [CustomPropertyDrawer(typeof(ObjectVessel<,>))] - public class ObjectVessel2Property : ObjectVesselPropertyBase + internal class ObjectVessel2Property : ObjectVesselPropertyBase { private Type property0Type = typeof(Object); private Type property1Type = typeof(Object); diff --git a/Editor/Core/Vessel/ObjectVessel3Property.cs b/Editor/Core/Vessel/ObjectVessel3Property.cs index a70525b..d4ff297 100644 --- a/Editor/Core/Vessel/ObjectVessel3Property.cs +++ b/Editor/Core/Vessel/ObjectVessel3Property.cs @@ -8,7 +8,7 @@ using Object = UnityEngine.Object; namespace XericUIEditor.Core.Vessel { [CustomPropertyDrawer(typeof(ObjectVessel<,,>))] - public class ObjectVessel3Property : ObjectVesselPropertyBase + internal class ObjectVessel3Property : ObjectVesselPropertyBase { private Type property0Type = typeof(Object); private Type property1Type = typeof(Object); diff --git a/Editor/Core/Vessel/ObjectVesselProperty.cs b/Editor/Core/Vessel/ObjectVesselProperty.cs index 428ba4f..56b4598 100644 --- a/Editor/Core/Vessel/ObjectVesselProperty.cs +++ b/Editor/Core/Vessel/ObjectVesselProperty.cs @@ -7,7 +7,7 @@ using Object = UnityEngine.Object; namespace XericUIEditor.Core.Vessel { [CustomPropertyDrawer(typeof(ObjectVessel<>))] - public class ObjectVesselProperty : ObjectVesselPropertyBase + internal class ObjectVesselProperty : ObjectVesselPropertyBase { private Type property0Type = typeof(Object); private string originTooltip = null; diff --git a/Editor/Core/Vessel/ObjectVesselPropertyBase.cs b/Editor/Core/Vessel/ObjectVesselPropertyBase.cs index 190dd4e..6989b2a 100644 --- a/Editor/Core/Vessel/ObjectVesselPropertyBase.cs +++ b/Editor/Core/Vessel/ObjectVesselPropertyBase.cs @@ -5,7 +5,7 @@ using XericUI.Core.Vessel; namespace XericUIEditor.Core.Vessel { - public class ObjectVesselPropertyBase : PropertyDrawer + internal class ObjectVesselPropertyBase : PropertyDrawer { /// /// 递归获取实际的泛型类型(处理嵌套情况) diff --git a/Editor/OverrideLayout/XericHorizontalOrVerticalLayoutGroupEditor.cs b/Editor/OverrideLayout/XericHorizontalOrVerticalLayoutGroupEditor.cs index 23e82eb..64167b0 100644 --- a/Editor/OverrideLayout/XericHorizontalOrVerticalLayoutGroupEditor.cs +++ b/Editor/OverrideLayout/XericHorizontalOrVerticalLayoutGroupEditor.cs @@ -7,7 +7,7 @@ namespace XericUIEditor.OverrideLayout { [CustomEditor(typeof(XericHorizontalOrVerticalLayoutGroup), true)] [CanEditMultipleObjects] - public class XericHorizontalOrVerticalLayoutGroupEditor : HorizontalOrVerticalLayoutGroupEditor + internal class XericHorizontalOrVerticalLayoutGroupEditor : HorizontalOrVerticalLayoutGroupEditor { SerializedProperty ignoreInvisible; SerializedProperty enableListScreening; diff --git a/Editor/OverrideLayout/XericScrollRectEditor.cs b/Editor/OverrideLayout/XericScrollRectEditor.cs index f9bf5f4..51b201f 100644 --- a/Editor/OverrideLayout/XericScrollRectEditor.cs +++ b/Editor/OverrideLayout/XericScrollRectEditor.cs @@ -7,7 +7,7 @@ namespace XericUIEditor.OverrideLayout { [CustomEditor(typeof(XericScrollRect), true)] [CanEditMultipleObjects] - public class XericScrollRectEditor : ScrollRectEditor + internal class XericScrollRectEditor : ScrollRectEditor { SerializedProperty m_EnableAutoActiveByMaskVisible; SerializedProperty m_layoutGroup; diff --git a/Editor/OverrideUI/XericButtonEditor.cs b/Editor/OverrideUI/XericButtonEditor.cs new file mode 100644 index 0000000..1c5b813 --- /dev/null +++ b/Editor/OverrideUI/XericButtonEditor.cs @@ -0,0 +1,62 @@ +using UnityEditor; +using UnityEditor.UI; +using XericUI.OverrideUI; + +namespace XericUIEditor.OverrideUI +{ + [CustomEditor(typeof(XericButton), true)] + [CanEditMultipleObjects] + /// + /// Custom Editor for the Button Component. + /// Extend this class to write a custom editor for a component derived from Button. + /// + internal class XericButtonEditor : SelectableEditor + { + SerializedProperty m_OnClickProperty; + + SerializedProperty m_TextProperty; + SerializedProperty m_EnableTextColorTransitionProperty; + SerializedProperty m_TextTransitionColorModeProperty; + SerializedProperty m_enableTextContextTransitionProperty; + SerializedProperty m_textTransitionContextModeProperty; + + protected override void OnEnable() + { + base.OnEnable(); + m_OnClickProperty = serializedObject.FindProperty("m_OnClick"); + + m_TextProperty = serializedObject.FindProperty("m_text"); + m_EnableTextColorTransitionProperty = serializedObject.FindProperty("m_enableTextColorTransition"); + m_TextTransitionColorModeProperty = serializedObject.FindProperty("m_textTransitionColorMode"); + m_enableTextContextTransitionProperty = serializedObject.FindProperty("m_enableTextContextTransition"); + m_textTransitionContextModeProperty = serializedObject.FindProperty("m_textTransitionContextMode"); + } + + public override void OnInspectorGUI() + { + base.OnInspectorGUI(); + EditorGUILayout.Space(); + + serializedObject.Update(); + + EditorGUILayout.PropertyField(m_TextProperty); + EditorGUILayout.PropertyField(m_EnableTextColorTransitionProperty); + if (m_EnableTextColorTransitionProperty.boolValue) + { + EditorGUI.indentLevel++; + EditorGUILayout.PropertyField(m_TextTransitionColorModeProperty); + EditorGUI.indentLevel--; + } + EditorGUILayout.PropertyField(m_enableTextContextTransitionProperty); + if (m_enableTextContextTransitionProperty.boolValue) + { + EditorGUI.indentLevel++; + EditorGUILayout.PropertyField(m_textTransitionContextModeProperty); + EditorGUI.indentLevel--; + } + + EditorGUILayout.PropertyField(m_OnClickProperty); + serializedObject.ApplyModifiedProperties(); + } + } +} \ No newline at end of file diff --git a/Editor/OverrideUI/XericButtonEditor.cs.meta b/Editor/OverrideUI/XericButtonEditor.cs.meta new file mode 100644 index 0000000..dcbaa51 --- /dev/null +++ b/Editor/OverrideUI/XericButtonEditor.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 00e32f6988bf41f29169c1660bcf009f +timeCreated: 1776646534 \ No newline at end of file diff --git a/Editor/OverrideUI/XericToggleEditor.cs b/Editor/OverrideUI/XericToggleEditor.cs index 9cb0001..08e9fd0 100644 --- a/Editor/OverrideUI/XericToggleEditor.cs +++ b/Editor/OverrideUI/XericToggleEditor.cs @@ -3,8 +3,9 @@ using UnityEditor.SceneManagement; using UnityEditor.UI; using UnityEngine; using UnityEngine.UI; +using XericUI; -namespace XericUI +namespace XericUIEditor.OverrideUI { [CustomEditor(typeof(XericToggle))] internal class XericToggleEditor : SelectableEditor @@ -68,6 +69,7 @@ namespace XericUI EditorGUILayout.PropertyField(m_TransitionProperty); EditorGUILayout.PropertyField(m_GraphicProperty); + EditorGUILayout.PropertyField(m_TextProperty); EditorGUILayout.PropertyField(m_EnableTextColorTransitionProperty); if (m_EnableTextColorTransitionProperty.boolValue) diff --git a/Runtime/OverrideUI/XericButton.cs b/Runtime/OverrideUI/XericButton.cs new file mode 100644 index 0000000..2ed638b --- /dev/null +++ b/Runtime/OverrideUI/XericButton.cs @@ -0,0 +1,204 @@ +using TMPro; +using UnityEngine; +using UnityEngine.UI; +using XericUI.Helper; + +namespace XericUI.OverrideUI +{ + public class XericButton : Button + { + +#if dUI_TextMeshPro + public TMP_Text m_text; + + public string TextContent + { + get => m_text != null ? m_text.text ?? string.Empty : string.Empty; + set { if(m_text) m_text.text = value; } + } + + public Color TextColor + { + get => m_text != null ? m_text.color : Color.black; + set { if(m_text) m_text.color = value; } + } +#else + public Text m_text; + + public string TextContent + { + get => m_text.text; + set => m_text.text = value; + } + + public Color TextColor + { + get => m_text.color; + set => m_text.color = value; + } +#endif + + public bool m_enableTextColorTransition = true; + public ColorBlock m_textTransitionColorMode = ColorBlock.defaultColorBlock; + public bool m_enableTextContextTransition = false; + public AnimationTriggers m_textTransitionContextMode = new AnimationTriggers() + { + normalTrigger = "button_normal", + highlightedTrigger = "button_highlight", + pressedTrigger = "button_pressed", + selectedTrigger = "button_selected", + disabledTrigger = "button_disabled", + }; + + public ColorBlock TextTransitionColorMode + { + get => m_textTransitionColorMode; + set => m_textTransitionColorMode = value; + } + + protected override void DoStateTransition(SelectionState state, bool instant) + { + if (!gameObject.activeInHierarchy) + return; + + Color tintColor; + Sprite transitionSprite; + string triggerName; + Color textColor; + string transitionName; + + switch (state) + { + case SelectionState.Normal: + tintColor = colors.normalColor; + textColor = m_textTransitionColorMode.normalColor; + transitionSprite = null; + triggerName = animationTriggers.normalTrigger; + transitionName = m_textTransitionContextMode.normalTrigger; + break; + case SelectionState.Highlighted: + tintColor = colors.highlightedColor; + textColor = m_textTransitionColorMode.highlightedColor; + transitionSprite = spriteState.highlightedSprite; + triggerName = animationTriggers.highlightedTrigger; + transitionName = m_textTransitionContextMode.highlightedTrigger; + break; + case SelectionState.Pressed: + tintColor = colors.pressedColor; + textColor = m_textTransitionColorMode.pressedColor; + transitionSprite = spriteState.pressedSprite; + triggerName = animationTriggers.pressedTrigger; + transitionName = m_textTransitionContextMode.pressedTrigger; + break; + case SelectionState.Selected: + tintColor = colors.selectedColor; + textColor = m_textTransitionColorMode.selectedColor; + transitionSprite = spriteState.selectedSprite; + triggerName = animationTriggers.selectedTrigger; + transitionName = m_textTransitionContextMode.selectedTrigger; + break; + case SelectionState.Disabled: + tintColor = colors.disabledColor; + textColor = m_textTransitionColorMode.disabledColor; + transitionSprite = spriteState.disabledSprite; + triggerName = animationTriggers.disabledTrigger; + transitionName = m_textTransitionContextMode.disabledTrigger; + break; + default: + tintColor = Color.black; + textColor = Color.white; + transitionSprite = null; + triggerName = string.Empty; + transitionName = m_textTransitionContextMode.normalTrigger; + break; + } + + switch (transition) + { + case Transition.ColorTint: + StartColorTween(tintColor * colors.colorMultiplier, instant); + break; + case Transition.SpriteSwap: + DoSpriteSwap(transitionSprite); + break; + case Transition.Animation: + TriggerAnimation(triggerName); + break; + } + + if (m_enableTextColorTransition) + TextColor = textColor; + if (m_enableTextContextTransition) + TextContent = transitionName; + } + + + void StartColorTween(Color targetColor, bool instant) + { + if (targetGraphic == null) + return; + + targetGraphic.CrossFadeColor(targetColor, instant ? 0f : colors.fadeDuration, true, true); + } + + void DoSpriteSwap(Sprite newSprite) + { + if (image == null) + return; + + image.overrideSprite = newSprite; + } + + void TriggerAnimation(string triggername) + { +#if PACKAGE_ANIMATION + if (transition != Transition.Animation || animator == null || !animator.isActiveAndEnabled || !animator.hasBoundPlayables || string.IsNullOrEmpty(triggername)) + return; + + animator.ResetTrigger(animationTriggers.normalTrigger); + animator.ResetTrigger(animationTriggers.highlightedTrigger); + animator.ResetTrigger(animationTriggers.pressedTrigger); + animator.ResetTrigger(animationTriggers.selectedTrigger); + animator.ResetTrigger(animationTriggers.disabledTrigger); + + animator.SetTrigger(triggername); +#endif + } + + #region 组件替换 +#if UNITY_EDITOR + [UnityEditor.MenuItem("CONTEXT/Button/Replace To XericButton", true)] + private static bool ValidateReplaceToXeric(UnityEditor.MenuCommand command) + => command.context is Button and not XericButton; + + [UnityEditor.MenuItem("CONTEXT/Button/Replace To XericButton", false, 10)] + private static void ReplaceToXeric(UnityEditor.MenuCommand command) + => command.ReplaceCommandContext( + o => + (o.targetGraphic, o.onClick), + (t, d) => + { + t.targetGraphic = d.targetGraphic; + t.onClick = d.onClick; + }); + + [UnityEditor.MenuItem("CONTEXT/Button/Replace To Button", true)] + private static bool ValidateReplaceToUnity(UnityEditor.MenuCommand command) + => command.context is XericButton; + + [UnityEditor.MenuItem("CONTEXT/Button/Replace To Button", false, 10)] + private static void ReplaceToUnity(UnityEditor.MenuCommand command) + => command.ReplaceCommandContext( + o => + (o.targetGraphic, o.onClick), + (t, d) => + { + t.targetGraphic = d.targetGraphic; + t.onClick = d.onClick; + }); +#endif + #endregion + } +} \ No newline at end of file diff --git a/Runtime/OverrideUI/XericButton.cs.meta b/Runtime/OverrideUI/XericButton.cs.meta new file mode 100644 index 0000000..897025d --- /dev/null +++ b/Runtime/OverrideUI/XericButton.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 8bdce41790b144b78cce0334f2df1e13 +timeCreated: 1776645582 \ No newline at end of file diff --git a/Runtime/OverrideUI/XericToggle.cs b/Runtime/OverrideUI/XericToggle.cs index d165622..9fbcb84 100644 --- a/Runtime/OverrideUI/XericToggle.cs +++ b/Runtime/OverrideUI/XericToggle.cs @@ -77,6 +77,7 @@ namespace XericUI Sprite transitionSprite; string triggerName; Color textColor; + string transitionName; switch (state) { @@ -85,36 +86,42 @@ namespace XericUI textColor = m_textTransitionColorMode.normalColor; transitionSprite = null; triggerName = animationTriggers.normalTrigger; + transitionName = m_textTransitionContextMode.normalTrigger; break; case SelectionState.Highlighted: tintColor = colors.highlightedColor; textColor = m_textTransitionColorMode.highlightedColor; transitionSprite = spriteState.highlightedSprite; triggerName = animationTriggers.highlightedTrigger; + transitionName = m_textTransitionContextMode.highlightedTrigger; break; case SelectionState.Pressed: tintColor = colors.pressedColor; textColor = m_textTransitionColorMode.pressedColor; transitionSprite = spriteState.pressedSprite; triggerName = animationTriggers.pressedTrigger; + transitionName = m_textTransitionContextMode.pressedTrigger; break; case SelectionState.Selected: tintColor = colors.selectedColor; textColor = m_textTransitionColorMode.selectedColor; transitionSprite = spriteState.selectedSprite; triggerName = animationTriggers.selectedTrigger; + transitionName = m_textTransitionContextMode.selectedTrigger; break; case SelectionState.Disabled: tintColor = colors.disabledColor; textColor = m_textTransitionColorMode.disabledColor; transitionSprite = spriteState.disabledSprite; triggerName = animationTriggers.disabledTrigger; + transitionName = m_textTransitionContextMode.disabledTrigger; break; default: tintColor = Color.black; - textColor = Color.black; + textColor = Color.white; transitionSprite = null; triggerName = string.Empty; + transitionName = m_textTransitionContextMode.normalTrigger; break; } @@ -133,6 +140,8 @@ namespace XericUI if (m_enableTextColorTransition) TextColor = isOn ? m_textTransitionColorMode.selectedColor : textColor; + if (m_enableTextContextTransition) + TextContent = transitionName; }