com.alicizax.unity.ui.exten.../Runtime/UXComponent/Controller/Property/GameObjectActiveState.cs
2026-03-11 15:23:44 +08:00

46 lines
1.4 KiB
C#

using System;
using UnityEngine;
namespace AlicizaX.UI
{
/// <summary>
/// GameObject 激活状态控制
/// 控制对象的显示/隐藏
/// </summary>
[Serializable]
[ControlerStateName("GameObject/Active")]
[ControlerStateAttachType(true)]
public class GameObjectActiveState : ControllerStateBase
{
[SerializeField] private bool _active = true;
[HideInInspector] [SerializeField] private bool _defaultActive = true;
public override void Init(UXControllerStateRecorder recorder)
{
if (recorder != null && recorder.gameObject != null)
{
_defaultActive = recorder.gameObject.activeSelf;
}
}
public override void Execute(UXControllerStateRecorder recorder, int entryIndex, int selectionIndex)
{
if (recorder != null && recorder.gameObject != null)
{
bool shouldBeActive = (entryIndex == selectionIndex) ? _active : _defaultActive;
recorder.gameObject.SetActive(shouldBeActive);
}
}
public override bool Valid(UXControllerStateRecorder recorder)
{
return recorder != null && recorder.gameObject != null;
}
public override string GetDescription()
{
return $"匹配时: {(_active ? "" : "")}, 默认: {(_defaultActive ? "" : "")}";
}
}
}