StartArtPressFeedback.cs 1.2 KB

123456789101112131415161718192021222324
  1. using UnityEngine;
  2. using UnityEngine.EventSystems;
  3. using UnityEngine.UI;
  4. namespace DevilLink2.UI
  5. {
  6. // Start-only instantaneous press. The transparent hit rectangle and click handling never scale.
  7. public sealed class StartArtPressFeedback : MonoBehaviour, IPointerDownHandler, IPointerUpHandler, IPointerExitHandler
  8. {
  9. private Button button;
  10. private RectTransform visual;
  11. public void Configure(Button control, RectTransform artwork) { button = control; visual = artwork; }
  12. public void OnPointerDown(PointerEventData data)
  13. {
  14. if (data.button == PointerEventData.InputButton.Left && button && button.IsActive() && button.IsInteractable() && visual)
  15. visual.localScale = new Vector3(.97f, .97f, 1);
  16. }
  17. public void OnPointerUp(PointerEventData data) { if (data.button == PointerEventData.InputButton.Left) ResetVisual(); }
  18. public void OnPointerExit(PointerEventData data) { ResetVisual(); }
  19. private void ResetVisual() { if (visual) visual.localScale = Vector3.one; }
  20. private void OnDisable() { ResetVisual(); }
  21. private void OnDestroy() { ResetVisual(); }
  22. }
  23. }