Files
ichni_Official/Assets/Scripts/UI/Base/UiExpandingContoursEffect.cs
SoulliesOfficial 923fc5359f 发包版本
2026-07-26 09:32:51 -04:00

57 lines
1.9 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using UnityEngine;
using UnityEngine.UI;
namespace Ichni.UI
{
/// <summary>
/// 将装饰性 UI Image 纳入「UI 效果」图形设置。
/// <para>
/// 此组件应只挂在使用 <c>UI_ExpandingContours</c> 等可选视觉 Shader 的 Image 上。
/// 关闭设置时仅禁用目标 Image 的绘制,不会停用 GameObject因此布局与子物体状态不受影响。
/// 目标应为不承载输入的装饰性 Image。
/// </para>
/// <para>
/// 新增同类 UI 特效时,只需在对应 Image 上添加本组件;无需再在 SettingsManager 中硬编码页面或物体名称。
/// </para>
/// </summary>
[DisallowMultipleComponent]
[RequireComponent(typeof(Graphic))]
public sealed class UiExpandingContoursEffect : MonoBehaviour
{
[SerializeField] private Graphic targetGraphic;
private void Reset()
{
targetGraphic = GetComponent<Graphic>();
}
private void Awake()
{
if (targetGraphic == null)
{
targetGraphic = GetComponent<Graphic>();
}
}
private void OnEnable()
{
// 页面首次显示或从隐藏状态恢复时,重新读取已经加载的玩家设置。
bool enableUiEffects = SettingsManager.instance?.settingsSaveData?.enableUiEffects ?? true;
ApplyEnabledState(enableUiEffects);
}
/// <summary>
/// 设置目标 Image 是否参与绘制。由 SettingsManager 在载入存档、场景切换和玩家切换开关时调用。
/// </summary>
public void ApplyEnabledState(bool enableUiEffects)
{
if (targetGraphic == null)
{
targetGraphic = GetComponent<Graphic>();
}
targetGraphic.enabled = enableUiEffects;
}
}
}