Files
MMORPG/Packages/com.unity.inputsystem/Samples~/RebindingUI/CanvasGroupModifier.cs
cooney ce83f21c93 UI 자동화를 위해 바인딩 기능 구현
- 유니티 에셋 인증 오류로 meta 재생성
2026-01-25 01:31:34 +09:00

52 lines
1.8 KiB
C#

using UnityEngine.EventSystems;
namespace UnityEngine.InputSystem.Samples.RebindUI
{
/// <summary>
/// Simple utility that modifies a referenced CanvasGroup while being active.
/// </summary>
public class CanvasGroupModifier : MonoBehaviour
{
[Tooltip("The Canvas Group to be modified while this component is active")]
public CanvasGroup canvasGroup;
[Tooltip("The interactable setting to use for the Canvas Group while this component is active")]
public bool interactable = false;
private bool m_SavedInteractable;
private GameObject m_SelectedObject;
private void OnEnable()
{
if (canvasGroup != null)
{
// Store selection to make sure it is not changed when switching "windows".
m_SelectedObject = EventSystem.current.currentSelectedGameObject;
// Save current setting and override
m_SavedInteractable = canvasGroup.interactable;
canvasGroup.interactable = interactable;
}
}
private void OnDisable()
{
if (canvasGroup != null)
{
// Restore previous setting.
canvasGroup.interactable = m_SavedInteractable;
// Restore previous selection.
var eventSystem = EventSystem.current;
if (eventSystem != null)
{
if (m_SelectedObject != null)
eventSystem.SetSelectedGameObject(m_SelectedObject);
else if (EventSystem.current.currentSelectedGameObject == null)
eventSystem.SetSelectedGameObject(eventSystem.firstSelectedGameObject);
}
}
}
}
}