添加样式组件刷新功能
This commit is contained in:
@@ -14,7 +14,7 @@ namespace XericUI.OverrideUI
|
||||
/// 替代 Unity 内置的 ColorBlock 和 SpriteState。
|
||||
/// </summary>
|
||||
[AddComponentMenu("Xeric UI Vessel/UI/Style Button", 51)]
|
||||
public class XericStyleButton : Button
|
||||
public class XericStyleButton : Button, IStyleRefreshable
|
||||
{
|
||||
#region 序列化字段
|
||||
|
||||
@@ -59,11 +59,14 @@ namespace XericUI.OverrideUI
|
||||
m_ColorState?.SubscribeAll(OnStyleChanged);
|
||||
m_TextureState?.SubscribeAll(OnStyleChanged);
|
||||
|
||||
StyleRefreshManager.Register(this);
|
||||
ApplyForState(m_CurrentState);
|
||||
}
|
||||
|
||||
protected override void OnDisable()
|
||||
{
|
||||
StyleRefreshManager.Unregister(this);
|
||||
|
||||
m_ColorState?.UnsubscribeAll(OnStyleChanged);
|
||||
m_TextureState?.UnsubscribeAll(OnStyleChanged);
|
||||
m_ColorState?.UnregisterAll();
|
||||
@@ -92,6 +95,11 @@ namespace XericUI.OverrideUI
|
||||
|
||||
#region 样式应用
|
||||
|
||||
public void RefreshStyle()
|
||||
{
|
||||
ApplyForState(m_CurrentState, false);
|
||||
}
|
||||
|
||||
private void ApplyForState(StyleSheetSelectionState state, bool instant = false)
|
||||
{
|
||||
// 颜色
|
||||
@@ -134,6 +142,12 @@ namespace XericUI.OverrideUI
|
||||
#region 组件替换
|
||||
|
||||
#if UNITY_EDITOR
|
||||
[UnityEditor.MenuItem("CONTEXT/XericStyleButton/Xeric UI/强制刷新样式", false, 1)]
|
||||
private static void ForceRefreshStyle(UnityEditor.MenuCommand command)
|
||||
{
|
||||
StyleRefreshManager.ForceRefreshAll();
|
||||
}
|
||||
|
||||
[UnityEditor.MenuItem("CONTEXT/Button/Replace To/Xeric (Style)", true)]
|
||||
private static bool ValidateReplaceToStyleButton(UnityEditor.MenuCommand command)
|
||||
=> command.context is Button and not XericStyleButton;
|
||||
|
||||
@@ -2,6 +2,7 @@ using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
using XericLibrary.Runtime.SuperStyleSheet;
|
||||
using XericUI.Core.StyleSheetUI;
|
||||
using XericUI.Helper;
|
||||
|
||||
namespace XericUI.OverrideUI
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace XericUI.OverrideUI
|
||||
/// 额外支持 isOn 覆盖和 Checkmark 样式。
|
||||
/// </summary>
|
||||
[AddComponentMenu("Xeric UI Vessel/UI/Style Toggle", 52)]
|
||||
public class XericStyleToggle : Toggle
|
||||
public class XericStyleToggle : Toggle, IStyleRefreshable
|
||||
{
|
||||
#region 序列化字段
|
||||
|
||||
@@ -86,12 +86,15 @@ namespace XericUI.OverrideUI
|
||||
m_CheckmarkStyle?.Register();
|
||||
m_CheckmarkStyle.OnValueChanged += OnStyleChanged;
|
||||
|
||||
StyleRefreshManager.Register(this);
|
||||
onValueChanged.AddListener(OnToggleValueChanged);
|
||||
ApplyForState(m_CurrentState);
|
||||
}
|
||||
|
||||
protected override void OnDisable()
|
||||
{
|
||||
StyleRefreshManager.Unregister(this);
|
||||
|
||||
onValueChanged.RemoveListener(OnToggleValueChanged);
|
||||
|
||||
m_ColorState?.UnsubscribeAll(OnStyleChanged);
|
||||
@@ -130,6 +133,11 @@ namespace XericUI.OverrideUI
|
||||
|
||||
#region 样式应用
|
||||
|
||||
public void RefreshStyle()
|
||||
{
|
||||
ApplyForState(m_CurrentState, false);
|
||||
}
|
||||
|
||||
private void ApplyForState(StyleSheetSelectionState state, bool instant = false)
|
||||
{
|
||||
// 颜色:On 覆盖优先
|
||||
@@ -181,6 +189,12 @@ namespace XericUI.OverrideUI
|
||||
#region 组件替换
|
||||
|
||||
#if UNITY_EDITOR
|
||||
[UnityEditor.MenuItem("CONTEXT/XericStyleToggle/Xeric UI/强制刷新样式", false, 1)]
|
||||
private static void ForceRefreshStyle(UnityEditor.MenuCommand command)
|
||||
{
|
||||
StyleRefreshManager.ForceRefreshAll();
|
||||
}
|
||||
|
||||
[UnityEditor.MenuItem("CONTEXT/Toggle/Replace To/Xeric (Style)", true)]
|
||||
private static bool ValidateReplaceToStyleToggle(UnityEditor.MenuCommand command)
|
||||
=> command.context is Toggle and not XericStyleToggle;
|
||||
|
||||
Reference in New Issue
Block a user