50 lines
1.1 KiB
C#
50 lines
1.1 KiB
C#
using DG.Tweening;
|
|
using System;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class MSignalButton : MonoBehaviour
|
|
{
|
|
public event Action OnClick;
|
|
|
|
[SerializeField] private Image _image;
|
|
[SerializeField] private Color _normalColor;
|
|
[SerializeField] private Color _pressedColor;
|
|
[SerializeField] private AudioClip _clip;
|
|
|
|
private bool _lastPressed = false;
|
|
private Sequence _animation;
|
|
|
|
public void TakeInput(bool pressed)
|
|
{
|
|
if (_lastPressed != pressed)
|
|
{
|
|
if (pressed)
|
|
{
|
|
OnClick?.Invoke();
|
|
PlayAnimation();
|
|
}
|
|
_lastPressed = pressed;
|
|
}
|
|
}
|
|
|
|
public void PlayAnimation()
|
|
{
|
|
if (_animation != null)
|
|
{
|
|
_animation.Kill();
|
|
_animation = null;
|
|
}
|
|
|
|
_animation = DOTween.Sequence();
|
|
|
|
_animation.Append(_image.DOColor(_pressedColor, 0.1f));
|
|
_animation.AppendCallback(() => SoundManager.instance.playClip(_clip));
|
|
_animation.Append(_image.DOColor(_normalColor, 0.1f));
|
|
|
|
_animation.PlayForward();
|
|
}
|
|
|
|
|
|
}
|