using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.UI; namespace Watermelon { public class AttackButtonBehavior : Button { private static AttackButtonBehavior instance; private Image radialFillImage; private UIGamepadButton uiGamepadButton; public static bool IsButtonPressed { get; private set; } public static event SimpleBoolCallback onStatusChanged; protected override void Awake() { instance = this; radialFillImage = transform.GetChild(0).GetComponent(); uiGamepadButton = GetComponent(); base.Awake(); } private void Update() { if (Control.InputType == InputType.Gamepad) { if (GamepadControl.WasButtonPressedThisFrame(uiGamepadButton.ButtonType)) { IsButtonPressed = true; onStatusChanged?.Invoke(true); } else if (GamepadControl.WasButtonReleasedThisFrame(uiGamepadButton.ButtonType)) { IsButtonPressed = false; onStatusChanged?.Invoke(false); } } } public override void OnPointerUp(PointerEventData eventData) { base.OnPointerUp(eventData); IsButtonPressed = false; onStatusChanged?.Invoke(false); } public override void OnPointerDown(PointerEventData eventData) { base.OnPointerDown(eventData); IsButtonPressed = true; onStatusChanged?.Invoke(true); } public static void SetReloadFill(float t) { if (instance == null) return; instance.radialFillImage.fillAmount = t; } } }