using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class CommandHandlerUI : MonoBehaviour { [SerializeField, HideInInspector] Button _undoButton; [SerializeField, HideInInspector] Button _redoButton; [SerializeField, HideInInspector] CommandHandler _commandHandler; private void Awake() { if (_commandHandler == null) return; _commandHandler.OnUndoUnavailable += DisableUndoButton; _commandHandler.OnRedoUnavailable += DisableRedoButton; _commandHandler.OnUndoAvailable += EnableUndoButton; _commandHandler.OnRedoAvailable += EnableRedoButton; } void EnableUndoButton() { EnableUndoButtonUse(true); } void DisableUndoButton() { EnableUndoButtonUse(false); } void EnableUndoButtonUse(bool enable) { if (_undoButton != null) { _undoButton.interactable = enable; } } void EnableRedoButton() { EnableRedoButtonUse(true); } void DisableRedoButton() { EnableRedoButtonUse(false); } void EnableRedoButtonUse(bool enable) { if (_redoButton != null) { _redoButton.interactable = enable; } } }